mirror of https://github.com/hashicorp/consul
Retry on bad dogstatsd connection (#13091)
- Introduce a new telemetry configurable parameter retry_failed_connection. User can set the value to true to let consul agent continue its start process on failed connection to datadog server. When set to false, agent will stop on failed start. The default behavior is true. Co-authored-by: Dan Upton <daniel@floppy.co> Co-authored-by: Evan Culver <eculver@users.noreply.github.com>pull/13157/head
parent
c9602bf23e
commit
364d4f5efe
@ -0,0 +1,5 @@
|
||||
```release-note:improvement
|
||||
config: introduce `telemetry.retry_failed_connection` in agent configuration to
|
||||
retry on failed connection to any telemetry backend. This prevents the agent from
|
||||
exiting if the given DogStatsD DNS name is unresolvable, for example.
|
||||
```
|
@ -0,0 +1,66 @@
|
||||
package lib
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/consul/logging"
|
||||
"github.com/hashicorp/go-multierror"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func newCfg() TelemetryConfig {
|
||||
return TelemetryConfig{
|
||||
StatsdAddr: "statsd.host:1234",
|
||||
StatsiteAddr: "statsite.host:1234",
|
||||
DogstatsdAddr: "mydog.host:8125",
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigureSinks(t *testing.T) {
|
||||
cfg := newCfg()
|
||||
sinks, err := configureSinks(cfg, "hostname", nil)
|
||||
require.Error(t, err)
|
||||
// 3 sinks: statsd, statsite, inmem
|
||||
require.Equal(t, 3, len(sinks))
|
||||
|
||||
cfg = TelemetryConfig{
|
||||
DogstatsdAddr: "",
|
||||
}
|
||||
_, err = configureSinks(cfg, "hostname", nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
}
|
||||
|
||||
func TestIsRetriableError(t *testing.T) {
|
||||
var err error
|
||||
err = multierror.Append(err, errors.New("an error"))
|
||||
r := isRetriableError(err)
|
||||
require.False(t, r)
|
||||
|
||||
err = multierror.Append(err, &net.DNSError{
|
||||
IsNotFound: true,
|
||||
})
|
||||
r = isRetriableError(err)
|
||||
require.True(t, r)
|
||||
}
|
||||
|
||||
func TestInitTelemetryRetrySuccess(t *testing.T) {
|
||||
logger, err := logging.Setup(logging.Config{
|
||||
LogLevel: "INFO",
|
||||
}, os.Stdout)
|
||||
require.NoError(t, err)
|
||||
cfg := newCfg()
|
||||
_, err = InitTelemetry(cfg, logger)
|
||||
require.Error(t, err)
|
||||
|
||||
cfg.RetryFailedConfiguration = true
|
||||
metricsCfg, err := InitTelemetry(cfg, logger)
|
||||
require.NoError(t, err)
|
||||
// TODO: we couldn't extract the metrics sinks from the
|
||||
// global metrics due to it's limitation
|
||||
// fanoutSink := metrics.Default()}
|
||||
metricsCfg.cancelFn()
|
||||
}
|
Loading…
Reference in new issue