Skip to content

Commit

Permalink
update to use PrometheusOpts in config
Browse files Browse the repository at this point in the history
Consul updated their prometheus telemetry setup to use
go-metrics/prometheus's options struct. This reflects that change and
the few tweaks needed related to that update.
  • Loading branch information
eikenb committed May 26, 2022
1 parent d959f58 commit 9a26477
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func (a *Agent) register() error {

// runMetrics is a long-running goroutine that exposes an http metrics interface
func (a *Agent) runMetrics() {
if a.config.Telemetry.PrometheusRetentionTime < 1 || a.config.ClientAddress == "" {
if a.config.Telemetry.PrometheusOpts.Expiration < 1 || a.config.ClientAddress == "" {
return
}

Expand Down
3 changes: 2 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strings"
"time"

"github.com/armon/go-metrics/prometheus"
"github.com/hashicorp/consul/api"
"github.com/hashicorp/consul/command/flags"
"github.com/hashicorp/consul/lib"
Expand Down Expand Up @@ -437,13 +438,13 @@ func convertTelemetry(telemetry Telemetry) (lib.TelemetryConfig, error) {
DisableHostname: boolVal(telemetry.DisableHostname),
DogstatsdAddr: stringVal(telemetry.DogstatsdAddr),
DogstatsdTags: telemetry.DogstatsdTags,
PrometheusRetentionTime: prometheusRetentionTime,
FilterDefault: boolVal(telemetry.FilterDefault),
AllowedPrefixes: telemetryAllowedPrefixes,
BlockedPrefixes: telemetryBlockedPrefixes,
MetricsPrefix: stringVal(telemetry.MetricsPrefix),
StatsdAddr: stringVal(telemetry.StatsdAddr),
StatsiteAddr: stringVal(telemetry.StatsiteAddr),
PrometheusOpts: prometheus.PrometheusOpts{Expiration: prometheusRetentionTime},
}, nil
}

Expand Down
17 changes: 11 additions & 6 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"testing"
"time"

"github.com/armon/go-metrics/prometheus"
"github.com/hashicorp/consul/lib"
"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -117,9 +118,11 @@ log_json = true
AllowedPrefixes: []string{"good", "better"},
BlockedPrefixes: []string{"bad", "worse"},
MetricsPrefix: "test",
PrometheusRetentionTime: 5 * time.Hour,
StatsdAddr: "example.io:8888",
StatsiteAddr: "5.6.7.8",
PrometheusOpts: prometheus.PrometheusOpts{
Expiration: 5 * time.Hour,
},
StatsdAddr: "example.io:8888",
StatsiteAddr: "5.6.7.8",
},
PassingThreshold: 3,
CriticalThreshold: 2,
Expand Down Expand Up @@ -255,9 +258,11 @@ func TestConvertTelemetry(t *testing.T) {
},
false,
lib.TelemetryConfig{
AllowedPrefixes: []string{"allow"},
BlockedPrefixes: []string{"deny"},
PrometheusRetentionTime: 1 * time.Minute,
AllowedPrefixes: []string{"allow"},
BlockedPrefixes: []string{"deny"},
PrometheusOpts: prometheus.PrometheusOpts{
Expiration: 1 * time.Minute,
},
},
},
{
Expand Down

0 comments on commit 9a26477

Please sign in to comment.