Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(analysis): Returns the resolved query as metadata in the New Relic provider #3715

Merged
merged 5 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading