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(alerts): add support for titleTemplate to NRQL alert conditions #1141

Merged
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
7 changes: 6 additions & 1 deletion pkg/alerts/nrql_conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,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.
Expand All @@ -261,6 +262,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.
Expand All @@ -276,6 +278,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.
Expand Down Expand Up @@ -325,6 +328,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
Expand Down Expand Up @@ -719,6 +723,7 @@ const (
enabled
entityGuid
description
titleTemplate
policyId
runbookUrl
terms {
Expand All @@ -737,7 +742,7 @@ const (
openViolationOnExpiration
}
signal {
aggregationWindow
aggregationWindow
evaluationOffset
evaluationDelay
fillOption
Expand Down
28 changes: 19 additions & 9 deletions pkg/alerts/nrql_conditions_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Loading