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 703bcd7 commit ba5e3f0
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 11 deletions.
4 changes: 2 additions & 2 deletions common/commands/command.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package commands

import (
"github.com/jfrog/jfrog-cli-core/v2/utils/usage/visibility"
"sync"

"github.com/jfrog/gofrog/version"
"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"
coreusage "github.com/jfrog/jfrog-cli-core/v2/utils/usage"
usageReporter "github.com/jfrog/jfrog-cli-core/v2/utils/usage"
rtClient "github.com/jfrog/jfrog-client-go/artifactory"
"github.com/jfrog/jfrog-client-go/artifactory/usage"
Expand Down Expand Up @@ -92,7 +92,7 @@ func reportUsage(command Command, channel chan<- bool) {
}

func reportUsageToVisibilitySystem(command Command, serverDetails *config.ServerDetails) {
if err := coreusage.NewVisibilitySystemManager(serverDetails).SendUsage(command.CommandName()); err != nil {
if err := visibility.NewVisibilitySystemManager(serverDetails).SendUsage(command.CommandName()); err != nil {
log.Debug("Visibility System Usage reporting:", err.Error())
}
}
Expand Down
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.20250115073108-4c3ba3651493
replace github.com/jfrog/jfrog-client-go => github.com/omerzi/jfrog-client-go v1.13.2-0.20250115125705-489947a67e4e

// 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.20250115073108-4c3ba3651493 h1:bBqa4ZoPuABhJj5Smo3C7r0Sx9f5feYcrpJEHTFNy/w=
github.com/omerzi/jfrog-client-go v1.13.2-0.20250115073108-4c3ba3651493/go.mod h1:ohIfKpMBCQsE9kunrKQ1wvoExpqsPLaluRFO186B5EM=
github.com/omerzi/jfrog-client-go v1.13.2-0.20250115125705-489947a67e4e h1:1AGK2NwuwvstzPtlkLgC6z5IEAMd9b0e5lkEgNBCegg=
github.com/omerzi/jfrog-client-go v1.13.2-0.20250115125705-489947a67e4e/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
38 changes: 38 additions & 0 deletions utils/usage/visibility/commands_count_metric.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package visibility

import (
"github.com/jfrog/jfrog-client-go/jfconnect/services"
)

type commandsCountLabels struct {
ProductID string `json:"product_id"`
ProductVersion string `json:"product_version"`
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 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 (ccm *commandsCountMetric) MetricsName() string {
return ccm.Name
}

func (ccm *commandsCountMetric) Value() int {
return ccm.Metric.Value
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package usage
package visibility

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

"github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
Expand All @@ -19,9 +18,9 @@ func NewVisibilitySystemManager(serverDetails *config.ServerDetails) *Visibility
}
}

func (vsm *VisibilitySystemManager) createCommandsCountMetric(commandName string) *jfrogcli.CommandsCountMetric {
metricLabels := jfrogcli.NewCommandsCountMetric()
metricLabels.Labels = jfrogcli.CommandsCountLabels{
func (vsm *VisibilitySystemManager) createCommandsCountMetric(commandName string) *commandsCountMetric {
metricLabels := newCommandsCountMetric()
metricLabels.Labels = commandsCountLabels{
ProductID: coreutils.GetCliUserAgentName(),
ProductVersion: coreutils.GetCliUserAgentVersion(),
FeatureID: commandName,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package usage
package visibility

import (
"encoding/json"
Expand Down

0 comments on commit ba5e3f0

Please sign in to comment.