Skip to content

Commit

Permalink
feat(analysis): Returns the resolved query as metadata in the New Rel…
Browse files Browse the repository at this point in the history
…ic provider (#3715)

* Adds newrelic resolved query to metadata

Signed-off-by: Orlando Valdez <[email protected]>

* Fix comment

Signed-off-by: Orlando Valdez <[email protected]>

* Updates tests

Signed-off-by: Orlando Valdez <[email protected]>

* Update docs

Signed-off-by: Orlando Valdez <[email protected]>

---------

Signed-off-by: Orlando Valdez <[email protected]>
  • Loading branch information
orlando-valdez-ck authored Jul 11, 2024
1 parent 3d29653 commit d89abb2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
8 changes: 8 additions & 0 deletions docs/analysis/newrelic.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,11 @@ stringData:
base-url-rest: <your-base-url>
base-url-nerdgraph: <your-base-url>
```

## Additional Metadata

The New Relic provider returns the below metadata under the `Metadata` map in the `MetricsResult` object of `AnalysisRun`.

| KEY | Description |
|-----------------------|-------------|
| ResolvedNewRelicQuery | Resolved query after substituting the template's arguments |
9 changes: 7 additions & 2 deletions metricproviders/newrelic/newrelic.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ import (
)

const (
//ProviderType indicates the provider is wavefront
// ProviderType indicates the provider is newrelic
ProviderType = "NewRelic"
DefaultNewRelicProfileSecretName = "newrelic"
repoURL = "https://github.com/argoproj/argo-rollouts"
resolvedNewRelicQuery = "ResolvedNewRelicQuery"
)

var userAgent = fmt.Sprintf("argo-rollouts/%s (%s)", version.GetVersion(), repoURL)
Expand Down Expand Up @@ -133,7 +134,11 @@ func (p *Provider) Type() string {

// GetMetadata returns any additional metadata which needs to be stored & displayed as part of the metrics result.
func (p *Provider) GetMetadata(metric v1alpha1.Metric) map[string]string {
return nil
metricsMetadata := make(map[string]string)
if metric.Provider.NewRelic.Query != "" {
metricsMetadata[resolvedNewRelicQuery] = metric.Provider.NewRelic.Query
}
return metricsMetadata
}

// NewNewRelicProvider creates a new NewRelic provider
Expand Down
23 changes: 14 additions & 9 deletions metricproviders/newrelic/newrelic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@ func TestRunSuccessfully(t *testing.T) {
FailureCondition: "result.count != 10",
Provider: v1alpha1.MetricProvider{
NewRelic: &v1alpha1.NewRelicMetric{
Query: "test",
Query: "resolved-query",
},
},
}
metricsMetadata := p.GetMetadata(metric)
assert.Nil(t, metricsMetadata)
assert.NotNil(t, metricsMetadata)
assert.Equal(t, "resolved-query", metricsMetadata[resolvedNewRelicQuery])

measurement := p.Run(newAnalysisRun(), metric)
assert.NotNil(t, measurement.StartedAt)
Expand All @@ -60,7 +61,8 @@ func TestRunWithTimeseries(t *testing.T) {
response: []nrdb.NRDBResult{
map[string]any{"count": 10},
map[string]any{"count": 20},
map[string]any{"count": 30}},
map[string]any{"count": 30},
},
}
p := NewNewRelicProvider(mock, *e)
metric := v1alpha1.Metric{
Expand All @@ -69,12 +71,13 @@ func TestRunWithTimeseries(t *testing.T) {
FailureCondition: "result[2].count < 20",
Provider: v1alpha1.MetricProvider{
NewRelic: &v1alpha1.NewRelicMetric{
Query: "test",
Query: "resolved-query",
},
},
}
metricsMetadata := p.GetMetadata(metric)
assert.Nil(t, metricsMetadata)
assert.NotNil(t, metricsMetadata)
assert.Equal(t, "resolved-query", metricsMetadata[resolvedNewRelicQuery])

measurement := p.Run(newAnalysisRun(), metric)
assert.NotNil(t, measurement.StartedAt)
Expand All @@ -95,12 +98,13 @@ func TestRunWithFacet(t *testing.T) {
FailureCondition: "result.count != 10 or result['average.duration'] >= 15.0",
Provider: v1alpha1.MetricProvider{
NewRelic: &v1alpha1.NewRelicMetric{
Query: "test",
Query: "resolved-query",
},
},
}
metricsMetadata := p.GetMetadata(metric)
assert.Nil(t, metricsMetadata)
assert.NotNil(t, metricsMetadata)
assert.Equal(t, "resolved-query", metricsMetadata[resolvedNewRelicQuery])

measurement := p.Run(newAnalysisRun(), metric)
assert.NotNil(t, measurement.StartedAt)
Expand All @@ -121,12 +125,13 @@ func TestRunWithMultipleSelectTerms(t *testing.T) {
FailureCondition: "result.count != 10",
Provider: v1alpha1.MetricProvider{
NewRelic: &v1alpha1.NewRelicMetric{
Query: "test",
Query: "resolved-query",
},
},
}
metricsMetadata := p.GetMetadata(metric)
assert.Nil(t, metricsMetadata)
assert.NotNil(t, metricsMetadata)
assert.Equal(t, "resolved-query", metricsMetadata[resolvedNewRelicQuery])

measurement := p.Run(newAnalysisRun(), metric)
assert.NotNil(t, measurement.StartedAt)
Expand Down

0 comments on commit d89abb2

Please sign in to comment.