Skip to content

Commit

Permalink
feat(alertCondition): support for lost signal
Browse files Browse the repository at this point in the history
  • Loading branch information
paologallinaharbur committed Jun 29, 2021
1 parent 20873a4 commit cd1d592
Show file tree
Hide file tree
Showing 13 changed files with 239 additions and 134 deletions.
35 changes: 34 additions & 1 deletion api/v1/alerts_nrqlcondition_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,29 @@ type AlertsNrqlSpecificSpec struct {
ExpectedGroups int `json:"expected_groups,omitempty"`
IgnoreOverlap bool `json:"ignore_overlap,omitempty"`
ViolationTimeLimit alerts.NrqlConditionViolationTimeLimit `json:"violationTimeLimit,omitempty"`
Expiration AlertsNrqlConditionExpiration `json:"expiration,omitempty"`
Signal AlertsNrqlConditionSignal `json:"signal,omitempty"`
}

// AlertsNrqlConditionSignal - Configuration that defines the signal that the NRQL condition will use to evaluate.
type AlertsNrqlConditionSignal struct {
AggregationWindow *int `json:"aggregation_window,omitempty"`
EvaluationOffset *int `json:"evaluation_offset,omitempty"`
FillOption *alerts.AlertsFillOption `json:"fill_option,omitempty"`
FillValue string `json:"fill_value,omitempty"`
}

// AlertsNrqlConditionExpiration
// Settings for how violations are opened or closed when a signal expires.
type AlertsNrqlConditionExpiration struct {
ExpirationDuration *int `json:"expirationDuration,omitempty"`
CloseViolationsOnExpiration bool `json:"closeViolationsOnExpiration,omitempty"`
OpenViolationOnExpiration bool `json:"openViolationOnExpiration,omitempty"`
}

