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

feat(kuma-cp): add basedOnKuma in cp_info metric #8218

Merged
merged 1 commit into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
17 changes: 6 additions & 11 deletions pkg/metrics/components/cp_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,13 @@ import (
)

func Setup(rt runtime.Runtime) error {
labels := version.Build.AsMap()
labels["instance_id"] = rt.GetInstanceId()
labels["cluster_id"] = rt.GetClusterId()
cpInfoMetric := prometheus.NewGaugeFunc(prometheus.GaugeOpts{
Name: "cp_info",
Help: "Static information about the CP instance",
ConstLabels: map[string]string{
"instance_id": rt.GetInstanceId(),
"cluster_id": rt.GetClusterId(),
"product": version.Product,
"version": version.Build.Version,
"build_date": version.Build.BuildDate,
"git_commit": version.Build.GitCommit,
"git_tag": version.Build.GitTag,
},
Name: "cp_info",
Help: "Static information about the CP instance",
ConstLabels: labels,
}, func() float64 {
return 1.0
})
Expand Down
27 changes: 26 additions & 1 deletion pkg/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,39 @@ func (b BuildInfo) FormatDetailedProductInfo() string {
)
}

func shortCommit(c string) string {
if len(c) < 7 {
return c
}
return c[:7]
}

func (b BuildInfo) AsMap() map[string]string {
res := map[string]string{
"product": b.Product,
"version": b.Version,
"build_date": b.BuildDate,
"git_commit": shortCommit(b.GitCommit),
"git_tag": b.GitTag,
}
if b.BasedOnKuma != "" {
res["based_on_kuma"] = shortCommit(b.BasedOnKuma)
}
return res
}

func (b BuildInfo) UserAgent(component string) string {
commit := shortCommit(b.GitCommit)
if b.BasedOnKuma != "" {
commit = fmt.Sprintf("%s/kuma-%s", commit, shortCommit(b.BasedOnKuma))
}
return fmt.Sprintf("%s/%s (%s; %s; %s/%s)",
component,
b.Version,
runtime.GOOS,
runtime.GOARCH,
b.Product,
b.GitCommit[:7])
commit)
}

var Build BuildInfo
Expand Down
Loading