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 fd1af60 commit 57be869
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 37 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/omerzi/jfrog-client-go v1.13.2-0.20250115131143-bfbba9e884e6
replace github.com/jfrog/jfrog-client-go => github.com/omerzi/jfrog-client-go v1.13.2-0.20250115143237-d0737923e44a

// 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 @@ -136,8 +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.20250115131143-bfbba9e884e6 h1:BD/0tW5DpVV9PDf59hK6CzLGTUyn4u6Wa6ME8U/07bI=
github.com/omerzi/jfrog-client-go v1.13.2-0.20250115131143-bfbba9e884e6/go.mod h1:ohIfKpMBCQsE9kunrKQ1wvoExpqsPLaluRFO186B5EM=
github.com/omerzi/jfrog-client-go v1.13.2-0.20250115143237-d0737923e44a h1:eU0OqNeazwVddhb2d/fhVU2vio13U2VoCaY3C7ZCMNI=
github.com/omerzi/jfrog-client-go v1.13.2-0.20250115143237-d0737923e44a/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
31 changes: 20 additions & 11 deletions utils/usage/visibility/commands_count_metric.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
package visibility

import (
"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
"github.com/jfrog/jfrog-client-go/jfconnect/services"
"os"
)

func newCommandsCountMetric(commandName string) services.VisibilityMetric {
return services.VisibilityMetric{
Value: 1,
Name: "jfcli_commands_count",
Labels: newCommandsCountLabels(commandName),
}
}

type commandsCountLabels struct {
ProductID string `json:"product_id"`
ProductVersion string `json:"product_version"`
Expand All @@ -15,16 +25,15 @@ type commandsCountLabels struct {
GhTokenForCodeScanningAlertsProvided string `json:"gh_token_for_code_scanning_alerts_provided"`
}

type commandsCountMetric struct {
services.Metric `json:",inline"`
Labels commandsCountLabels `json:"labels"`
}

func newCommandsCountMetric() commandsCountMetric {
return commandsCountMetric{
Metric: services.Metric{
Value: 1,
Name: "jfcli_commands_count",
},
func newCommandsCountLabels(featureID string) *commandsCountLabels {
return &commandsCountLabels{
ProductID: coreutils.GetCliUserAgentName(),
ProductVersion: coreutils.GetCliUserAgentVersion(),
FeatureID: featureID,
OIDCUsed: os.Getenv("JFROG_CLI_USAGE_OIDC_USED"),
JobID: os.Getenv("JFROG_CLI_USAGE_JOB_ID"),
RunID: os.Getenv("JFROG_CLI_USAGE_RUN_ID"),
GitRepo: os.Getenv("JFROG_CLI_USAGE_GIT_REPO"),
GhTokenForCodeScanningAlertsProvided: os.Getenv("JFROG_CLI_USAGE_GH_TOKEN_FOR_CODE_SCANNING_ALERTS_PROVIDED"),
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ package visibility

import (
"encoding/json"
"testing"

"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
testsutils "github.com/jfrog/jfrog-client-go/utils/tests"
"github.com/stretchr/testify/assert"
"testing"
)

func TestCreateCommandsCountMetric(t *testing.T) {
Expand All @@ -30,7 +29,7 @@ func TestCreateCommandsCountMetric(t *testing.T) {
}()

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

Expand Down
21 changes: 1 addition & 20 deletions utils/usage/visibility/visibility_system_manager.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package visibility

import (
"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"
)

type VisibilitySystemManager struct {
Expand All @@ -18,26 +15,10 @@ func NewVisibilitySystemManager(serverDetails *config.ServerDetails) *Visibility
}
}

func (vsm *VisibilitySystemManager) createCommandsCountMetric(commandName string) commandsCountMetric {
metricLabels := newCommandsCountMetric()
metricLabels.Labels = commandsCountLabels{
ProductID: coreutils.GetCliUserAgentName(),
ProductVersion: coreutils.GetCliUserAgentVersion(),
FeatureID: commandName,
OIDCUsed: os.Getenv("JFROG_CLI_USAGE_OIDC_USED"),
JobID: os.Getenv("JFROG_CLI_USAGE_JOB_ID"),
RunID: os.Getenv("JFROG_CLI_USAGE_RUN_ID"),
GitRepo: os.Getenv("JFROG_CLI_USAGE_GIT_REPO"),
GhTokenForCodeScanningAlertsProvided: os.Getenv("JFROG_CLI_USAGE_GH_TOKEN_FOR_CODE_SCANNING_ALERTS_PROVIDED"),
}
return metricLabels
}

func (vsm *VisibilitySystemManager) SendUsage(commandName string) error {
manager, err := utils.CreateJfConnectServiceManager(vsm.serverDetails, 0, 0)
if err != nil {
return err
}
metric := vsm.createCommandsCountMetric(commandName)
return manager.PostVisibilityMetric(&metric)
return manager.PostVisibilityMetric(newCommandsCountMetric(commandName))
}

0 comments on commit 57be869

Please sign in to comment.