Skip to content

Commit

Permalink
use common deploymod code. try to detect homebrew
Browse files Browse the repository at this point in the history
  • Loading branch information
captncraig committed Nov 29, 2023
1 parent a98b2bf commit c718c12
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
10 changes: 8 additions & 2 deletions internal/useragent/useragent.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func Get() string {
metadata = append(metadata, mode)
}
metadata = append(metadata, goos)
if op := getDeployMode(); op != "" {
if op := GetDeployMode(); op != "" {
metadata = append(metadata, op)
}
if len(metadata) > 0 {
Expand All @@ -49,12 +49,18 @@ func getRunMode() string {
}
}

func getDeployMode() string {
// GetDeployMode returns our best-effort guess at the way Grafana Agent was deployed.
func GetDeployMode() string {
op := os.Getenv(deployModeEnv)
// only return known modes. Use "binary" as a default catch-all.
switch op {
case "operator", "helm", "docker", "deb", "rpm", "brew":
return op
}
// try to detect if executable is in homebrew directory
if path, err := os.Executable(); err == nil && runtime.GOOS == "darwin" && strings.Contains(path, "brew") {
return "brew"
}
// fallback to binary
return "binary"
}
14 changes: 2 additions & 12 deletions pkg/usagestats/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (
"fmt"
"io"
"net/http"
"os"
"runtime"
"time"

"github.com/grafana/agent/internal/useragent"
"github.com/prometheus/common/version"
)

Expand Down Expand Up @@ -40,7 +40,7 @@ func sendReport(ctx context.Context, seed *AgentSeed, interval time.Time, metric
Arch: runtime.GOARCH,
Interval: interval,
Metrics: metrics,
DeployMode: getDeployMode(),
DeployMode: useragent.GetDeployMode(),
}
out, err := json.MarshalIndent(report, "", " ")
if err != nil {
Expand All @@ -66,13 +66,3 @@ func sendReport(ctx context.Context, seed *AgentSeed, interval time.Time, metric
}
return nil
}

func getDeployMode() string {
op := os.Getenv("AGENT_DEPLOY_MODE")
// only return known modes. Use "binary" as a default catch-all.
switch op {
case "operator", "helm", "docker", "deb", "rpm", "brew":
return op
}
return "binary"
}

0 comments on commit c718c12

Please sign in to comment.