Added support to override metric_url in newrelic output plugin (#9342)

This commit is contained in:
Harkamal Singh 2021-06-15 17:15:31 -04:00 committed by GitHub
parent 769f582245
commit cc82c7ccf9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 0 deletions

View File

@ -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

View File

@ -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)

View File

@ -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) {