Skip to content

Commit

Permalink
add docs, correctly handle REST and nergraph base URLs
Browse files Browse the repository at this point in the history
Signed-off-by: Fischer Jemison <[email protected]>
  • Loading branch information
jemisonf committed Apr 1, 2021
1 parent c9f9296 commit 347816f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 12 deletions.
16 changes: 16 additions & 0 deletions docs/analysis/newrelic.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,19 @@ data:
account-id: <newrelic-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: <newrelic-personal-api-key>
account-id: <newrelic-account-id>
region: "us" # optional, defaults to "us" if not set. Only set to "eu" if you use EU New Relic
base-url-rest: <your-base-url>
base-url-nerdgraph: <your-base-url>
```
23 changes: 14 additions & 9 deletions metricproviders/newrelic/newrelic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
Expand Down
7 changes: 4 additions & 3 deletions metricproviders/newrelic/newrelic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 347816f

Please sign in to comment.