mirror of https://github.com/status-im/consul.git
fix some tests that were broken from the TelemetryConfig change
This commit is contained in:
parent
2fe021f03c
commit
ad4cebc1d8
|
@ -8,7 +8,6 @@ import (
|
|||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"github.com/armon/go-metrics/prometheus"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"os"
|
||||
|
@ -19,6 +18,8 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/armon/go-metrics/prometheus"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/hashicorp/consul/agent/cache"
|
||||
|
@ -7817,9 +7818,15 @@ func TestSanitize(t *testing.T) {
|
|||
"DogstatsdTags": [],
|
||||
"FilterDefault": false,
|
||||
"MetricsPrefix": "",
|
||||
"PrometheusRetentionTime": "0s",
|
||||
"StatsdAddr": "",
|
||||
"StatsiteAddr": ""
|
||||
"StatsiteAddr": "",
|
||||
"PrometheusOpts": {
|
||||
"Expiration": "0s",
|
||||
"Registerer": null,
|
||||
"GaugeDefinitions": [],
|
||||
"CounterDefinitions": [],
|
||||
"SummaryDefinitions": []
|
||||
}
|
||||
},
|
||||
"TranslateWANAddrs": false,
|
||||
"TxnMaxReqLen": 5678000000000000,
|
||||
|
|
|
@ -220,6 +220,10 @@ func (c *TelemetryConfig) MergeDefaults(defaults *TelemetryConfig) {
|
|||
// implementing this for the types we actually have for now. Test failure
|
||||
// should catch the case where we add new types later.
|
||||
switch f.Kind() {
|
||||
case reflect.Struct:
|
||||
if f.Type() == reflect.TypeOf(prometheus.PrometheusOpts{}) {
|
||||
continue
|
||||
}
|
||||
case reflect.Slice:
|
||||
if !f.IsNil() {
|
||||
continue
|
||||
|
@ -281,13 +285,7 @@ func prometheusSink(cfg TelemetryConfig, hostname string) (metrics.MetricSink, e
|
|||
return nil, nil
|
||||
}
|
||||
|
||||
prometheusOpts := prometheus.PrometheusOpts{
|
||||
Expiration: cfg.PrometheusOpts.Expiration,
|
||||
GaugeDefinitions: cfg.PrometheusOpts.GaugeDefinitions,
|
||||
CounterDefinitions: cfg.PrometheusOpts.CounterDefinitions,
|
||||
SummaryDefinitions: cfg.PrometheusOpts.SummaryDefinitions,
|
||||
}
|
||||
sink, err := prometheus.NewPrometheusSinkFrom(prometheusOpts)
|
||||
sink, err := prometheus.NewPrometheusSinkFrom(cfg.PrometheusOpts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -5,11 +5,14 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/armon/go-metrics/prometheus"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func makeFullTelemetryConfig(t *testing.T) TelemetryConfig {
|
||||
var (
|
||||
promOpts = prometheus.PrometheusOpts{}
|
||||
strSliceVal = []string{"foo"}
|
||||
strVal = "foo"
|
||||
intVal = int64(1 * time.Second)
|
||||
|
@ -27,6 +30,12 @@ func makeFullTelemetryConfig(t *testing.T) TelemetryConfig {
|
|||
// now for brevity but will fail the test if a new field type is added since
|
||||
// this is likely not implemented in MergeDefaults either.
|
||||
switch f.Kind() {
|
||||
case reflect.Struct:
|
||||
if f.Type() != reflect.TypeOf(promOpts) {
|
||||
t.Fatalf("unknown struct type in TelemetryConfig: actual %v, expected: %v", f.Type(), reflect.TypeOf(promOpts))
|
||||
}
|
||||
// TODO(kit): This should delve into the fields and set them individually rather than using an empty struct
|
||||
f.Set(reflect.ValueOf(promOpts))
|
||||
case reflect.Slice:
|
||||
if f.Type() != reflect.TypeOf(strSliceVal) {
|
||||
t.Fatalf("unknown slice type in TelemetryConfig." +
|
||||
|
|
Loading…
Reference in New Issue