Configure metrics wrapper with the "global" object, not just the fanout. (#9099)
This commit is contained in:
parent
a117cf7e73
commit
ebac0443d5
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
@ -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"}
|
||||
|
|
|
@ -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
|
||||
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue