From 137d7c67078efc2886a8bf0baf4d7a6020c44504 Mon Sep 17 00:00:00 2001 From: baNROne <93732247+baNROne@users.noreply.github.com> Date: Tue, 14 May 2024 17:54:11 -0700 Subject: [PATCH 1/3] feat: Add support for title template fix: Remove omitempty refactor(alerts): Change field name --- pkg/alerts/nrql_conditions.go | 5 ++++ .../nrql_conditions_integration_test.go | 28 +++++++++++++------ 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/pkg/alerts/nrql_conditions.go b/pkg/alerts/nrql_conditions.go index 390b26107..795b3292e 100644 --- a/pkg/alerts/nrql_conditions.go +++ b/pkg/alerts/nrql_conditions.go @@ -243,6 +243,7 @@ type NrqlConditionBase struct { Expiration *AlertsNrqlConditionExpiration `json:"expiration,omitempty"` Signal *AlertsNrqlConditionSignal `json:"signal,omitempty"` EntityGUID common.EntityGUID `json:"entityGuid,omitempty"` + TitleTemplate *string `json:"titleTemplate,omitempty"` } // NrqlConditionCreateBase represents the base fields for creating a New Relic NRQL Alert condition. @@ -258,6 +259,7 @@ type NrqlConditionCreateBase struct { ViolationTimeLimitSeconds int `json:"violationTimeLimitSeconds,omitempty"` Expiration *AlertsNrqlConditionExpiration `json:"expiration,omitempty"` Signal *AlertsNrqlConditionCreateSignal `json:"signal,omitempty"` + TitleTemplate *string `json:"titleTemplate,omitempty"` } // NrqlConditionUpdateBase represents the base fields for updating a New Relic NRQL Alert condition. @@ -273,6 +275,7 @@ type NrqlConditionUpdateBase struct { ViolationTimeLimitSeconds int `json:"violationTimeLimitSeconds,omitempty"` Expiration *AlertsNrqlConditionExpiration `json:"expiration,omitempty"` Signal *AlertsNrqlConditionUpdateSignal `json:"signal"` + TitleTemplate *string `json:"titleTemplate"` } // NrqlConditionCreateInput represents the input options for creating a Nrql Condition. @@ -322,6 +325,7 @@ type NrqlCondition struct { Terms []ConditionTerm `json:"terms,omitempty"` Type string `json:"type,omitempty"` EntityGUID *common.EntityGUID `json:"entity_guid,omitempty"` + TitleTemplate *string `json:"titleTemplate,omitempty"` } // NrqlQuery represents a NRQL query to use with a NRQL alert condition @@ -715,6 +719,7 @@ const ( enabled entityGuid description + titleTemplate policyId runbookUrl terms { diff --git a/pkg/alerts/nrql_conditions_integration_test.go b/pkg/alerts/nrql_conditions_integration_test.go index 0ec623d30..87b478dd3 100644 --- a/pkg/alerts/nrql_conditions_integration_test.go +++ b/pkg/alerts/nrql_conditions_integration_test.go @@ -27,6 +27,7 @@ var ( nrqlConditionBaseAggTimer = 5 // needed for setting pointer nrqlConditionBaseSlideBy = 30 // needed for setting pointer nrqlConditionEvaluationDelay = 60 // needed for setting pointer + nrqlConditionTitleTemplate = "Title {{ createdAt }}" // needed for setting pointer nrqlConditionCreateBase = NrqlConditionCreateBase{ Description: "test description", Enabled: true, @@ -35,7 +36,8 @@ var ( Query: "SELECT rate(sum(apm.service.cpu.usertime.utilization), 1 second) * 100 as cpuUsage FROM Metric WHERE appName like 'Dummy App'", EvaluationOffset: &nrqlConditionBaseEvalOffset, }, - RunbookURL: "test.com", + RunbookURL: "test.com", + TitleTemplate: &nrqlConditionTitleTemplate, Terms: []NrqlConditionTerm{ { Threshold: &nrqlConditionBaseThreshold, @@ -68,7 +70,8 @@ var ( Query: "SELECT rate(sum(apm.service.cpu.usertime.utilization), 1 second) * 100 as cpuUsage FROM Metric WHERE appName like 'Dummy App'", EvaluationOffset: &nrqlConditionBaseEvalOffset, }, - RunbookURL: "test.com", + RunbookURL: "test.com", + TitleTemplate: &nrqlConditionTitleTemplate, Terms: []NrqlConditionTerm{ { Threshold: &nrqlConditionBaseThreshold, @@ -100,7 +103,8 @@ var ( Nrql: NrqlConditionCreateQuery{ Query: "SELECT rate(sum(apm.service.cpu.usertime.utilization), 1 second) * 100 as cpuUsage FROM Metric WHERE appName like 'Dummy App'", }, - RunbookURL: "test.com", + RunbookURL: "test.com", + TitleTemplate: &nrqlConditionTitleTemplate, Terms: []NrqlConditionTerm{ { Threshold: &nrqlConditionBaseThreshold, @@ -133,7 +137,8 @@ var ( Nrql: NrqlConditionUpdateQuery{ Query: "SELECT rate(sum(apm.service.cpu.usertime.utilization), 1 second) * 100 as cpuUsage FROM Metric WHERE appName like 'Dummy App'", }, - RunbookURL: "test.com", + RunbookURL: "test.com", + TitleTemplate: &nrqlConditionTitleTemplate, Terms: []NrqlConditionTerm{ { Threshold: &nrqlConditionBaseThreshold, @@ -166,7 +171,8 @@ var ( Nrql: NrqlConditionCreateQuery{ Query: "SELECT rate(sum(apm.service.cpu.usertime.utilization), 1 second) * 100 as cpuUsage FROM Metric WHERE appName like 'Dummy App' FACET OtherStuff", }, - RunbookURL: "test.com", + RunbookURL: "test.com", + TitleTemplate: &nrqlConditionTitleTemplate, Terms: []NrqlConditionTerm{ { Threshold: &nrqlConditionBaseThreshold, @@ -200,7 +206,8 @@ var ( Nrql: NrqlConditionUpdateQuery{ Query: "SELECT rate(sum(apm.service.cpu.usertime.utilization), 1 second) * 100 as cpuUsage FROM Metric WHERE appName like 'Dummy App'", }, - RunbookURL: "test.com", + RunbookURL: "test.com", + TitleTemplate: &nrqlConditionTitleTemplate, Terms: []NrqlConditionTerm{ { Threshold: &nrqlConditionBaseThreshold, @@ -455,7 +462,8 @@ func TestIntegrationNrqlConditions_Search(t *testing.T) { Query: "SELECT rate(sum(apm.service.cpu.usertime.utilization), 1 second) * 100 as cpuUsage FROM Metric WHERE appName like 'Dummy App'", EvaluationOffset: &nrqlConditionBaseEvalOffset, }, - RunbookURL: "test.com", + RunbookURL: "test.com", + TitleTemplate: &nrqlConditionTitleTemplate, Terms: []NrqlConditionTerm{ { Threshold: &thresholdCritical, @@ -522,7 +530,8 @@ func TestIntegrationNrqlConditions_CreateStatic(t *testing.T) { Query: "SELECT rate(sum(apm.service.cpu.usertime.utilization), 1 second) * 100 as cpuUsage FROM Metric WHERE appName like 'Dummy App'", EvaluationOffset: &nrqlConditionBaseEvalOffset, }, - RunbookURL: "test.com", + RunbookURL: "test.com", + TitleTemplate: &nrqlConditionTitleTemplate, Terms: []NrqlConditionTerm{ { Threshold: &nrqlConditionBaseThreshold, @@ -587,7 +596,8 @@ func TestIntegrationNrqlConditions_ZeroValueThreshold(t *testing.T) { Query: "SELECT rate(sum(apm.service.cpu.usertime.utilization), 1 second) * 100 as cpuUsage FROM Metric WHERE appName like 'Dummy App'", EvaluationOffset: &nrqlConditionBaseEvalOffset, }, - RunbookURL: "test.com", + RunbookURL: "test.com", + TitleTemplate: &nrqlConditionTitleTemplate, Terms: []NrqlConditionTerm{ { Threshold: &nrqlConditionBaseThresholdZeroValue, From df71d2d5c8e69fa36d3703182ba501da52827517 Mon Sep 17 00:00:00 2001 From: baNROne <93732247+baNROne@users.noreply.github.com> Date: Tue, 14 May 2024 18:03:58 -0700 Subject: [PATCH 2/3] chore: Adjust formatting --- pkg/alerts/nrql_conditions.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/alerts/nrql_conditions.go b/pkg/alerts/nrql_conditions.go index 795b3292e..5d4154f69 100644 --- a/pkg/alerts/nrql_conditions.go +++ b/pkg/alerts/nrql_conditions.go @@ -738,9 +738,9 @@ const ( openViolationOnExpiration } signal { - aggregationWindow + aggregationWindow evaluationOffset - evaluationDelay + evaluationDelay fillOption fillValue aggregationMethod From 2dd8235f4780f54be413532d3a05df4fc4fcf001 Mon Sep 17 00:00:00 2001 From: baNROne <93732247+baNROne@users.noreply.github.com> Date: Wed, 7 Aug 2024 12:25:16 -0700 Subject: [PATCH 3/3] chore(alerts): Adjust whitespace --- pkg/alerts/nrql_conditions.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/alerts/nrql_conditions.go b/pkg/alerts/nrql_conditions.go index d58546c9d..9fe78497d 100644 --- a/pkg/alerts/nrql_conditions.go +++ b/pkg/alerts/nrql_conditions.go @@ -742,7 +742,7 @@ const ( openViolationOnExpiration } signal { - aggregationWindow + aggregationWindow evaluationOffset evaluationDelay fillOption