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

export build version as a prometheus label #405

Merged
merged 3 commits into from Mar 26, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion main.go
Expand Up @@ -406,7 +406,7 @@ func Main(config *Config, configTest bool, buildVersion string, logger *logrus.L
go lightHouse.LhUpdateWorker(ifce)
}

err = startStats(config, configTest)
err = startStats(config, buildVersion, configTest)
if err != nil {
return nil, NewContextualError("Failed to start stats emitter", nil, err)
}
Expand Down
21 changes: 18 additions & 3 deletions stats.go
Expand Up @@ -6,6 +6,7 @@ import (
"log"
"net"
"net/http"
"runtime"
"time"

graphite "github.com/cyberdelia/go-metrics-graphite"
Expand All @@ -15,7 +16,7 @@ import (
"github.com/rcrowley/go-metrics"
)

func startStats(c *Config, configTest bool) error {
func startStats(c *Config, buildVersion string, configTest bool) error {
mType := c.GetString("stats.type", "")
if mType == "" || mType == "none" {
return nil
Expand All @@ -30,7 +31,7 @@ func startStats(c *Config, configTest bool) error {
case "graphite":
startGraphiteStats(interval, c, configTest)
case "prometheus":
startPrometheusStats(interval, c, configTest)
startPrometheusStats(interval, c, buildVersion, configTest)
default:
return fmt.Errorf("stats.type was not understood: %s", mType)
}
Expand Down Expand Up @@ -64,7 +65,7 @@ func startGraphiteStats(i time.Duration, c *Config, configTest bool) error {
return nil
}

func startPrometheusStats(i time.Duration, c *Config, configTest bool) error {
func startPrometheusStats(i time.Duration, c *Config, buildVersion string, configTest bool) error {
namespace := c.GetString("stats.namespace", "")
subsystem := c.GetString("stats.subsystem", "")

Expand All @@ -82,6 +83,20 @@ func startPrometheusStats(i time.Duration, c *Config, configTest bool) error {
pClient := mp.NewPrometheusProvider(metrics.DefaultRegistry, namespace, subsystem, pr, i)
go pClient.UpdatePrometheusMetrics()

// Export our version information as labels on a static gauge
g := prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: namespace,
Subsystem: subsystem,
Name: "info",
Help: "Version information for the Nebula binary",
ConstLabels: prometheus.Labels{
"version": buildVersion,
"goversion": runtime.Version(),
},
})
pr.MustRegister(g)
g.Set(1)

if !configTest {
go func() {
l.Infof("Prometheus stats listening on %s at %s", listen, path)
Expand Down