Skip to content

Commit

Permalink
Visibility - update commands count metric to correspond with client i…
Browse files Browse the repository at this point in the history
…mprovements
  • Loading branch information
omerzi committed Jan 15, 2025
1 parent 66660ff commit 5573f66
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 15 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ require (
gopkg.in/warnings.v0 v0.1.2 // indirect
)

// replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go v1.28.1-0.20241225183733-80a5e1ba7a2c
replace github.com/jfrog/jfrog-client-go => github.com/omerzi/jfrog-client-go v1.13.2-0.20250114141023-3e8625108e2b

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

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@ github.com/jfrog/build-info-go v1.10.8 h1:8D4wtvKzLS1hzfDWtfH4OliZLtLCgL62tXCnGW
github.com/jfrog/build-info-go v1.10.8/go.mod h1:JcISnovFXKx3wWf3p1fcMmlPdt6adxScXvoJN4WXqIE=
github.com/jfrog/gofrog v1.7.6 h1:QmfAiRzVyaI7JYGsB7cxfAJePAZTzFz0gRWZSE27c6s=
github.com/jfrog/gofrog v1.7.6/go.mod h1:ntr1txqNOZtHplmaNd7rS4f8jpA5Apx8em70oYEe7+4=
github.com/jfrog/jfrog-client-go v1.49.0 h1:NaTK6+LQBEJafL//6ntnS/eVx1dZMJnxydALwWHKORQ=
github.com/jfrog/jfrog-client-go v1.49.0/go.mod h1:ohIfKpMBCQsE9kunrKQ1wvoExpqsPLaluRFO186B5EM=
github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4=
github.com/kevinburke/ssh_config v1.2.0/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM=
github.com/klauspost/compress v1.4.1/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
Expand Down Expand Up @@ -138,6 +136,8 @@ github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyua
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/nwaples/rardecode v1.1.3 h1:cWCaZwfM5H7nAD6PyEdcVnczzV8i/JtotnyW/dD9lEc=
github.com/nwaples/rardecode v1.1.3/go.mod h1:5DzqNKiOdpKKBH87u8VlvAnPZMXcGRhxWkRpHbbfGS0=
github.com/omerzi/jfrog-client-go v1.13.2-0.20250114141023-3e8625108e2b h1:pUy1KFONlfsjunVBQTbXpyHR1TZPhIaM9rIhKPL2ZLE=
github.com/omerzi/jfrog-client-go v1.13.2-0.20250114141023-3e8625108e2b/go.mod h1:ohIfKpMBCQsE9kunrKQ1wvoExpqsPLaluRFO186B5EM=
github.com/onsi/gomega v1.34.1 h1:EUMJIKUjM8sKjYbtxQI9A4z2o+rruxnzNvpknOXie6k=
github.com/onsi/gomega v1.34.1/go.mod h1:kU1QgUvBDLXBJq618Xvm2LUX6rSAfRaFRTcdOeDLwwY=
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
Expand Down
16 changes: 6 additions & 10 deletions utils/usage/visibility_system_manager.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package usage

import (
"github.com/jfrog/jfrog-client-go/jfconnect/services/metrics/jfrogcli"
"os"

"github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
"github.com/jfrog/jfrog-cli-core/v2/utils/config"
"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
"github.com/jfrog/jfrog-client-go/jfconnect/services"
)

type VisibilitySystemManager struct {
Expand All @@ -19,8 +19,9 @@ func NewVisibilitySystemManager(serverDetails *config.ServerDetails) *Visibility
}
}

func (vsm *VisibilitySystemManager) createMetric(commandName string) services.VisibilityMetric {
metricLabels := services.Labels{
func (vsm *VisibilitySystemManager) createCommandsCountMetric(commandName string) *jfrogcli.CommandsCountMetric {
metricLabels := jfrogcli.NewCommandsCountMetric()
metricLabels.Labels = jfrogcli.CommandsCountLabels{
ProductID: coreutils.GetCliUserAgentName(),
ProductVersion: coreutils.GetCliUserAgentVersion(),
FeatureID: commandName,
Expand All @@ -30,18 +31,13 @@ func (vsm *VisibilitySystemManager) createMetric(commandName string) services.Vi
GitRepo: os.Getenv("JFROG_CLI_USAGE_GIT_REPO"),
GhTokenForCodeScanningAlertsProvided: os.Getenv("JFROG_CLI_USAGE_GH_TOKEN_FOR_CODE_SCANNING_ALERTS_PROVIDED"),
}

return services.VisibilityMetric{
Value: 1,
MetricsName: "jfcli_commands_count",
Labels: metricLabels,
}
return &metricLabels
}

func (vsm *VisibilitySystemManager) SendUsage(commandName string) error {
manager, err := utils.CreateJfConnectServiceManager(vsm.serverDetails, 0, 0)
if err != nil {
return err
}
return manager.PostVisibilityMetric(vsm.createMetric(commandName))
return manager.PostVisibilityMetric(vsm.createCommandsCountMetric(commandName))
}
4 changes: 2 additions & 2 deletions utils/usage/visibility_system_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/stretchr/testify/assert"
)

func TestCreateMetric(t *testing.T) {
func TestCreateCommandsCountMetric(t *testing.T) {
// Set environment variables for the test using SetEnvWithCallbackAndAssert
envVars := map[string]string{
"JFROG_CLI_USAGE_OIDC_USED": "TRUE",
Expand All @@ -30,7 +30,7 @@ func TestCreateMetric(t *testing.T) {
}()

commandName := "testCommand"
metric := NewVisibilitySystemManager(nil).createMetric(commandName)
metric := NewVisibilitySystemManager(nil).createCommandsCountMetric(commandName)
metricJSON, err := json.Marshal(metric)
assert.NoError(t, err)

Expand Down

0 comments on commit 5573f66

Please sign in to comment.