Skip to content

Commit

Permalink
Restructure visibility metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
omerzi committed Jan 15, 2025
1 parent bfbba9e commit d073792
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 53 deletions.
43 changes: 0 additions & 43 deletions jfconnect/services/connect.go

This file was deleted.

50 changes: 40 additions & 10 deletions jfconnect/services/metrics.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit d073792

Please sign in to comment.