From e79fd17bab81dc8956d6641895cf1a789b32a349 Mon Sep 17 00:00:00 2001 From: Fischer Jemison Date: Thu, 1 Apr 2021 13:18:01 -0700 Subject: [PATCH] add docs, correctly handle REST and nergraph base URLs --- docs/analysis/newrelic.md | 16 ++++++++++++++++ metricproviders/newrelic/newrelic.go | 23 ++++++++++++++--------- metricproviders/newrelic/newrelic_test.go | 7 ++++--- 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/docs/analysis/newrelic.md b/docs/analysis/newrelic.md index 31e6ec90f1..de1153505d 100644 --- a/docs/analysis/newrelic.md +++ b/docs/analysis/newrelic.md @@ -38,3 +38,19 @@ data: account-id: region: "us" # optional, defaults to "us" if not set. Only set to "eu" if you use EU New Relic ``` + +To use the New Relic metric provider from behind a proxy, provide a `base-url-rest` key pointing to the base URL of the New Relic REST API for your proxy, and a `base-url-nerdgraph` key pointing to the base URL for NerdGraph for your proxy: + +```yaml +apiVersion: v1 +kind: Secret +metadata: + name: newrelic +type: Opaque +data: + personal-api-key: + account-id: + region: "us" # optional, defaults to "us" if not set. Only set to "eu" if you use EU New Relic + base-url-rest: + base-url-nerdgraph: +``` diff --git a/metricproviders/newrelic/newrelic.go b/metricproviders/newrelic/newrelic.go index c6b56a4d08..8b52ed66ec 100644 --- a/metricproviders/newrelic/newrelic.go +++ b/metricproviders/newrelic/newrelic.go @@ -155,15 +155,20 @@ func NewNewRelicAPIClient(metric v1alpha1.Metric, kubeclientset kubernetes.Inter newrelicOptions := []newrelic.ConfigOption{newrelic.ConfigPersonalAPIKey(apiKey), newrelic.ConfigUserAgent(userAgent)} - // support either base-url or region; default to us region if neither is used - if _, ok := secret.Data["base-url"]; ok { - newrelicOptions = append(newrelicOptions, newrelic.ConfigBaseURL(string(secret.Data["base-url"]))) - } else { - region := "us" - if _, ok := secret.Data["region"]; ok { - region = string(secret.Data["region"]) - } - newrelicOptions = append(newrelicOptions, newrelic.ConfigRegion(region)) + region := "us" + if _, ok := secret.Data["region"]; ok { + region = string(secret.Data["region"]) + } + newrelicOptions = append(newrelicOptions, newrelic.ConfigRegion(region)) + + // base URL for the new relic REST API + if _, ok := secret.Data["base-url-rest"]; ok { + newrelicOptions = append(newrelicOptions, newrelic.ConfigBaseURL(string(secret.Data["base-url-rest"]))) + } + + // base URL for the nerdgraph (graphQL) API + if _, ok := secret.Data["base-url-nerdgraph"]; ok { + newrelicOptions = append(newrelicOptions, newrelic.ConfigNerdGraphBaseURL(string(secret.Data["base-url-nerdgraph"]))) } if apiKey != "" && accountID != "" { diff --git a/metricproviders/newrelic/newrelic_test.go b/metricproviders/newrelic/newrelic_test.go index 4870e04647..54353ab288 100644 --- a/metricproviders/newrelic/newrelic_test.go +++ b/metricproviders/newrelic/newrelic_test.go @@ -348,9 +348,10 @@ func TestNewNewRelicAPIClient(t *testing.T) { t.Run("when a base-url is set", func(t *testing.T) { tokenSecret.Data = map[string][]byte{ - "personal-api-key": []byte("ABCDEFG01234"), - "account-id": []byte("12345"), - "base-url": []byte("example.com"), + "personal-api-key": []byte("ABCDEFG01234"), + "account-id": []byte("12345"), + "base-url-rest": []byte("example.com/api/v2"), + "base-url-nerdgraph": []byte("example.com/query"), } _, err := NewNewRelicAPIClient(metric, fakeClient)