diff --git a/lib/stringutil/strings.go b/lib/stringutil/strings.go index 059ab7e3d..4329e9be7 100644 --- a/lib/stringutil/strings.go +++ b/lib/stringutil/strings.go @@ -21,3 +21,13 @@ func Wrap(colVal interface{}) string { // The normal string escape is to do for O'Reilly is O\\'Reilly, but Snowflake escapes via \' return fmt.Sprintf("'%s'", strings.ReplaceAll(fmt.Sprint(colVal), "'", `\'`)) } + +func Empty(vals ...string) bool { + for _, val := range vals { + if val == "" { + return true + } + } + + return false +} diff --git a/lib/stringutil/strings_test.go b/lib/stringutil/strings_test.go index e09904681..d57ac0129 100644 --- a/lib/stringutil/strings_test.go +++ b/lib/stringutil/strings_test.go @@ -18,3 +18,11 @@ func TestReverseComplex(t *testing.T) { assert.Equal(t, Reverse(val), Reverse(Reverse(Reverse(val)))) assert.Equal(t, val, Reverse(Reverse(val))) } + +func TestEmpty(t *testing.T) { + assert.False(t, Empty("hi", "there", "artie", "transfer")) + assert.False(t, Empty("dusty")) + + assert.True(t, Empty("robin", "jacqueline", "charlie", "")) + assert.True(t, Empty("")) +} diff --git a/lib/telemetry/metrics/datadog.go b/lib/telemetry/metrics/datadog.go index c645b9d16..8312df1ee 100644 --- a/lib/telemetry/metrics/datadog.go +++ b/lib/telemetry/metrics/datadog.go @@ -3,13 +3,16 @@ package metrics import ( "context" "fmt" + "os" "strconv" "time" "github.com/DataDog/datadog-go/statsd" "gopkg.in/yaml.v3" + "github.com/artie-labs/transfer/lib/logger" "github.com/artie-labs/transfer/lib/maputil" + "github.com/artie-labs/transfer/lib/stringutil" ) const ( @@ -69,7 +72,15 @@ func getTags(tags interface{}) []string { } func NewDatadogClient(ctx context.Context, settings map[string]interface{}) (context.Context, error) { - datadogClient, err := statsd.New(fmt.Sprint(maputil.GetKeyFromMap(settings, DatadogAddr, DefaultAddr))) + address := fmt.Sprint(maputil.GetKeyFromMap(settings, DatadogAddr, DefaultAddr)) + host := os.Getenv("TELEMETRY_HOST") + port := os.Getenv("TELEMETRY_PORT") + if !stringutil.Empty(host, port) { + address = fmt.Sprintf("%s:%s", host, port) + logger.FromContext(ctx).WithField("address", address).Info("overriding telemetry address with env vars") + } + + datadogClient, err := statsd.New(address) if err != nil { return ctx, err }