diff --git a/jfconnect/services/connect.go b/jfconnect/services/connect.go deleted file mode 100644 index 85a3f3e4e..000000000 --- a/jfconnect/services/connect.go +++ /dev/null @@ -1,43 +0,0 @@ -package services - -import ( - "encoding/json" - "github.com/jfrog/jfrog-client-go/auth" - "github.com/jfrog/jfrog-client-go/http/jfroghttpclient" - clientutils "github.com/jfrog/jfrog-client-go/utils" - "github.com/jfrog/jfrog-client-go/utils/errorutils" - "net/http" -) - -const LogMetricApiEndpoint = "api/v1/backoffice/metrics/log" - -type JfConnectService struct { - client *jfroghttpclient.JfrogHttpClient - serviceDetails *auth.ServiceDetails -} - -func NewJfConnectService(serviceDetails auth.ServiceDetails, client *jfroghttpclient.JfrogHttpClient) *JfConnectService { - return &JfConnectService{serviceDetails: &serviceDetails, client: client} -} - -func (jcs *JfConnectService) GetJfConnectDetails() auth.ServiceDetails { - return *jcs.serviceDetails -} - -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, metricJson, &httpClientDetails) - if err != nil { - return err - } - return errorutils.CheckResponseStatusWithBody(resp, body, http.StatusCreated, http.StatusOK) -} diff --git a/jfconnect/services/metrics.go b/jfconnect/services/metrics.go index 5a04216ca..2930e705a 100644 --- a/jfconnect/services/metrics.go +++ b/jfconnect/services/metrics.go @@ -1,19 +1,49 @@ package services -type VisibilityMetric interface { - MetricValue() int - MetricName() string +import ( + "encoding/json" + "github.com/jfrog/jfrog-client-go/auth" + "github.com/jfrog/jfrog-client-go/http/jfroghttpclient" + clientutils "github.com/jfrog/jfrog-client-go/utils" + "github.com/jfrog/jfrog-client-go/utils/errorutils" + "net/http" +) + +const LogMetricApiEndpoint = "api/v1/backoffice/metrics/log" + +type VisibilityMetric struct { + Value int `json:"value"` + Name string `json:"metrics_name"` + Labels any `json:"labels"` } -type Metric struct { - Value int `json:"value"` - Name string `json:"metrics_name"` +type JfConnectService struct { + client *jfroghttpclient.JfrogHttpClient + serviceDetails *auth.ServiceDetails } -func (m *Metric) MetricValue() int { - return m.Value +func NewJfConnectService(serviceDetails auth.ServiceDetails, client *jfroghttpclient.JfrogHttpClient) *JfConnectService { + return &JfConnectService{serviceDetails: &serviceDetails, client: client} } -func (m *Metric) MetricName() string { - return m.Name +func (jcs *JfConnectService) GetJfConnectDetails() auth.ServiceDetails { + return *jcs.serviceDetails +} + +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, metricJson, &httpClientDetails) + if err != nil { + return err + } + return errorutils.CheckResponseStatusWithBody(resp, body, http.StatusCreated, http.StatusOK) }