Skip to content

Commit 57be869

Browse files
committed
Visibility - update commands count metric to correspond with client improvements
1 parent fd1af60 commit 57be869

File tree

5 files changed

+26
-37
lines changed

5 files changed

+26
-37
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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/omerzi/jfrog-client-go v1.13.2-0.20250115131143-bfbba9e884e6
99+
replace github.com/jfrog/jfrog-client-go => github.com/omerzi/jfrog-client-go v1.13.2-0.20250115143237-d0737923e44a
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
@@ -136,8 +136,8 @@ github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyua
136136
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
137137
github.com/nwaples/rardecode v1.1.3 h1:cWCaZwfM5H7nAD6PyEdcVnczzV8i/JtotnyW/dD9lEc=
138138
github.com/nwaples/rardecode v1.1.3/go.mod h1:5DzqNKiOdpKKBH87u8VlvAnPZMXcGRhxWkRpHbbfGS0=
139-
github.com/omerzi/jfrog-client-go v1.13.2-0.20250115131143-bfbba9e884e6 h1:BD/0tW5DpVV9PDf59hK6CzLGTUyn4u6Wa6ME8U/07bI=
140-
github.com/omerzi/jfrog-client-go v1.13.2-0.20250115131143-bfbba9e884e6/go.mod h1:ohIfKpMBCQsE9kunrKQ1wvoExpqsPLaluRFO186B5EM=
139+
github.com/omerzi/jfrog-client-go v1.13.2-0.20250115143237-d0737923e44a h1:eU0OqNeazwVddhb2d/fhVU2vio13U2VoCaY3C7ZCMNI=
140+
github.com/omerzi/jfrog-client-go v1.13.2-0.20250115143237-d0737923e44a/go.mod h1:ohIfKpMBCQsE9kunrKQ1wvoExpqsPLaluRFO186B5EM=
141141
github.com/onsi/gomega v1.34.1 h1:EUMJIKUjM8sKjYbtxQI9A4z2o+rruxnzNvpknOXie6k=
142142
github.com/onsi/gomega v1.34.1/go.mod h1:kU1QgUvBDLXBJq618Xvm2LUX6rSAfRaFRTcdOeDLwwY=
143143
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
package visibility
22

33
import (
4+
"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
45
"github.com/jfrog/jfrog-client-go/jfconnect/services"
6+
"os"
57
)
68

9+
func newCommandsCountMetric(commandName string) services.VisibilityMetric {
10+
return services.VisibilityMetric{
11+
Value: 1,
12+
Name: "jfcli_commands_count",
13+
Labels: newCommandsCountLabels(commandName),
14+
}
15+
}
16+
717
type commandsCountLabels struct {
818
ProductID string `json:"product_id"`
919
ProductVersion string `json:"product_version"`
@@ -15,16 +25,15 @@ type commandsCountLabels struct {
1525
GhTokenForCodeScanningAlertsProvided string `json:"gh_token_for_code_scanning_alerts_provided"`
1626
}
1727

18-
type commandsCountMetric struct {
19-
services.Metric `json:",inline"`
20-
Labels commandsCountLabels `json:"labels"`
21-
}
22-
23-
func newCommandsCountMetric() commandsCountMetric {
24-
return commandsCountMetric{
25-
Metric: services.Metric{
26-
Value: 1,
27-
Name: "jfcli_commands_count",
28-
},
28+
func newCommandsCountLabels(featureID string) *commandsCountLabels {
29+
return &commandsCountLabels{
30+
ProductID: coreutils.GetCliUserAgentName(),
31+
ProductVersion: coreutils.GetCliUserAgentVersion(),
32+
FeatureID: featureID,
33+
OIDCUsed: os.Getenv("JFROG_CLI_USAGE_OIDC_USED"),
34+
JobID: os.Getenv("JFROG_CLI_USAGE_JOB_ID"),
35+
RunID: os.Getenv("JFROG_CLI_USAGE_RUN_ID"),
36+
GitRepo: os.Getenv("JFROG_CLI_USAGE_GIT_REPO"),
37+
GhTokenForCodeScanningAlertsProvided: os.Getenv("JFROG_CLI_USAGE_GH_TOKEN_FOR_CODE_SCANNING_ALERTS_PROVIDED"),
2938
}
3039
}

utils/usage/visibility/visibility_system_manager_test.go renamed to utils/usage/visibility/commands_count_metric_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@ package visibility
22

33
import (
44
"encoding/json"
5-
"testing"
6-
75
"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
86
testsutils "github.com/jfrog/jfrog-client-go/utils/tests"
97
"github.com/stretchr/testify/assert"
8+
"testing"
109
)
1110

1211
func TestCreateCommandsCountMetric(t *testing.T) {
@@ -30,7 +29,7 @@ func TestCreateCommandsCountMetric(t *testing.T) {
3029
}()
3130

3231
commandName := "testCommand"
33-
metric := NewVisibilitySystemManager(nil).createCommandsCountMetric(commandName)
32+
metric := newCommandsCountMetric(commandName)
3433
metricJSON, err := json.Marshal(metric)
3534
assert.NoError(t, err)
3635

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
package visibility
22

33
import (
4-
"os"
5-
64
"github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
75
"github.com/jfrog/jfrog-cli-core/v2/utils/config"
8-
"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
96
)
107

118
type VisibilitySystemManager struct {
@@ -18,26 +15,10 @@ func NewVisibilitySystemManager(serverDetails *config.ServerDetails) *Visibility
1815
}
1916
}
2017

21-
func (vsm *VisibilitySystemManager) createCommandsCountMetric(commandName string) commandsCountMetric {
22-
metricLabels := newCommandsCountMetric()
23-
metricLabels.Labels = commandsCountLabels{
24-
ProductID: coreutils.GetCliUserAgentName(),
25-
ProductVersion: coreutils.GetCliUserAgentVersion(),
26-
FeatureID: commandName,
27-
OIDCUsed: os.Getenv("JFROG_CLI_USAGE_OIDC_USED"),
28-
JobID: os.Getenv("JFROG_CLI_USAGE_JOB_ID"),
29-
RunID: os.Getenv("JFROG_CLI_USAGE_RUN_ID"),
30-
GitRepo: os.Getenv("JFROG_CLI_USAGE_GIT_REPO"),
31-
GhTokenForCodeScanningAlertsProvided: os.Getenv("JFROG_CLI_USAGE_GH_TOKEN_FOR_CODE_SCANNING_ALERTS_PROVIDED"),
32-
}
33-
return metricLabels
34-
}
35-
3618
func (vsm *VisibilitySystemManager) SendUsage(commandName string) error {
3719
manager, err := utils.CreateJfConnectServiceManager(vsm.serverDetails, 0, 0)
3820
if err != nil {
3921
return err
4022
}
41-
metric := vsm.createCommandsCountMetric(commandName)
42-
return manager.PostVisibilityMetric(&metric)
23+
return manager.PostVisibilityMetric(newCommandsCountMetric(commandName))
4324
}

0 commit comments

Comments
 (0)