Skip to content

Commit

Permalink
Configure metrics wrapper with the "global" object, not just the fano…
Browse files Browse the repository at this point in the history
…ut. (#9099)
  • Loading branch information
Mark Gritter authored and andaley committed Jul 17, 2020
1 parent 09715bd commit c49c6a6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
6 changes: 4 additions & 2 deletions helper/metricsutil/wrapped_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type ClusterMetricSink struct {
MaxGaugeCardinality int
GaugeInterval time.Duration

// Sink is the go-metrics sink to send to
// Sink is the go-metrics instance to send to.
Sink metrics.MetricSink
}

Expand Down Expand Up @@ -57,9 +57,11 @@ func (m *ClusterMetricSink) MeasureSinceWithLabels(key []string, start time.Time

// BlackholeSink is a default suitable for use in unit tests.
func BlackholeSink() *ClusterMetricSink {
sink, _ := metrics.New(metrics.DefaultConfig(""),
&metrics.BlackholeSink{})
return &ClusterMetricSink{
ClusterName: "",
Sink: &metrics.BlackholeSink{},
Sink: sink,
}
}

Expand Down
14 changes: 13 additions & 1 deletion helper/metricsutil/wrapped_metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ func isLabelPresent(toFind Label, ls []Label) bool {
return false
}

// We can use a sink directly, or wrap the top-level
// go-metrics implementation for testing purposes.
func defaultMetrics(sink metrics.MetricSink) *metrics.Metrics {
// No service name
config := metrics.DefaultConfig("")

// No host name
config.EnableHostname = false
m, _ := metrics.New(config, sink)
return m
}

func TestClusterLabelPresent(t *testing.T) {
testClusterName := "test-cluster"

Expand All @@ -28,7 +40,7 @@ func TestClusterLabelPresent(t *testing.T) {
2000000*time.Hour)
clusterSink := &ClusterMetricSink{
ClusterName: testClusterName,
Sink: inmemSink,
Sink: defaultMetrics(inmemSink),
}

key1 := []string{"aaa", "bbb"}
Expand Down
4 changes: 2 additions & 2 deletions internalshared/configutil/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ func SetupTelemetry(opts *SetupTelemetryOpts) (*metrics.InmemSink, *metricsutil.
metricsConf.EnableHostname = false
}
fanout = append(fanout, inm)
_, err := metrics.NewGlobal(metricsConf, fanout)
globalMetrics, err := metrics.NewGlobal(metricsConf, fanout)

if err != nil {
return nil, nil, false, err
Expand All @@ -332,7 +332,7 @@ func SetupTelemetry(opts *SetupTelemetryOpts) (*metrics.InmemSink, *metricsutil.
ClusterName: opts.ClusterName,
MaxGaugeCardinality: 500,
GaugeInterval: 10 * time.Minute,
Sink: fanout,
Sink: globalMetrics,
}

return inm, wrapper, prometheusEnabled, nil
Expand Down

0 comments on commit c49c6a6

Please sign in to comment.