Skip to content

Commit fe9e5dd

Browse files
committed
Merge branch 'dev'
2 parents 1291ebc + 556265c commit fe9e5dd

File tree

4 files changed

+13
-33
lines changed

4 files changed

+13
-33
lines changed

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ require (
1414
github.com/jedib0t/go-pretty/v6 v6.6.3
1515
github.com/jfrog/build-info-go v1.10.7
1616
github.com/jfrog/gofrog v1.7.6
17-
github.com/jfrog/jfrog-client-go v1.48.4
17+
github.com/jfrog/jfrog-client-go v1.48.5
1818
github.com/magiconair/properties v1.8.7
1919
github.com/manifoldco/promptui v0.9.0
2020
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c
@@ -96,7 +96,7 @@ require (
9696
gopkg.in/warnings.v0 v0.1.2 // indirect
9797
)
9898

99-
// replace github.com/jfrog/jfrog-client-go => github.com/eyalbe4/jfrog-client-go v1.28.1-0.20241220200217-c4b9ef90c453
99+
// replace github.com/jfrog/jfrog-client-go => github.com/eyalbe4/jfrog-client-go v1.28.1-0.20241222155750-04d75d451f23
100100

101101
// replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go v1.8.9-0.20241121100855-e7a75ceee2bd
102102

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ github.com/jfrog/build-info-go v1.10.7 h1:10NVHYg0193gJpQft+S4WQfvYMtj5jlwwhJRvk
9393
github.com/jfrog/build-info-go v1.10.7/go.mod h1:JcISnovFXKx3wWf3p1fcMmlPdt6adxScXvoJN4WXqIE=
9494
github.com/jfrog/gofrog v1.7.6 h1:QmfAiRzVyaI7JYGsB7cxfAJePAZTzFz0gRWZSE27c6s=
9595
github.com/jfrog/gofrog v1.7.6/go.mod h1:ntr1txqNOZtHplmaNd7rS4f8jpA5Apx8em70oYEe7+4=
96-
github.com/jfrog/jfrog-client-go v1.48.4 h1:uXvBr2ebFKpBRUhWgC9TSSJe32IbSYGlbDp9tDzBcaY=
97-
github.com/jfrog/jfrog-client-go v1.48.4/go.mod h1:2ySOMva54L3EYYIlCBYBTcTgqfrrQ19gtpA/MWfA/ec=
96+
github.com/jfrog/jfrog-client-go v1.48.5 h1:q8v8oZ2HwwVw6+ZCwKbuIpUmxpWUeZzvTASQl/QKxKw=
97+
github.com/jfrog/jfrog-client-go v1.48.5/go.mod h1:2ySOMva54L3EYYIlCBYBTcTgqfrrQ19gtpA/MWfA/ec=
9898
github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4=
9999
github.com/kevinburke/ssh_config v1.2.0/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM=
100100
github.com/klauspost/compress v1.4.1/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package usage
22

33
import (
4-
"encoding/json"
54
"os"
65

76
"github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
87
"github.com/jfrog/jfrog-cli-core/v2/utils/config"
98
"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
9+
"github.com/jfrog/jfrog-client-go/jfconnect/services"
1010
)
1111

1212
type VisibilitySystemManager struct {
@@ -19,24 +19,8 @@ func NewVisibilitySystemManager(serverDetails *config.ServerDetails) *Visibility
1919
}
2020
}
2121

22-
type labels struct {
23-
ProductID string `json:"product_id"`
24-
FeatureID string `json:"feature_id"`
25-
OIDCUsed string `json:"oidc_used"`
26-
JobID string `json:"job_id"`
27-
RunID string `json:"run_id"`
28-
GitRepo string `json:"git_repo"`
29-
GhTokenForCodeScanningAlertsProvided string `json:"gh_token_for_code_scanning_alerts_provided"`
30-
}
31-
32-
type visibilityMetric struct {
33-
Value int `json:"value"`
34-
MetricsName string `json:"metrics_name"`
35-
Labels labels `json:"labels"`
36-
}
37-
38-
func (vsm *VisibilitySystemManager) createMetric(commandName string) ([]byte, error) {
39-
metricLabels := labels{
22+
func (vsm *VisibilitySystemManager) createMetric(commandName string) services.VisibilityMetric {
23+
metricLabels := services.Labels{
4024
ProductID: coreutils.GetCliUserAgentName(),
4125
FeatureID: commandName,
4226
OIDCUsed: os.Getenv("JFROG_CLI_USAGE_OIDC_USED"),
@@ -46,23 +30,17 @@ func (vsm *VisibilitySystemManager) createMetric(commandName string) ([]byte, er
4630
GhTokenForCodeScanningAlertsProvided: os.Getenv("JFROG_CLI_USAGE_GH_TOKEN_FOR_CODE_SCANNING_ALERTS_PROVIDED"),
4731
}
4832

49-
metric := visibilityMetric{
33+
return services.VisibilityMetric{
5034
Value: 1,
5135
MetricsName: "jfcli_commands_count",
5236
Labels: metricLabels,
5337
}
54-
55-
return json.Marshal(metric)
5638
}
5739

5840
func (vsm *VisibilitySystemManager) SendUsage(commandName string) error {
5941
manager, err := utils.CreateJfConnectServiceManager(vsm.serverDetails)
6042
if err != nil {
6143
return err
6244
}
63-
metric, err := vsm.createMetric(commandName)
64-
if err != nil {
65-
return err
66-
}
67-
return manager.PostMetric(metric)
45+
return manager.PostVisibilityMetric(vsm.createMetric(commandName))
6846
}

utils/usage/visibility_system_manager_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package usage
22

33
import (
4+
"encoding/json"
45
"testing"
56

67
"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
@@ -29,7 +30,8 @@ func TestCreateMetric(t *testing.T) {
2930
}()
3031

3132
commandName := "testCommand"
32-
metric, err := NewVisibilitySystemManager(nil).createMetric(commandName)
33+
metric := NewVisibilitySystemManager(nil).createMetric(commandName)
34+
metricJSON, err := json.Marshal(metric)
3335
assert.NoError(t, err)
3436

3537
// Define the expected JSON structure
@@ -48,5 +50,5 @@ func TestCreateMetric(t *testing.T) {
4850
}`
4951

5052
// Compare the generated JSON to the expected JSON
51-
assert.JSONEq(t, expectedJSON, string(metric))
53+
assert.JSONEq(t, expectedJSON, string(metricJSON))
5254
}

0 commit comments

Comments
 (0)