Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Internal API - Visibility System fix & improvements #1061

Merged
merged 2 commits into from
Dec 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 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
PostMetric(services.VisibilityMetric) error
eyalbe4 marked this conversation as resolved.
Show resolved Hide resolved
}

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) PostMetric(metric services.VisibilityMetric) error {
jfConnectService := services.NewJfConnectService(jm.config.GetServiceDetails(), jm.client)
return jfConnectService.PostMetric(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) PostMetric(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"`
}
Loading