-
Notifications
You must be signed in to change notification settings - Fork 916
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: add operator build_info metrics and go runtime metrics #6044
base: master
Are you sure you want to change the base?
Changes from 7 commits
3f919e8
fb2da37
851c785
e1acbcf
5868c91
4880924
a65fcac
d7fd1fd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,13 +19,17 @@ package version | |
import ( | ||
"fmt" | ||
"runtime" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
) | ||
|
||
// Info contains versioning information. | ||
type Info struct { | ||
GitVersion string `json:"gitVersion"` | ||
GitCommit string `json:"gitCommit"` | ||
GitRevision string `json:"gitRevision"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
GitTreeState string `json:"gitTreeState"` | ||
GitBranch string `json:"gitBranch"` | ||
BuildDate string `json:"buildDate"` | ||
GoVersion string `json:"goVersion"` | ||
Compiler string `json:"compiler"` | ||
|
@@ -42,11 +46,39 @@ func (info Info) String() string { | |
func Get() Info { | ||
return Info{ | ||
GitVersion: gitVersion, | ||
GitRevision: gitRevision, | ||
GitCommit: gitCommit, | ||
GitTreeState: gitTreeState, | ||
GitBranch: gitBranch, | ||
BuildDate: buildDate, | ||
GoVersion: runtime.Version(), | ||
Compiler: runtime.Compiler, | ||
Platform: fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH), | ||
} | ||
} | ||
|
||
// NewCollector returns a collector that exports metrics about current version | ||
// information. | ||
func NewCollector(program string) prometheus.Collector { | ||
return prometheus.NewGaugeFunc( | ||
prometheus.GaugeOpts{ | ||
Namespace: program, | ||
Name: "build_info", | ||
Help: fmt.Sprintf( | ||
"A metric with a constant '1' value labeled by version, revision, branch, goversion from which %s was built, and the goos and goarch for the build.", | ||
program, | ||
), | ||
ConstLabels: prometheus.Labels{ | ||
"version": Get().GitVersion, | ||
"revision": Get().GitRevision, | ||
"branch": Get().GitBranch, | ||
"goversion": runtime.Version(), | ||
"goos": runtime.GOOS, | ||
"goarch": runtime.GOARCH, | ||
"compiler": runtime.Compiler, | ||
"platform": fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH), | ||
}, | ||
}, | ||
func() float64 { return 1 }, | ||
) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not familiar with these metrics either.
Could you add some simple comments indicating the purpose or usage of each metric?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @chaosi-zju .
I got it.
Add comments for each metric.
Please re-check it.
BTW, I will extend these metrics to all other components.