Skip to content

Commit

Permalink
Internal - Set a min Artifactory version for Visibility System usage (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
eyalbe4 authored Dec 25, 2024
1 parent 8cd365a commit dfeb70c
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 29 deletions.
2 changes: 1 addition & 1 deletion artifactory/commands/transferfiles/transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ func (tdc *TransferFilesCommand) reportTransferFilesUsage() {
AttributeValue: sourceStorageInfo.BinariesSize,
},
}
if err = usage.NewArtifactoryCallHome().SendUsage(coreutils.GetCliUserAgent(), tdc.CommandName(), tdc.targetStorageInfoManager.GetServiceManager(), reportUsageAttributes...); err != nil {
if err = usage.NewArtifactoryCallHome().Send(coreutils.GetCliUserAgent(), tdc.CommandName(), tdc.targetStorageInfoManager.GetServiceManager(), reportUsageAttributes...); err != nil {
log.Debug(err.Error())
}
}
Expand Down
4 changes: 3 additions & 1 deletion artifactory/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ func CreateMetadataServiceManager(serviceDetails *config.ServerDetails, isDryRun
return metadata.NewManager(serviceConfig)
}

func CreateJfConnectServiceManager(serverDetails *config.ServerDetails) (jfconnect.Manager, error) {
func CreateJfConnectServiceManager(serverDetails *config.ServerDetails, httpRetries, httpRetryWaitMilliSecs int) (jfconnect.Manager, error) {
certsPath, err := coreutils.GetJfrogCertsDir()
if err != nil {
return nil, err
Expand All @@ -275,6 +275,8 @@ func CreateJfConnectServiceManager(serverDetails *config.ServerDetails) (jfconne
SetServiceDetails(jfConnectAuth).
SetCertificatesPath(certsPath).
SetInsecureTls(serverDetails.InsecureTls).
SetHttpRetries(httpRetries).
SetHttpRetryWaitMilliSecs(httpRetryWaitMilliSecs).
Build()
if err != nil {
return nil, err
Expand Down
59 changes: 37 additions & 22 deletions common/commands/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,22 @@ package commands
import (
"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"
"github.com/jfrog/jfrog-client-go/utils/log"
)

const (
minCallHomeArtifactoryVersion = "6.9.0"
minVisibilitySystemArtifactoryVersion = "7.102"
)

type Command interface {
// Runs the command
Run() error
Expand Down Expand Up @@ -43,32 +50,45 @@ func reportUsage(command Command, channel chan<- bool) {

serverDetails, err := command.ServerDetails()
if err != nil {
log.Debug("Usage reporting:", err.Error())
log.Debug("Usage reporting. Failed accessing ServerDetails.", err.Error())
return
}
if serverDetails == nil || serverDetails.ArtifactoryUrl == "" {
return
}
serviceManager, err := utils.CreateServiceManager(serverDetails, -1, 0, false)
if err != nil {
log.Debug("Usage reporting. Failed creating the Artifactory Service Manager.", err.Error())
return
}
artifactoryVersion, err := serviceManager.GetVersion()
if err != nil {
log.Debug("Usage reporting. Failed getting the version of Artifactory", err.Error())
return
}

if serverDetails != nil {
var wg sync.WaitGroup
var wg sync.WaitGroup

// Report the usage to Artifactory's Call Home API.
if serverDetails.ArtifactoryUrl != "" {
wg.Add(1)
go func() {
defer wg.Done()
reportUsageToArtifactoryCallHome(command, serverDetails)
}()
}
// Report the usage to Artifactory's Call Home API.
if version.NewVersion(artifactoryVersion).AtLeast(minCallHomeArtifactoryVersion) {
wg.Add(1)
go func() {
defer wg.Done()
reportUsageToArtifactoryCallHome(command, serviceManager)
}()
}

// Report the usage to the Visibility System.
// Report the usage to the Visibility System.
if version.NewVersion(artifactoryVersion).AtLeast(minVisibilitySystemArtifactoryVersion) {
wg.Add(1)
go func() {
defer wg.Done()
reportUsageToVisibilitySystem(command, serverDetails)
}()

// Wait for the two report actions to finish.
wg.Wait()
}

// Wait for the two report actions to finish.
wg.Wait()
}

func reportUsageToVisibilitySystem(command Command, serverDetails *config.ServerDetails) {
Expand All @@ -77,14 +97,9 @@ func reportUsageToVisibilitySystem(command Command, serverDetails *config.Server
}
}

func reportUsageToArtifactoryCallHome(command Command, serverDetails *config.ServerDetails) {
func reportUsageToArtifactoryCallHome(command Command, serviceManager rtClient.ArtifactoryServicesManager) {
log.Debug(usageReporter.ArtifactoryCallHomePrefix, "Sending info...")
serviceManager, err := utils.CreateServiceManager(serverDetails, -1, 0, false)
if err != nil {
log.Debug(usageReporter.ArtifactoryCallHomePrefix, err.Error())
return
}
if err = usage.NewArtifactoryCallHome().SendUsage(coreutils.GetCliUserAgent(), command.CommandName(), serviceManager); err != nil {
if err := usage.NewArtifactoryCallHome().Send(coreutils.GetCliUserAgent(), command.CommandName(), serviceManager); err != nil {
log.Debug(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/jfrog/jfrog-client-go v1.28.1-0.20241223175448-88f1089d0694
replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go v1.28.1-0.20241225183733-80a5e1ba7a2c

// 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,8 @@ github.com/jfrog/build-info-go v1.10.7 h1:10NVHYg0193gJpQft+S4WQfvYMtj5jlwwhJRvk
github.com/jfrog/build-info-go v1.10.7/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.28.1-0.20241223175448-88f1089d0694 h1:1EP8yAhB+SGTXhfGa/w4S748S12qJKXU4u/yiAJxnX0=
github.com/jfrog/jfrog-client-go v1.28.1-0.20241223175448-88f1089d0694/go.mod h1:2ySOMva54L3EYYIlCBYBTcTgqfrrQ19gtpA/MWfA/ec=
github.com/jfrog/jfrog-client-go v1.28.1-0.20241225183733-80a5e1ba7a2c h1:MoNDrchpG4Bf0Buy6OwTk9G+bCjPf1UjMK99mop0zxQ=
github.com/jfrog/jfrog-client-go v1.28.1-0.20241225183733-80a5e1ba7a2c/go.mod h1:2ySOMva54L3EYYIlCBYBTcTgqfrrQ19gtpA/MWfA/ec=
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
2 changes: 1 addition & 1 deletion utils/usage/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func (ur *UsageReporter) reportToArtifactory(features ...ReportFeature) (err err
if err != nil {
return
}
return usage.NewArtifactoryCallHome().SendUsageToArtifactory(ur.ProductId, serviceManager, converted...)
return usage.NewArtifactoryCallHome().SendToArtifactory(ur.ProductId, serviceManager, converted...)
}

func convertAttributesToMap(reportFeature ReportFeature) (converted map[string]string) {
Expand Down
2 changes: 1 addition & 1 deletion utils/usage/visibility_system_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (vsm *VisibilitySystemManager) createMetric(commandName string) services.Vi
}

func (vsm *VisibilitySystemManager) SendUsage(commandName string) error {
manager, err := utils.CreateJfConnectServiceManager(vsm.serverDetails)
manager, err := utils.CreateJfConnectServiceManager(vsm.serverDetails, -1, 0)
if err != nil {
return err
}
Expand Down

0 comments on commit dfeb70c

Please sign in to comment.