diff --git a/docs/analysis/newrelic.md b/docs/analysis/newrelic.md index 81afad9b75..589e6d14f6 100644 --- a/docs/analysis/newrelic.md +++ b/docs/analysis/newrelic.md @@ -54,3 +54,11 @@ stringData: base-url-rest: base-url-nerdgraph: ``` + +## 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 | diff --git a/metricproviders/newrelic/newrelic.go b/metricproviders/newrelic/newrelic.go index 0c971e5c60..e70db7c765 100644 --- a/metricproviders/newrelic/newrelic.go +++ b/metricproviders/newrelic/newrelic.go @@ -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) @@ -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 diff --git a/metricproviders/newrelic/newrelic_test.go b/metricproviders/newrelic/newrelic_test.go index 8f49049815..cf4b421111 100644 --- a/metricproviders/newrelic/newrelic_test.go +++ b/metricproviders/newrelic/newrelic_test.go @@ -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) @@ -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{ @@ -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) @@ -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) @@ -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)