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 version metrics and /health endpoint #96

Merged
merged 2 commits into from
May 7, 2024
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
73 changes: 72 additions & 1 deletion metrics.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package main

import "github.com/prometheus/client_golang/prometheus"
import (
"runtime/debug"
"time"

"github.com/prometheus/client_golang/prometheus"
)

// - RPC requests by method (counter)
// - Epochs available epoch_available{epoch="200"} = 1
Expand Down Expand Up @@ -74,3 +79,69 @@ var metrics_responseTimeHistogram = prometheus.NewHistogramVec(
},
[]string{"method"},
)

// - Version information of this binary
var metrics_version = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "version",
Help: "Version information of this binary",
},
[]string{"started_at", "tag", "commit", "compiler", "goarch", "goos", "goamd64", "vcs", "vcs_revision", "vcs_time", "vcs_modified"},
)

func init() {
// Add an entry to the metric with the version information.
labeledValues := map[string]string{
"started_at": StartedAt.Format(time.RFC3339),
"tag": GitTag,
"commit": GitCommit,
"compiler": "",
"goarch": "",
"goos": "",
"goamd64": "",
"vcs": "",
"vcs_revision": "",
"vcs_time": "",
"vcs_modified": "",
}
if info, ok := debug.ReadBuildInfo(); ok {
for _, setting := range info.Settings {
if isAnyOf(setting.Key,
"-compiler",
"GOARCH",
"GOOS",
"GOAMD64",
"vcs",
"vcs.revision",
"vcs.time",
"vcs.modified",
) {
switch setting.Key {
case "-compiler":
labeledValues["compiler"] = setting.Value
case "GOARCH":
labeledValues["goarch"] = setting.Value
case "GOOS":
labeledValues["goos"] = setting.Value
case "GOAMD64":
labeledValues["goamd64"] = setting.Value
case "vcs":
labeledValues["vcs"] = setting.Value
case "vcs.revision":
labeledValues["vcs_revision"] = setting.Value
case "vcs.time":
labeledValues["vcs_time"] = setting.Value
case "vcs.modified":
labeledValues["vcs_modified"] = setting.Value
}
}
}
}
metrics_version.With(labeledValues).Set(1)
}

var StartedAt = time.Now()

func GetUptime() time.Duration {
return time.Since(StartedAt)
}
8 changes: 8 additions & 0 deletions multiepoch.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,14 @@ func newMultiEpochHandler(handler *MultiEpoch, lsConf *ListenerConfig) func(ctx
handler(reqCtx)
return
}
{
// Handle the /health endpoint
if string(reqCtx.Path()) == "/health" && reqCtx.IsGet() {
method = "/health"
reqCtx.SetStatusCode(http.StatusOK)
return
}
}
}
{
// make sure the method is POST
Expand Down
Loading