// AlertsNrqlConditionTerm represents the terms of a New Relic alert condition.
type AlertsNrqlConditionTerm struct {
Operator alerts.AlertsNrqlConditionTermsOperator `json:"operator,omitempty"`
Operator alerts.AlertsNRQLConditionTermsOperator `json:"operator,omitempty"`
Priority alerts.NrqlConditionPriority `json:"priority,omitempty"`
Threshold string `json:"threshold,omitempty"`
ThresholdDuration int `json:"threshold_duration,omitempty"`
Expand Down Expand Up @@ -88,6 +106,21 @@ func (in AlertsNrqlConditionSpec) ToNrqlConditionInput() alerts.NrqlConditionInp
conditionInput.RunbookURL = in.RunbookURL
conditionInput.ViolationTimeLimit = in.ViolationTimeLimit

conditionInput.Expiration = &alerts.AlertsNrqlConditionExpiration{}
conditionInput.Expiration.ExpirationDuration = in.Expiration.ExpirationDuration
conditionInput.Expiration.CloseViolationsOnExpiration = in.Expiration.CloseViolationsOnExpiration
conditionInput.Expiration.OpenViolationOnExpiration = in.Expiration.OpenViolationOnExpiration

conditionInput.Signal = &alerts.AlertsNrqlConditionSignal{}
conditionInput.Signal.FillOption = in.Signal.FillOption
conditionInput.Signal.AggregationWindow = in.Signal.AggregationWindow
conditionInput.Signal.EvaluationOffset = in.Signal.EvaluationOffset
f, err := strconv.ParseFloat(in.Signal.FillValue, 10)
if err != nil {
log.Error(err, "strconv.ParseFloat()", "signal.FillValue", in.Signal.FillValue)
}
conditionInput.Signal.FillValue = &f

if in.ValueFunction != nil {
// f := alerts.NrqlConditionValueFunction(in.ValueFunction)
conditionInput.ValueFunction = in.ValueFunction
Expand Down
4 changes: 2 additions & 2 deletions api/v1/alerts_nrqlcondition_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var _ = Describe("AlertsNrqlConditionSpec", func() {
condition.ExistingPolicyID = "42"
condition.Terms = []AlertsNrqlConditionTerm{
{
Operator: alerts.AlertsNrqlConditionTermsOperatorTypes.ABOVE,
Operator: alerts.AlertsNRQLConditionTermsOperatorTypes.ABOVE,
Priority: alerts.NrqlConditionPriorities.Critical,
Threshold: "5",
ThresholdDuration: 60,
Expand Down Expand Up @@ -65,7 +65,7 @@ var _ = Describe("AlertsNrqlConditionSpec", func() {
Expect(fmt.Sprint(reflect.TypeOf(apiTerm))).To(Equal("alerts.NrqlConditionTerm"))

//Expect(apiTerm.Duration).To(Equal(30))
Expect(apiTerm.Operator).To(Equal(alerts.AlertsNrqlConditionTermsOperatorTypes.ABOVE))
Expect(apiTerm.Operator).To(Equal(alerts.AlertsNRQLConditionTermsOperatorTypes.ABOVE))
Expect(apiTerm.Priority).To(Equal(alerts.NrqlConditionPriorities.Critical))
expectedThreshold := 5.0
Expect(apiTerm.Threshold).To(Equal(&expectedThreshold))
Expand Down
2 changes: 1 addition & 1 deletion api/v1/alerts_nrqlcondition_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var _ = Describe("ValidateCreate", func() {
spec := AlertsNrqlConditionSpec{}
spec.Terms = []AlertsNrqlConditionTerm{
{
Operator: alerts.AlertsNrqlConditionTermsOperatorTypes.ABOVE,
Operator: alerts.AlertsNRQLConditionTermsOperatorTypes.ABOVE,
Priority: alerts.NrqlConditionPriorities.Critical,
Threshold: "5",
ThresholdDuration: 60,
Expand Down
4 changes: 2 additions & 2 deletions api/v1/alerts_policy_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var _ = Describe("Equals", func() {
spec := AlertsPolicyConditionSpec{}
spec.Terms = []AlertsNrqlConditionTerm{
{
Operator: alerts.AlertsNrqlConditionTermsOperatorTypes.ABOVE,
Operator: alerts.AlertsNRQLConditionTermsOperatorTypes.ABOVE,
Priority: alerts.NrqlConditionPriorities.Critical,
Threshold: "5",
ThresholdDuration: 60,
Expand Down Expand Up @@ -95,7 +95,7 @@ var _ = Describe("Equals", func() {

spec.Terms = []AlertsNrqlConditionTerm{
{
Operator: alerts.AlertsNrqlConditionTermsOperatorTypes.ABOVE,
Operator: alerts.AlertsNRQLConditionTermsOperatorTypes.ABOVE,
Priority: alerts.NrqlConditionPriorities.Critical,
Threshold: "5",
ThresholdDuration: 60,
Expand Down
6 changes: 3 additions & 3 deletions api/v1/alerts_policy_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ var _ = Describe("AlertsPolicy_webhooks", func() {
spec1 := AlertsPolicyConditionSpec{}
spec1.Terms = []AlertsNrqlConditionTerm{
{
Operator: alerts.AlertsNrqlConditionTermsOperatorTypes.ABOVE,
Operator: alerts.AlertsNRQLConditionTermsOperatorTypes.ABOVE,
Priority: alerts.NrqlConditionPriorities.Critical,
Threshold: "5",
ThresholdDuration: 60,
Expand All @@ -129,7 +129,7 @@ var _ = Describe("AlertsPolicy_webhooks", func() {
spec2 := AlertsPolicyConditionSpec{}
spec2.Terms = []AlertsNrqlConditionTerm{
{
Operator: alerts.AlertsNrqlConditionTermsOperatorTypes.ABOVE,
Operator: alerts.AlertsNRQLConditionTermsOperatorTypes.ABOVE,
Priority: alerts.NrqlConditionPriorities.Critical,
Threshold: "5",
ThresholdDuration: 60,
Expand Down Expand Up @@ -185,7 +185,7 @@ var _ = Describe("AlertsPolicy_webhooks", func() {
conditionSpec := AlertsPolicyConditionSpec{}
conditionSpec.Terms = []AlertsNrqlConditionTerm{
{
Operator: alerts.AlertsNrqlConditionTermsOperatorTypes.ABOVE,
Operator: alerts.AlertsNRQLConditionTermsOperatorTypes.ABOVE,
Priority: alerts.NrqlConditionPriorities.Critical,
Threshold: "5",
ThresholdDuration: 60,
Expand Down
52 changes: 52 additions & 0 deletions api/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 50 additions & 0 deletions config/crd/bases/nr.k8s.newrelic.com_alertsnrqlconditions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,17 @@ spec:
type: string
expected_groups:
type: integer
expiration:
description: AlertsNrqlConditionExpiration Settings for how violations
are opened or closed when a signal expires.
properties:
closeViolationsOnExpiration:
type: boolean
expirationDuration:
type: integer
openViolationOnExpiration:
type: boolean
type: object
id:
type: integer
ignore_overlap:
Expand All @@ -94,6 +105,20 @@ spec:
type: string
runbook_url:
type: string
signal:
description: AlertsNrqlConditionSignal - Configuration that defines
the signal that the NRQL condition will use to evaluate.
properties:
aggregation_window:
type: integer
evaluation_offset:
type: integer
fill_option:
description: AlertsFillOption - The available fill options.
type: string
fill_value:
type: string
type: object
terms:
items:
description: AlertsNrqlConditionTerm represents the terms of a New Relic alert condition.
Expand Down Expand Up @@ -172,6 +197,17 @@ spec:
type: string
expected_groups:
type: integer
expiration:
description: AlertsNrqlConditionExpiration Settings for how violations
are opened or closed when a signal expires.
properties:
closeViolationsOnExpiration:
type: boolean
expirationDuration:
type: integer
openViolationOnExpiration:
type: boolean
type: object
id:
type: integer
ignore_overlap:
Expand All @@ -190,6 +226,20 @@ spec:
type: string
runbook_url:
type: string
signal:
description: AlertsNrqlConditionSignal - Configuration that defines
the signal that the NRQL condition will use to evaluate.
properties:
aggregation_window:
type: integer
evaluation_offset:
type: integer
fill_option:
description: AlertsFillOption - The available fill options.
type: string
fill_value:
type: string
type: object
terms:
items:
description: AlertsNrqlConditionTerm represents the terms of a New Relic alert condition.
Expand Down
52 changes: 52 additions & 0 deletions config/crd/bases/nr.k8s.newrelic.com_alertspolicies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,17 @@ spec:
type: string
expected_groups:
type: integer
expiration:
description: AlertsNrqlConditionExpiration Settings for how
violations are opened or closed when a signal expires.
properties:
closeViolationsOnExpiration:
type: boolean
expirationDuration:
type: integer
openViolationOnExpiration:
type: boolean
type: object
gc_metric:
type: string
id:
Expand All @@ -122,6 +133,20 @@ spec:
type: string
runbook_url:
type: string
signal:
description: AlertsNrqlConditionSignal - Configuration that
defines the signal that the NRQL condition will use to evaluate.
properties:
aggregation_window:
type: integer
evaluation_offset:
type: integer
fill_option:
description: AlertsFillOption - The available fill options.
type: string
fill_value:
type: string
type: object
terms:
items:
description: AlertsNrqlConditionTerm represents the terms of a New Relic alert condition.
Expand Down Expand Up @@ -252,6 +277,17 @@ spec:
type: string
expected_groups:
type: integer
expiration:
description: AlertsNrqlConditionExpiration Settings for
how violations are opened or closed when a signal expires.
properties:
closeViolationsOnExpiration:
type: boolean
expirationDuration:
type: integer
openViolationOnExpiration:
type: boolean
type: object
gc_metric:
type: string
id:
Expand All @@ -274,6 +310,22 @@ spec:
type: string
runbook_url:
type: string
signal:
description: AlertsNrqlConditionSignal - Configuration
that defines the signal that the NRQL condition will
use to evaluate.
properties:
aggregation_window:
type: integer
evaluation_offset:
type: integer
fill_option:
description: AlertsFillOption - The available fill
options.
type: string
fill_value:
type: string
type: object
terms:
items:
description: AlertsNrqlConditionTerm represents the terms of a New Relic alert condition.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ var _ = Describe("AlertsNrqlCondition reconciliation", func() {
spec.APIKey = "nraa-key"
spec.Terms = []nrv1.AlertsNrqlConditionTerm{
{
Operator: alerts.AlertsNrqlConditionTermsOperatorTypes.ABOVE,
Operator: alerts.AlertsNRQLConditionTermsOperatorTypes.ABOVE,
Priority: alerts.NrqlConditionPriorities.Critical,
Threshold: "5",
ThresholdDuration: 60,
Expand Down
7 changes: 5 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,22 @@ module github.com/newrelic/newrelic-kubernetes-operator
go 1.13

require (
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver/v3 v3.1.1 // indirect
github.com/davecgh/go-spew v1.1.1
github.com/fatih/color v1.10.0 // indirect
github.com/go-logr/logr v0.1.0
github.com/golang/mock v1.4.3
github.com/goreleaser/goreleaser v0.143.0
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/maxbrunsfeld/counterfeiter/v6 v6.2.3
github.com/newrelic/go-agent/v3 v3.7.0
github.com/newrelic/newrelic-client-go v0.39.0
github.com/newrelic/newrelic-client-go v0.60.0
github.com/onsi/ginkgo v1.13.0
github.com/onsi/gomega v1.10.1
github.com/prometheus/client_golang v1.6.0 // indirect
github.com/prometheus/common v0.10.0 // indirect
github.com/stretchr/testify v1.6.1
github.com/stretchr/testify v1.7.0
golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1 // indirect
golang.org/x/tools v0.0.0-20200724022722-7017fd6b1305
gomodules.xyz/jsonpatch/v2 v2.1.0 // indirect
Expand Down
Loading

0 comments on commit cd1d592

Please sign in to comment.