mirror of https://github.com/hashicorp/consul
Revert telemetry config changes ready for cleaner approach
parent
32f362bad9
commit
9f559da913
|
@ -428,9 +428,6 @@ type Performance struct {
|
||||||
RPCHoldTimeout *string `json:"rpc_hold_timeout" hcl:"rpc_hold_timeout" mapstructure:"rpc_hold_timeout"`
|
RPCHoldTimeout *string `json:"rpc_hold_timeout" hcl:"rpc_hold_timeout" mapstructure:"rpc_hold_timeout"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Telemetry defines the configuration for logging telemetry. NOTE: that any
|
|
||||||
// additions here that are reflected in RuntimeConfig also need to be added to
|
|
||||||
// RuntimeConfig.TelemetryConfig.
|
|
||||||
type Telemetry struct {
|
type Telemetry struct {
|
||||||
CirconusAPIApp *string `json:"circonus_api_app,omitempty" hcl:"circonus_api_app" mapstructure:"circonus_api_app"`
|
CirconusAPIApp *string `json:"circonus_api_app,omitempty" hcl:"circonus_api_app" mapstructure:"circonus_api_app"`
|
||||||
CirconusAPIToken *string `json:"circonus_api_token,omitempty" json:"-" hcl:"circonus_api_token" mapstructure:"circonus_api_token" json:"-"`
|
CirconusAPIToken *string `json:"circonus_api_token,omitempty" json:"-" hcl:"circonus_api_token" mapstructure:"circonus_api_token" json:"-"`
|
||||||
|
|
|
@ -1331,69 +1331,6 @@ type RuntimeConfig struct {
|
||||||
Watches []map[string]interface{}
|
Watches []map[string]interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TelemetryConfig returns all the Telemetry fields in a map for passing on to
|
|
||||||
// other processes that need to share the same telemetry config. This method
|
|
||||||
// must be kept in sync with additions to Telemetry* configs above. includeEmpty
|
|
||||||
// is not really useful in practice but allows us to verify in tests using
|
|
||||||
// reflection that new fields were not missed. This method avoids runtime
|
|
||||||
// reflection however it's tests validate it's completeness using reflection.
|
|
||||||
func (c *RuntimeConfig) TelemetryConfig(includeEmpty bool) map[string]interface{} {
|
|
||||||
t := make(map[string]interface{})
|
|
||||||
|
|
||||||
addString := func(key string, val string) {
|
|
||||||
if !includeEmpty && val == "" {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
t[key] = val
|
|
||||||
}
|
|
||||||
|
|
||||||
addBool := func(key string, val bool) {
|
|
||||||
if !includeEmpty && !val {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
t[key] = val
|
|
||||||
}
|
|
||||||
|
|
||||||
addDuration := func(key string, val time.Duration) {
|
|
||||||
if !includeEmpty && val == 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
t[key] = val
|
|
||||||
}
|
|
||||||
|
|
||||||
addStrSlice := func(key string, val []string) {
|
|
||||||
if !includeEmpty && len(val) == 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
t[key] = val
|
|
||||||
}
|
|
||||||
|
|
||||||
addString("CirconusAPIApp", c.TelemetryCirconusAPIApp)
|
|
||||||
addString("CirconusAPIToken", c.TelemetryCirconusAPIToken)
|
|
||||||
addString("CirconusAPIURL", c.TelemetryCirconusAPIURL)
|
|
||||||
addString("CirconusBrokerID", c.TelemetryCirconusBrokerID)
|
|
||||||
addString("CirconusBrokerSelectTag", c.TelemetryCirconusBrokerSelectTag)
|
|
||||||
addString("CirconusCheckDisplayName", c.TelemetryCirconusCheckDisplayName)
|
|
||||||
addString("CirconusCheckForceMetricActivation", c.TelemetryCirconusCheckForceMetricActivation)
|
|
||||||
addString("CirconusCheckID", c.TelemetryCirconusCheckID)
|
|
||||||
addString("CirconusCheckInstanceID", c.TelemetryCirconusCheckInstanceID)
|
|
||||||
addString("CirconusCheckSearchTag", c.TelemetryCirconusCheckSearchTag)
|
|
||||||
addString("CirconusCheckTags", c.TelemetryCirconusCheckTags)
|
|
||||||
addString("CirconusSubmissionInterval", c.TelemetryCirconusSubmissionInterval)
|
|
||||||
addString("CirconusSubmissionURL", c.TelemetryCirconusSubmissionURL)
|
|
||||||
addBool("DisableHostname", c.TelemetryDisableHostname)
|
|
||||||
addString("DogstatsdAddr", c.TelemetryDogstatsdAddr)
|
|
||||||
addStrSlice("DogstatsdTags", c.TelemetryDogstatsdTags)
|
|
||||||
addDuration("PrometheusRetentionTime", c.TelemetryPrometheusRetentionTime)
|
|
||||||
addBool("FilterDefault", c.TelemetryFilterDefault)
|
|
||||||
addStrSlice("AllowedPrefixes", c.TelemetryAllowedPrefixes)
|
|
||||||
addStrSlice("BlockedPrefixes", c.TelemetryBlockedPrefixes)
|
|
||||||
addString("MetricsPrefix", c.TelemetryMetricsPrefix)
|
|
||||||
addString("StatsdAddr", c.TelemetryStatsdAddr)
|
|
||||||
addString("StatsiteAddr", c.TelemetryStatsiteAddr)
|
|
||||||
return t
|
|
||||||
}
|
|
||||||
|
|
||||||
// IncomingHTTPSConfig returns the TLS configuration for HTTPS
|
// IncomingHTTPSConfig returns the TLS configuration for HTTPS
|
||||||
// connections to consul.
|
// connections to consul.
|
||||||
func (c *RuntimeConfig) IncomingHTTPSConfig() (*tls.Config, error) {
|
func (c *RuntimeConfig) IncomingHTTPSConfig() (*tls.Config, error) {
|
||||||
|
|
|
@ -23,7 +23,6 @@ import (
|
||||||
"github.com/hashicorp/consul/types"
|
"github.com/hashicorp/consul/types"
|
||||||
"github.com/pascaldekloe/goe/verify"
|
"github.com/pascaldekloe/goe/verify"
|
||||||
"github.com/sergi/go-diff/diffmatchpatch"
|
"github.com/sergi/go-diff/diffmatchpatch"
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type configTest struct {
|
type configTest struct {
|
||||||
|
@ -4533,75 +4532,3 @@ func metaPairs(n int, format string) string {
|
||||||
panic("invalid format: " + format)
|
panic("invalid format: " + format)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTelemetryConfig(t *testing.T) {
|
|
||||||
|
|
||||||
tests := []struct {
|
|
||||||
name string
|
|
||||||
cfg RuntimeConfig
|
|
||||||
includeEmpty bool
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
name: "sanity check specific fields",
|
|
||||||
cfg: RuntimeConfig{
|
|
||||||
TelemetryAllowedPrefixes: []string{"foo", "bar"},
|
|
||||||
TelemetryStatsiteAddr: "localhost:1234",
|
|
||||||
TelemetryDisableHostname: true,
|
|
||||||
},
|
|
||||||
includeEmpty: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "verify all telemetry fields present",
|
|
||||||
cfg: RuntimeConfig{},
|
|
||||||
includeEmpty: true,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, tt := range tests {
|
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
|
||||||
// Build expected response with reflection
|
|
||||||
cfgValue := reflect.ValueOf(tt.cfg)
|
|
||||||
structType := cfgValue.Type()
|
|
||||||
nFields := cfgValue.NumField()
|
|
||||||
|
|
||||||
expect := make(map[string]interface{})
|
|
||||||
|
|
||||||
for i := 0; i < nFields; i++ {
|
|
||||||
name := structType.Field(i).Name
|
|
||||||
if strings.HasPrefix(name, "Telemetry") {
|
|
||||||
val := cfgValue.Field(i)
|
|
||||||
if !tt.includeEmpty {
|
|
||||||
// No built in way to check for zero-values for all types so only
|
|
||||||
// implementing this for the types we actually have for now. The test
|
|
||||||
// failure will hopefully catch the case where we add new types later.
|
|
||||||
switch val.Kind() {
|
|
||||||
case reflect.Slice:
|
|
||||||
if val.IsNil() {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
case reflect.Int, reflect.Int64: // time.Duration == int64
|
|
||||||
if val.Int() == 0 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
case reflect.String:
|
|
||||||
if val.String() == "" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
case reflect.Bool:
|
|
||||||
if val.Bool() == false {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
t.Fatalf("New type added to Telemetry* fields in RuntimeConfig." +
|
|
||||||
"Update this test.")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// non-zero values should be exported.
|
|
||||||
expect[strings.TrimPrefix(name, "Telemetry")] = val.Interface()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
require.Equal(t, expect, tt.cfg.TelemetryConfig(tt.includeEmpty))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue