From cc82c7ccf9b055d13aec5132dd81e7bf03c62c06 Mon Sep 17 00:00:00 2001 From: Harkamal Singh <41585091+hsinghkalsi@users.noreply.github.com> Date: Tue, 15 Jun 2021 17:15:31 -0400 Subject: [PATCH] Added support to override metric_url in newrelic output plugin (#9342) --- plugins/outputs/newrelic/README.md | 4 ++++ plugins/outputs/newrelic/newrelic.go | 8 ++++++++ plugins/outputs/newrelic/newrelic_test.go | 8 ++++++++ 3 files changed, 20 insertions(+) diff --git a/plugins/outputs/newrelic/README.md b/plugins/outputs/newrelic/README.md index 462c0c315..e15bedb4b 100644 --- a/plugins/outputs/newrelic/README.md +++ b/plugins/outputs/newrelic/README.md @@ -21,6 +21,10 @@ Telegraf minimum version: Telegraf 1.15.0 ## HTTP Proxy override. If unset use values from the standard ## proxy environment variables to determine proxy, if any. # http_proxy = "http://corporate.proxy:3128" + + ## Metric URL override to enable geographic location endpoints. + # If not set use values from the standard + # metric_url = "https://metric-api.newrelic.com/metric/v1" ``` [Metrics API]: https://docs.newrelic.com/docs/data-ingest-apis/get-data-new-relic/metric-api/introduction-metric-api diff --git a/plugins/outputs/newrelic/newrelic.go b/plugins/outputs/newrelic/newrelic.go index 4f67c5de0..02b2b9c3f 100644 --- a/plugins/outputs/newrelic/newrelic.go +++ b/plugins/outputs/newrelic/newrelic.go @@ -21,6 +21,7 @@ type NewRelic struct { MetricPrefix string `toml:"metric_prefix"` Timeout config.Duration `toml:"timeout"` HTTPProxy string `toml:"http_proxy"` + MetricURL string `toml:"metric_url"` harvestor *telemetry.Harvester dc *cumulative.DeltaCalculator @@ -49,6 +50,10 @@ func (nr *NewRelic) SampleConfig() string { ## HTTP Proxy override. If unset use values from the standard ## proxy environment variables to determine proxy, if any. # http_proxy = "http://corporate.proxy:3128" + + ## Metric URL override to enable geographic location endpoints. + # If not set use values from the standard + # metric_url = "https://metric-api.newrelic.com/metric/v1" ` } @@ -77,6 +82,9 @@ func (nr *NewRelic) Connect() error { nr.errorCount++ nr.savedErrors[nr.errorCount] = errorString } + if nr.MetricURL != "" { + cfg.MetricsURLOverride = nr.MetricURL + } }) if err != nil { return fmt.Errorf("unable to connect to newrelic %v", err) diff --git a/plugins/outputs/newrelic/newrelic_test.go b/plugins/outputs/newrelic/newrelic_test.go index 7071176fc..e545a1ac9 100644 --- a/plugins/outputs/newrelic/newrelic_test.go +++ b/plugins/outputs/newrelic/newrelic_test.go @@ -173,6 +173,14 @@ func TestNewRelic_Connect(t *testing.T) { }, wantErr: false, }, + { + name: "Test: Metric URL ", + newrelic: &NewRelic{ + InsightsKey: "12121212", + MetricURL: "https://test.nr.com", + }, + wantErr: false, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {