From 7cc07c031216e1ffbbf0b7ae94c7054bc8e4491c Mon Sep 17 00:00:00 2001 From: eyalbe4 Date: Sun, 22 Dec 2024 17:13:31 +0200 Subject: [PATCH 1/2] Internal API - Visibility System improvements --- jfconnect/manager.go | 4 ++-- jfconnect/services/metrics.go | 27 ++++++++++++++++++++++++--- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/jfconnect/manager.go b/jfconnect/manager.go index 08fffb052..f6e9495e0 100644 --- a/jfconnect/manager.go +++ b/jfconnect/manager.go @@ -7,7 +7,7 @@ import ( ) type Manager interface { - PostMetric([]byte) error + PostMetric(services.VisibilityMetric) error } type jfConnectManager struct { @@ -39,7 +39,7 @@ func (jm *jfConnectManager) Client() *jfroghttpclient.JfrogHttpClient { return jm.client } -func (jm *jfConnectManager) PostMetric(metric []byte) error { +func (jm *jfConnectManager) PostMetric(metric services.VisibilityMetric) error { jfConnectService := services.NewJfConnectService(jm.config.GetServiceDetails(), jm.client) return jfConnectService.PostMetric(metric) } diff --git a/jfconnect/services/metrics.go b/jfconnect/services/metrics.go index cb3fa9ecb..3142ad1d8 100644 --- a/jfconnect/services/metrics.go +++ b/jfconnect/services/metrics.go @@ -1,6 +1,7 @@ package services import ( + "encoding/json" "net/http" "github.com/jfrog/jfrog-client-go/auth" @@ -9,7 +10,7 @@ import ( "github.com/jfrog/jfrog-client-go/utils/errorutils" ) -const LogMetricApiEndpoint = "jfconnect/api/v1/backoffice/metrics/log" +const LogMetricApiEndpoint = "api/v1/backoffice/metrics/log" type JfConnectService struct { client *jfroghttpclient.JfrogHttpClient @@ -24,16 +25,36 @@ func (jcs *JfConnectService) GetJfConnectDetails() auth.ServiceDetails { return *jcs.serviceDetails } -func (jcs *JfConnectService) PostMetric(metric []byte) error { +func (jcs *JfConnectService) PostMetric(metric VisibilityMetric) error { + metricJson, err := json.Marshal(metric) + if err != nil { + return errorutils.CheckError(err) + } details := jcs.GetJfConnectDetails() httpClientDetails := details.CreateHttpClientDetails() httpClientDetails.SetContentTypeApplicationJson() url := clientutils.AddTrailingSlashIfNeeded(details.GetUrl()) url += LogMetricApiEndpoint - resp, body, err := jcs.client.SendPost(url, metric, &httpClientDetails) + resp, body, err := jcs.client.SendPost(url, metricJson, &httpClientDetails) if err != nil { return err } return errorutils.CheckResponseStatusWithBody(resp, body, http.StatusCreated, http.StatusOK) } + +type Labels struct { + ProductID string `json:"product_id"` + FeatureID string `json:"feature_id"` + OIDCUsed string `json:"oidc_used"` + JobID string `json:"job_id"` + RunID string `json:"run_id"` + GitRepo string `json:"git_repo"` + GhTokenForCodeScanningAlertsProvided string `json:"gh_token_for_code_scanning_alerts_provided"` +} + +type VisibilityMetric struct { + Value int `json:"value"` + MetricsName string `json:"metrics_name"` + Labels Labels `json:"labels"` +} From 04d75d451f2377197b0b7412adaf1f07977e1e74 Mon Sep 17 00:00:00 2001 From: eyalbe4 Date: Sun, 22 Dec 2024 17:57:50 +0200 Subject: [PATCH 2/2] CR comment --- jfconnect/manager.go | 6 +++--- jfconnect/services/metrics.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/jfconnect/manager.go b/jfconnect/manager.go index f6e9495e0..20aee5e87 100644 --- a/jfconnect/manager.go +++ b/jfconnect/manager.go @@ -7,7 +7,7 @@ import ( ) type Manager interface { - PostMetric(services.VisibilityMetric) error + PostVisibilityMetric(services.VisibilityMetric) error } type jfConnectManager struct { @@ -39,7 +39,7 @@ func (jm *jfConnectManager) Client() *jfroghttpclient.JfrogHttpClient { return jm.client } -func (jm *jfConnectManager) PostMetric(metric services.VisibilityMetric) error { +func (jm *jfConnectManager) PostVisibilityMetric(metric services.VisibilityMetric) error { jfConnectService := services.NewJfConnectService(jm.config.GetServiceDetails(), jm.client) - return jfConnectService.PostMetric(metric) + return jfConnectService.PostVisibilityMetric(metric) } diff --git a/jfconnect/services/metrics.go b/jfconnect/services/metrics.go index 3142ad1d8..e7ff49543 100644 --- a/jfconnect/services/metrics.go +++ b/jfconnect/services/metrics.go @@ -25,7 +25,7 @@ func (jcs *JfConnectService) GetJfConnectDetails() auth.ServiceDetails { return *jcs.serviceDetails } -func (jcs *JfConnectService) PostMetric(metric VisibilityMetric) error { +func (jcs *JfConnectService) PostVisibilityMetric(metric VisibilityMetric) error { metricJson, err := json.Marshal(metric) if err != nil { return errorutils.CheckError(err)