Skip to content

Commit f3151d6

Browse files
committed
Merge branch 'dev'
2 parents 4658ed5 + d77d8c8 commit f3151d6

2 files changed

Lines changed: 27 additions & 6 deletions

File tree

jfconnect/manager.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
)
88

99
type Manager interface {
10-
PostMetric([]byte) error
10+
PostVisibilityMetric(services.VisibilityMetric) error
1111
}
1212

1313
type jfConnectManager struct {
@@ -39,7 +39,7 @@ func (jm *jfConnectManager) Client() *jfroghttpclient.JfrogHttpClient {
3939
return jm.client
4040
}
4141

42-
func (jm *jfConnectManager) PostMetric(metric []byte) error {
42+
func (jm *jfConnectManager) PostVisibilityMetric(metric services.VisibilityMetric) error {
4343
jfConnectService := services.NewJfConnectService(jm.config.GetServiceDetails(), jm.client)
44-
return jfConnectService.PostMetric(metric)
44+
return jfConnectService.PostVisibilityMetric(metric)
4545
}

jfconnect/services/metrics.go

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package services
22

33
import (
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

1415
type 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

Comments
 (0)