diff --git a/jfconnect/manager.go b/jfconnect/manager.go index 08fffb052..20aee5e87 100644 --- a/jfconnect/manager.go +++ b/jfconnect/manager.go @@ -7,7 +7,7 @@ import ( ) type Manager interface { - PostMetric([]byte) 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 []byte) 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 cb3fa9ecb..e7ff49543 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) PostVisibilityMetric(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"` +}