Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Deploy Mode to usage stats. #5880

Merged
merged 6 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
}
3 changes: 3 additions & 0 deletions pkg/usagestats/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"runtime"
"time"

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

Expand All @@ -27,6 +28,7 @@ type Report struct {
Metrics map[string]interface{} `json:"metrics"`
Os string `json:"os"`
Arch string `json:"arch"`
DeployMode string `json:"deployMode"`
}

func sendReport(ctx context.Context, seed *AgentSeed, interval time.Time, metrics map[string]interface{}) error {
Expand All @@ -38,6 +40,7 @@ func sendReport(ctx context.Context, seed *AgentSeed, interval time.Time, metric
Arch: runtime.GOARCH,
Interval: interval,
Metrics: metrics,
DeployMode: useragent.GetDeployMode(),
}
out, err := json.MarshalIndent(report, "", " ")
if err != nil {
Expand Down