11package services
22
33import (
4+ "encoding/json"
45 "net/http"
56
67 "github.com/jfrog/jfrog-client-go/auth"
@@ -9,7 +10,7 @@ import (
910 "github.com/jfrog/jfrog-client-go/utils/errorutils"
1011)
1112
12- const LogMetricApiEndpoint = "jfconnect/ api/v1/backoffice/metrics/log"
13+ const LogMetricApiEndpoint = "api/v1/backoffice/metrics/log"
1314
1415type JfConnectService struct {
1516 client * jfroghttpclient.JfrogHttpClient
@@ -24,16 +25,36 @@ func (jcs *JfConnectService) GetJfConnectDetails() auth.ServiceDetails {
2425 return * jcs .serviceDetails
2526}
2627
27- func (jcs * JfConnectService ) PostMetric (metric []byte ) error {
28+ func (jcs * JfConnectService ) PostVisibilityMetric (metric VisibilityMetric ) error {
29+ metricJson , err := json .Marshal (metric )
30+ if err != nil {
31+ return errorutils .CheckError (err )
32+ }
2833 details := jcs .GetJfConnectDetails ()
2934 httpClientDetails := details .CreateHttpClientDetails ()
3035 httpClientDetails .SetContentTypeApplicationJson ()
3136
3237 url := clientutils .AddTrailingSlashIfNeeded (details .GetUrl ())
3338 url += LogMetricApiEndpoint
34- resp , body , err := jcs .client .SendPost (url , metric , & httpClientDetails )
39+ resp , body , err := jcs .client .SendPost (url , metricJson , & httpClientDetails )
3540 if err != nil {
3641 return err
3742 }
3843 return errorutils .CheckResponseStatusWithBody (resp , body , http .StatusCreated , http .StatusOK )
3944}
45+
46+ type Labels struct {
47+ ProductID string `json:"product_id"`
48+ FeatureID string `json:"feature_id"`
49+ OIDCUsed string `json:"oidc_used"`
50+ JobID string `json:"job_id"`
51+ RunID string `json:"run_id"`
52+ GitRepo string `json:"git_repo"`
53+ GhTokenForCodeScanningAlertsProvided string `json:"gh_token_for_code_scanning_alerts_provided"`
54+ }
55+
56+ type VisibilityMetric struct {
57+ Value int `json:"value"`
58+ MetricsName string `json:"metrics_name"`
59+ Labels Labels `json:"labels"`
60+ }
0 commit comments