Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
eyalb4doc committed Dec 22, 2024
2 parents 4658ed5 + d77d8c8 commit f3151d6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
6 changes: 3 additions & 3 deletions jfconnect/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

type Manager interface {
PostMetric([]byte) error
PostVisibilityMetric(services.VisibilityMetric) error
}

type jfConnectManager struct {
Expand Down Expand Up @@ -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)
}
27 changes: 24 additions & 3 deletions jfconnect/services/metrics.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package services

import (
"encoding/json"
"net/http"

"github.com/jfrog/jfrog-client-go/auth"
Expand All @@ -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
Expand All @@ -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"`
}

0 comments on commit f3151d6

Please sign in to comment.