Skip to content

Commit

Permalink
refactor: Add subsystem to static metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidNix authored May 11, 2023
2 parents 8c8bdd9 + befd042 commit 05ab298
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions metrics/cosmos.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ func NewCosmos() *Cosmos {
return &Cosmos{
heightGauge: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: prometheus.BuildFQName(Namespace, CosmosSubsystem, "latest_block_height"),
Name: prometheus.BuildFQName(namespace, cosmosSubsystem, "latest_block_height"),
Help: "Latest block height of a cosmos node.",
},
// labels
[]string{"chain_id"},
),
valJailGauge: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: prometheus.BuildFQName(Namespace, CosmosValSubsystem, "latest_jailed_status"),
Name: prometheus.BuildFQName(namespace, cosmosValSubsystem, "latest_jailed_status"),
Help: "0 if the validator is not jailed. 1 if the validator is jailed. 2 if the validator is tombstoned.",
},
// labels
Expand Down
8 changes: 4 additions & 4 deletions metrics/metrics.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package metrics

const (
Namespace = "sl_exporter"
NoSubsystem = ""
CosmosSubsystem = "cosmos"
CosmosValSubsystem = CosmosSubsystem + "_val"
namespace = "sl_exporter"
staticSubsystem = "static"
cosmosSubsystem = "cosmos"
cosmosValSubsystem = cosmosSubsystem + "_val"
)
2 changes: 1 addition & 1 deletion metrics/static.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func BuildStatic(gauges []StaticGauge) []prometheus.Collector {
metrics := make([]prometheus.Collector, len(gauges))
for i, g := range gauges {
gaugeVec := prometheus.NewGaugeVec(
prometheus.GaugeOpts{Name: prometheus.BuildFQName(Namespace, NoSubsystem, g.Name), Help: g.Description},
prometheus.GaugeOpts{Name: prometheus.BuildFQName(namespace, staticSubsystem, g.Name), Help: g.Description},
g.Labels,
)
for _, sample := range g.Samples {
Expand Down
16 changes: 8 additions & 8 deletions metrics/static_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ func TestBuildStatic(t *testing.T) {
r := httptest.NewRecorder()
h.ServeHTTP(r, stubRequest)

const want = `# HELP sl_exporter_gauge_1 desc_1
# TYPE sl_exporter_gauge_1 gauge
sl_exporter_gauge_1{chain="agoric-1",denom="ubld"} 1
sl_exporter_gauge_1{chain="cosmoshub-4",denom="uatom"} 2
# HELP sl_exporter_gauge_2 desc_2
# TYPE sl_exporter_gauge_2 gauge
sl_exporter_gauge_2 3`
const want = `# HELP sl_exporter_static_gauge_1 desc_1
# TYPE sl_exporter_static_gauge_1 gauge
sl_exporter_static_gauge_1{chain="agoric-1",denom="ubld"} 1
sl_exporter_static_gauge_1{chain="cosmoshub-4",denom="uatom"} 2
# HELP sl_exporter_static_gauge_2 desc_2
# TYPE sl_exporter_static_gauge_2 gauge
sl_exporter_static_gauge_2 3`
require.Equal(t, want, strings.TrimSpace(r.Body.String()))
})

Expand All @@ -58,7 +58,7 @@ sl_exporter_gauge_2 3`
t.Run("invalid labels", func(t *testing.T) {
gauges := []StaticGauge{
{
Name: "sl_exporter_gauge_1",
Name: "sl_exporter_static_gauge_1",
Description: "desc_1",
Labels: []string{"chain", "denom"},
Samples: []StaticSample{
Expand Down

0 comments on commit 05ab298

Please sign in to comment.