From 1ff0ee13ea2639973cf9227659a53cd02bddd195 Mon Sep 17 00:00:00 2001 From: dawidwisn <76947218+dawidwisn@users.noreply.github.com> Date: Tue, 8 Oct 2024 10:14:23 +0200 Subject: [PATCH] feat: PC-13340 Replay on SLO edit/creation - DataSource setting (#559) Abbitilit to trigger replay on SLO edit/creation - DataSource setting --- internal/manifest/v1alpha/examples/agent.go | 13 ++-- internal/manifest/v1alpha/examples/direct.go | 13 ++-- .../agent/examples/amazon-prometheus.yaml | 6 ++ .../v1alpha/agent/examples/app-dynamics.yaml | 6 ++ .../v1alpha/agent/examples/azure-monitor.yaml | 6 ++ .../agent/examples/azure-prometheus.yaml | 6 ++ .../v1alpha/agent/examples/cloud-watch.yaml | 6 ++ manifest/v1alpha/agent/examples/datadog.yaml | 6 ++ .../v1alpha/agent/examples/dynatrace.yaml | 6 ++ .../examples/google-cloud-monitoring.yaml | 6 ++ manifest/v1alpha/agent/examples/graphite.yaml | 6 ++ .../v1alpha/agent/examples/honeycomb.yaml | 6 ++ .../v1alpha/agent/examples/lightstep.yaml | 6 ++ .../v1alpha/agent/examples/logic-monitor.yaml | 6 ++ .../v1alpha/agent/examples/new-relic.yaml | 6 ++ .../v1alpha/agent/examples/prometheus.yaml | 6 ++ manifest/v1alpha/agent/examples/splunk.yaml | 6 ++ manifest/v1alpha/agent/validation.go | 17 +++++ manifest/v1alpha/agent/validation_test.go | 67 +++++++++++++------ manifest/v1alpha/data_sources.go | 52 ++++++++++++++ .../v1alpha/direct/examples/app-dynamics.yaml | 6 ++ .../direct/examples/azure-monitor.yaml | 6 ++ .../direct/examples/azure-prometheus.yaml | 6 ++ .../v1alpha/direct/examples/cloud-watch.yaml | 6 ++ manifest/v1alpha/direct/examples/datadog.yaml | 6 ++ .../v1alpha/direct/examples/dynatrace.yaml | 6 ++ .../examples/google-cloud-monitoring.yaml | 6 ++ .../v1alpha/direct/examples/honeycomb.yaml | 6 ++ .../v1alpha/direct/examples/lightstep.yaml | 6 ++ .../direct/examples/logic-monitor.yaml | 6 ++ .../v1alpha/direct/examples/new-relic.yaml | 6 ++ manifest/v1alpha/direct/examples/splunk.yaml | 6 ++ manifest/v1alpha/direct/validation.go | 16 +++++ manifest/v1alpha/direct/validation_test.go | 61 +++++++++++------ 34 files changed, 350 insertions(+), 51 deletions(-) diff --git a/internal/manifest/v1alpha/examples/agent.go b/internal/manifest/v1alpha/examples/agent.go index 86df5735..3266e06a 100644 --- a/internal/manifest/v1alpha/examples/agent.go +++ b/internal/manifest/v1alpha/examples/agent.go @@ -60,12 +60,15 @@ func (a agentExample) Generate() v1alphaAgent.Agent { agent = a.generateVariant(agent) typ, _ := agent.Spec.GetType() if maxDuration, err := v1alpha.GetDataRetrievalMaxDuration(manifest.KindAgent, typ); err == nil { + defaultDuration := v1alpha.HistoricalRetrievalDuration{ + Value: ptr(*maxDuration.Value / 2), + Unit: maxDuration.Unit, + } agent.Spec.HistoricalDataRetrieval = &v1alpha.HistoricalDataRetrieval{ - MaxDuration: maxDuration, - DefaultDuration: v1alpha.HistoricalRetrievalDuration{ - Value: ptr(*maxDuration.Value / 2), - Unit: maxDuration.Unit, - }, + MaxDuration: maxDuration, + DefaultDuration: defaultDuration, + TriggeredBySloCreation: &defaultDuration, + TriggeredBySloEdit: &defaultDuration, } } defaultQueryDelay := v1alpha.GetQueryDelayDefaults()[typ] diff --git a/internal/manifest/v1alpha/examples/direct.go b/internal/manifest/v1alpha/examples/direct.go index e0fadd12..e9d7d1b0 100644 --- a/internal/manifest/v1alpha/examples/direct.go +++ b/internal/manifest/v1alpha/examples/direct.go @@ -66,12 +66,15 @@ func (d directExample) Generate() v1alphaDirect.Direct { direct = d.generateVariant(direct) typ, _ := direct.Spec.GetType() if maxDuration, err := v1alpha.GetDataRetrievalMaxDuration(manifest.KindDirect, typ); err == nil { + defaultDuration := v1alpha.HistoricalRetrievalDuration{ + Value: ptr(*maxDuration.Value / 2), + Unit: maxDuration.Unit, + } direct.Spec.HistoricalDataRetrieval = &v1alpha.HistoricalDataRetrieval{ - MaxDuration: maxDuration, - DefaultDuration: v1alpha.HistoricalRetrievalDuration{ - Value: ptr(*maxDuration.Value / 2), - Unit: maxDuration.Unit, - }, + MaxDuration: maxDuration, + DefaultDuration: defaultDuration, + TriggeredBySloCreation: &defaultDuration, + TriggeredBySloEdit: &defaultDuration, } } defaultQueryDelay := v1alpha.GetQueryDelayDefaults()[typ] diff --git a/manifest/v1alpha/agent/examples/amazon-prometheus.yaml b/manifest/v1alpha/agent/examples/amazon-prometheus.yaml index b313726c..c3c8e79f 100644 --- a/manifest/v1alpha/agent/examples/amazon-prometheus.yaml +++ b/manifest/v1alpha/agent/examples/amazon-prometheus.yaml @@ -17,6 +17,12 @@ spec: defaultDuration: value: 15 unit: Day + triggeredBySloCreation: + value: 15 + unit: Day + triggeredBySloEdit: + value: 15 + unit: Day queryDelay: value: 1 unit: Second diff --git a/manifest/v1alpha/agent/examples/app-dynamics.yaml b/manifest/v1alpha/agent/examples/app-dynamics.yaml index fe739fa3..ae2f63fb 100644 --- a/manifest/v1alpha/agent/examples/app-dynamics.yaml +++ b/manifest/v1alpha/agent/examples/app-dynamics.yaml @@ -16,6 +16,12 @@ spec: defaultDuration: value: 15 unit: Day + triggeredBySloCreation: + value: 15 + unit: Day + triggeredBySloEdit: + value: 15 + unit: Day queryDelay: value: 2 unit: Minute diff --git a/manifest/v1alpha/agent/examples/azure-monitor.yaml b/manifest/v1alpha/agent/examples/azure-monitor.yaml index a1a8ec66..8ccccab4 100644 --- a/manifest/v1alpha/agent/examples/azure-monitor.yaml +++ b/manifest/v1alpha/agent/examples/azure-monitor.yaml @@ -16,6 +16,12 @@ spec: defaultDuration: value: 15 unit: Day + triggeredBySloCreation: + value: 15 + unit: Day + triggeredBySloEdit: + value: 15 + unit: Day queryDelay: value: 6 unit: Minute diff --git a/manifest/v1alpha/agent/examples/azure-prometheus.yaml b/manifest/v1alpha/agent/examples/azure-prometheus.yaml index 171431ef..2dc6c2cb 100644 --- a/manifest/v1alpha/agent/examples/azure-prometheus.yaml +++ b/manifest/v1alpha/agent/examples/azure-prometheus.yaml @@ -17,6 +17,12 @@ spec: defaultDuration: value: 15 unit: Day + triggeredBySloCreation: + value: 15 + unit: Day + triggeredBySloEdit: + value: 15 + unit: Day queryDelay: value: 1 unit: Second diff --git a/manifest/v1alpha/agent/examples/cloud-watch.yaml b/manifest/v1alpha/agent/examples/cloud-watch.yaml index ed032506..accc831b 100644 --- a/manifest/v1alpha/agent/examples/cloud-watch.yaml +++ b/manifest/v1alpha/agent/examples/cloud-watch.yaml @@ -15,6 +15,12 @@ spec: defaultDuration: value: 7 unit: Day + triggeredBySloCreation: + value: 7 + unit: Day + triggeredBySloEdit: + value: 7 + unit: Day queryDelay: value: 2 unit: Minute diff --git a/manifest/v1alpha/agent/examples/datadog.yaml b/manifest/v1alpha/agent/examples/datadog.yaml index 88862514..19569da3 100644 --- a/manifest/v1alpha/agent/examples/datadog.yaml +++ b/manifest/v1alpha/agent/examples/datadog.yaml @@ -16,6 +16,12 @@ spec: defaultDuration: value: 15 unit: Day + triggeredBySloCreation: + value: 15 + unit: Day + triggeredBySloEdit: + value: 15 + unit: Day queryDelay: value: 2 unit: Minute diff --git a/manifest/v1alpha/agent/examples/dynatrace.yaml b/manifest/v1alpha/agent/examples/dynatrace.yaml index 7eab1e5d..0d255117 100644 --- a/manifest/v1alpha/agent/examples/dynatrace.yaml +++ b/manifest/v1alpha/agent/examples/dynatrace.yaml @@ -16,6 +16,12 @@ spec: defaultDuration: value: 14 unit: Day + triggeredBySloCreation: + value: 14 + unit: Day + triggeredBySloEdit: + value: 14 + unit: Day queryDelay: value: 3 unit: Minute diff --git a/manifest/v1alpha/agent/examples/google-cloud-monitoring.yaml b/manifest/v1alpha/agent/examples/google-cloud-monitoring.yaml index 0e7e555d..64b00a14 100644 --- a/manifest/v1alpha/agent/examples/google-cloud-monitoring.yaml +++ b/manifest/v1alpha/agent/examples/google-cloud-monitoring.yaml @@ -15,6 +15,12 @@ spec: defaultDuration: value: 15 unit: Day + triggeredBySloCreation: + value: 15 + unit: Day + triggeredBySloEdit: + value: 15 + unit: Day queryDelay: value: 3 unit: Minute diff --git a/manifest/v1alpha/agent/examples/graphite.yaml b/manifest/v1alpha/agent/examples/graphite.yaml index 89e94087..ff538a4d 100644 --- a/manifest/v1alpha/agent/examples/graphite.yaml +++ b/manifest/v1alpha/agent/examples/graphite.yaml @@ -16,6 +16,12 @@ spec: defaultDuration: value: 15 unit: Day + triggeredBySloCreation: + value: 15 + unit: Day + triggeredBySloEdit: + value: 15 + unit: Day queryDelay: value: 2 unit: Minute diff --git a/manifest/v1alpha/agent/examples/honeycomb.yaml b/manifest/v1alpha/agent/examples/honeycomb.yaml index dd3f2e7f..0d386356 100644 --- a/manifest/v1alpha/agent/examples/honeycomb.yaml +++ b/manifest/v1alpha/agent/examples/honeycomb.yaml @@ -15,6 +15,12 @@ spec: defaultDuration: value: 3 unit: Day + triggeredBySloCreation: + value: 3 + unit: Day + triggeredBySloEdit: + value: 3 + unit: Day queryDelay: value: 6 unit: Minute diff --git a/manifest/v1alpha/agent/examples/lightstep.yaml b/manifest/v1alpha/agent/examples/lightstep.yaml index 7e5718e0..042e84d9 100644 --- a/manifest/v1alpha/agent/examples/lightstep.yaml +++ b/manifest/v1alpha/agent/examples/lightstep.yaml @@ -18,6 +18,12 @@ spec: defaultDuration: value: 15 unit: Day + triggeredBySloCreation: + value: 15 + unit: Day + triggeredBySloEdit: + value: 15 + unit: Day queryDelay: value: 3 unit: Minute diff --git a/manifest/v1alpha/agent/examples/logic-monitor.yaml b/manifest/v1alpha/agent/examples/logic-monitor.yaml index b441cf30..ea43cec9 100644 --- a/manifest/v1alpha/agent/examples/logic-monitor.yaml +++ b/manifest/v1alpha/agent/examples/logic-monitor.yaml @@ -16,6 +16,12 @@ spec: defaultDuration: value: 15 unit: Day + triggeredBySloCreation: + value: 15 + unit: Day + triggeredBySloEdit: + value: 15 + unit: Day queryDelay: value: 3 unit: Minute diff --git a/manifest/v1alpha/agent/examples/new-relic.yaml b/manifest/v1alpha/agent/examples/new-relic.yaml index a0362d60..9ae597dc 100644 --- a/manifest/v1alpha/agent/examples/new-relic.yaml +++ b/manifest/v1alpha/agent/examples/new-relic.yaml @@ -16,6 +16,12 @@ spec: defaultDuration: value: 15 unit: Day + triggeredBySloCreation: + value: 15 + unit: Day + triggeredBySloEdit: + value: 15 + unit: Day queryDelay: value: 2 unit: Minute diff --git a/manifest/v1alpha/agent/examples/prometheus.yaml b/manifest/v1alpha/agent/examples/prometheus.yaml index e2b5645a..d6841a3e 100644 --- a/manifest/v1alpha/agent/examples/prometheus.yaml +++ b/manifest/v1alpha/agent/examples/prometheus.yaml @@ -16,6 +16,12 @@ spec: defaultDuration: value: 15 unit: Day + triggeredBySloCreation: + value: 15 + unit: Day + triggeredBySloEdit: + value: 15 + unit: Day queryDelay: value: 1 unit: Second diff --git a/manifest/v1alpha/agent/examples/splunk.yaml b/manifest/v1alpha/agent/examples/splunk.yaml index 36ccff33..3aa77175 100644 --- a/manifest/v1alpha/agent/examples/splunk.yaml +++ b/manifest/v1alpha/agent/examples/splunk.yaml @@ -16,6 +16,12 @@ spec: defaultDuration: value: 15 unit: Day + triggeredBySloCreation: + value: 15 + unit: Day + triggeredBySloEdit: + value: 15 + unit: Day queryDelay: value: 6 unit: Minute diff --git a/manifest/v1alpha/agent/validation.go b/manifest/v1alpha/agent/validation.go index 54490cd7..9dfe89a4 100644 --- a/manifest/v1alpha/agent/validation.go +++ b/manifest/v1alpha/agent/validation.go @@ -417,6 +417,23 @@ var historicalDataRetrievalValidationRule = govy.NewRule(func(spec Spec) error { errors.Errorf("must be less than or equal to %d %s", *maxDurationAllowed.Value, maxDurationAllowed.Unit)) } + + if spec.HistoricalDataRetrieval.TriggeredBySloCreation != nil && + spec.HistoricalDataRetrieval.TriggeredBySloCreation.BiggerThan(maxDurationAllowed) { + return govy.NewPropertyError( + "historicalDataRetrieval.triggeredBySloCreation", + spec.HistoricalDataRetrieval.TriggeredBySloCreation, + errors.Errorf("must be less than or equal to %d %s", + *maxDurationAllowed.Value, maxDurationAllowed.Unit)) + } + if spec.HistoricalDataRetrieval.TriggeredBySloEdit != nil && + spec.HistoricalDataRetrieval.TriggeredBySloEdit.BiggerThan(maxDurationAllowed) { + return govy.NewPropertyError( + "historicalDataRetrieval.triggeredBySloEdit", + spec.HistoricalDataRetrieval.TriggeredBySloEdit, + errors.Errorf("must be less than or equal to %d %s", + *maxDurationAllowed.Value, maxDurationAllowed.Unit)) + } return nil }) diff --git a/manifest/v1alpha/agent/validation_test.go b/manifest/v1alpha/agent/validation_test.go index 440530d0..ca4e4e94 100644 --- a/manifest/v1alpha/agent/validation_test.go +++ b/manifest/v1alpha/agent/validation_test.go @@ -232,8 +232,10 @@ func TestValidateSpec_HistoricalDataRetrieval(t *testing.T) { } { agent := validAgent(v1alpha.Prometheus) agent.Spec.HistoricalDataRetrieval = &v1alpha.HistoricalDataRetrieval{ - MaxDuration: v1alpha.HistoricalRetrievalDuration{Unit: unit, Value: ptr(0)}, - DefaultDuration: v1alpha.HistoricalRetrievalDuration{Unit: unit, Value: ptr(0)}, + MaxDuration: v1alpha.HistoricalRetrievalDuration{Unit: unit, Value: ptr(0)}, + DefaultDuration: v1alpha.HistoricalRetrievalDuration{Unit: unit, Value: ptr(0)}, + TriggeredBySloCreation: &v1alpha.HistoricalRetrievalDuration{Unit: unit, Value: ptr(0)}, + TriggeredBySloEdit: &v1alpha.HistoricalRetrievalDuration{Unit: unit, Value: ptr(0)}, } err := validate(agent) testutils.AssertNoError(t, agent, err) @@ -357,8 +359,10 @@ func TestValidateSpec_HistoricalDataRetrieval(t *testing.T) { } { agent := validAgent(v1alpha.Prometheus) agent.Spec.HistoricalDataRetrieval = &v1alpha.HistoricalDataRetrieval{ - MaxDuration: v1alpha.HistoricalRetrievalDuration{Value: ptr(10), Unit: unit}, - DefaultDuration: v1alpha.HistoricalRetrievalDuration{Value: ptr(10), Unit: unit}, + MaxDuration: v1alpha.HistoricalRetrievalDuration{Value: ptr(10), Unit: unit}, + DefaultDuration: v1alpha.HistoricalRetrievalDuration{Value: ptr(10), Unit: unit}, + TriggeredBySloCreation: &v1alpha.HistoricalRetrievalDuration{Value: ptr(10), Unit: unit}, + TriggeredBySloEdit: &v1alpha.HistoricalRetrievalDuration{Value: ptr(10), Unit: unit}, } err := validate(agent) testutils.AssertNoError(t, agent, err) @@ -375,31 +379,54 @@ func TestValidateSpec_HistoricalDataRetrieval(t *testing.T) { Value: ptr(10), Unit: v1alpha.HRDHour, }, - } - err := validate(agent) - testutils.AssertContainsErrors(t, agent, err, 1, testutils.ExpectedError{ - Prop: "spec.historicalDataRetrieval", - Message: "historical data retrieval is not supported for Generic Agent", - }) - }) - t.Run("data retrieval default larger than max", func(t *testing.T) { - agent := validAgent(v1alpha.Prometheus) - agent.Spec.HistoricalDataRetrieval = &v1alpha.HistoricalDataRetrieval{ - MaxDuration: v1alpha.HistoricalRetrievalDuration{ - Value: ptr(1), + TriggeredBySloCreation: &v1alpha.HistoricalRetrievalDuration{ + Value: ptr(10), Unit: v1alpha.HRDHour, }, - DefaultDuration: v1alpha.HistoricalRetrievalDuration{ - Value: ptr(2), + TriggeredBySloEdit: &v1alpha.HistoricalRetrievalDuration{ + Value: ptr(10), Unit: v1alpha.HRDHour, }, } err := validate(agent) testutils.AssertContainsErrors(t, agent, err, 1, testutils.ExpectedError{ - Prop: "spec.historicalDataRetrieval.defaultDuration", - Message: "must be less than or equal to 'maxDuration' (1 Hour)", + Prop: "spec.historicalDataRetrieval", + Message: "historical data retrieval is not supported for Generic Agent", }) }) + t.Run("data retrieval default, triggeredBySloCreation and TriggeredBySloEdit larger than max", + func(t *testing.T) { + agent := validAgent(v1alpha.Prometheus) + agent.Spec.HistoricalDataRetrieval = &v1alpha.HistoricalDataRetrieval{ + MaxDuration: v1alpha.HistoricalRetrievalDuration{ + Value: ptr(1), + Unit: v1alpha.HRDHour, + }, + DefaultDuration: v1alpha.HistoricalRetrievalDuration{ + Value: ptr(2), + Unit: v1alpha.HRDHour, + }, + TriggeredBySloCreation: &v1alpha.HistoricalRetrievalDuration{ + Value: ptr(10), + Unit: v1alpha.HRDHour, + }, + TriggeredBySloEdit: &v1alpha.HistoricalRetrievalDuration{ + Value: ptr(10), + Unit: v1alpha.HRDHour, + }, + } + err := validate(agent) + testutils.AssertContainsErrors(t, agent, err, 3, testutils.ExpectedError{ + Prop: "spec.historicalDataRetrieval.defaultDuration", + Message: "must be less than or equal to 'maxDuration' (1 Hour)", + }, testutils.ExpectedError{ + Prop: "spec.historicalDataRetrieval.triggeredBySloCreation", + Message: "must be less than or equal to 'maxDuration' (1 Hour)", + }, testutils.ExpectedError{ + Prop: "spec.historicalDataRetrieval.triggeredBySloEdit", + Message: "must be less than or equal to 'maxDuration' (1 Hour)", + }) + }) t.Run("data retrieval max greater than max allowed", func(t *testing.T) { for _, typ := range v1alpha.DataSourceTypeValues() { maxDuration, err := v1alpha.GetDataRetrievalMaxDuration(manifest.KindAgent, typ) diff --git a/manifest/v1alpha/data_sources.go b/manifest/v1alpha/data_sources.go index 435aee08..be061f87 100644 --- a/manifest/v1alpha/data_sources.go +++ b/manifest/v1alpha/data_sources.go @@ -238,12 +238,20 @@ type HistoricalDataRetrieval struct { MinimumAgentVersion string `json:"minimumAgentVersion,omitempty"` MaxDuration HistoricalRetrievalDuration `json:"maxDuration" validate:"required"` DefaultDuration HistoricalRetrievalDuration `json:"defaultDuration" validate:"required"` + // TriggeredBySloCreation is not supported yet, applying it will have no effect + TriggeredBySloCreation *HistoricalRetrievalDuration `json:"triggeredBySloCreation,omitempty"` + // TriggeredBySloEdit is not supported yet, applying it will have no effect + TriggeredBySloEdit *HistoricalRetrievalDuration `json:"triggeredBySloEdit,omitempty"` } func HistoricalDataRetrievalValidation() govy.Validator[HistoricalDataRetrieval] { return govy.New[HistoricalDataRetrieval]( govy.For(govy.GetSelf[HistoricalDataRetrieval]()). Rules(defaultDataRetrievalDurationValidation), + govy.For(govy.GetSelf[HistoricalDataRetrieval]()). + Rules(triggeredBySloCreationValidation), + govy.For(govy.GetSelf[HistoricalDataRetrieval]()). + Rules(triggeredBySloEditValidation), govy.For(func(h HistoricalDataRetrieval) HistoricalRetrievalDuration { return h.MaxDuration }). WithName("maxDuration"). Required(). @@ -252,6 +260,14 @@ func HistoricalDataRetrievalValidation() govy.Validator[HistoricalDataRetrieval] WithName("defaultDuration"). Required(). Include(historicalRetrievalDurationValidation), + govy.ForPointer(func(h HistoricalDataRetrieval) *HistoricalRetrievalDuration { return h.TriggeredBySloCreation }). + WithName("triggeredByCreation"). + OmitEmpty(). + Include(historicalRetrievalDurationValidation), + govy.ForPointer(func(h HistoricalDataRetrieval) *HistoricalRetrievalDuration { return h.TriggeredBySloEdit }). + WithName("triggeredByEdit"). + OmitEmpty(). + Include(historicalRetrievalDurationValidation), ) } @@ -283,6 +299,42 @@ var defaultDataRetrievalDurationValidation = govy.NewRule( return nil }) +var triggeredBySloCreationValidation = govy.NewRule( + func(dataRetrieval HistoricalDataRetrieval) error { + if dataRetrieval.TriggeredBySloCreation != nil && + dataRetrieval.TriggeredBySloCreation.BiggerThan(dataRetrieval.MaxDuration) { + var maxDurationValue int + if dataRetrieval.MaxDuration.Value != nil { + maxDurationValue = *dataRetrieval.MaxDuration.Value + } + return govy.NewPropertyError( + "triggeredBySloCreation", + dataRetrieval.TriggeredBySloCreation, + errors.Errorf( + "must be less than or equal to 'maxDuration' (%d %s)", + maxDurationValue, dataRetrieval.MaxDuration.Unit)) + } + return nil + }) + +var triggeredBySloEditValidation = govy.NewRule( + func(dataRetrieval HistoricalDataRetrieval) error { + if dataRetrieval.TriggeredBySloEdit != nil && + dataRetrieval.TriggeredBySloEdit.BiggerThan(dataRetrieval.MaxDuration) { + var maxDurationValue int + if dataRetrieval.MaxDuration.Value != nil { + maxDurationValue = *dataRetrieval.MaxDuration.Value + } + return govy.NewPropertyError( + "triggeredBySloEdit", + dataRetrieval.TriggeredBySloEdit, + errors.Errorf( + "must be less than or equal to 'maxDuration' (%d %s)", + maxDurationValue, dataRetrieval.MaxDuration.Unit)) + } + return nil + }) + // HistoricalRetrievalDuration struct was previously called Duration. However, this name was too generic // since we also needed to introduce a Duration struct for QueryDelay, which allowed for different time units. // Time travel is allowed for days/hours/minutes, and query delay can be set to minutes/seconds. Separating those two diff --git a/manifest/v1alpha/direct/examples/app-dynamics.yaml b/manifest/v1alpha/direct/examples/app-dynamics.yaml index c1b963f4..7658b0ed 100644 --- a/manifest/v1alpha/direct/examples/app-dynamics.yaml +++ b/manifest/v1alpha/direct/examples/app-dynamics.yaml @@ -20,6 +20,12 @@ spec: defaultDuration: value: 15 unit: Day + triggeredBySloCreation: + value: 15 + unit: Day + triggeredBySloEdit: + value: 15 + unit: Day queryDelay: value: 2 unit: Minute diff --git a/manifest/v1alpha/direct/examples/azure-monitor.yaml b/manifest/v1alpha/direct/examples/azure-monitor.yaml index fa40fd6f..7a3dfd7d 100644 --- a/manifest/v1alpha/direct/examples/azure-monitor.yaml +++ b/manifest/v1alpha/direct/examples/azure-monitor.yaml @@ -18,6 +18,12 @@ spec: defaultDuration: value: 15 unit: Day + triggeredBySloCreation: + value: 15 + unit: Day + triggeredBySloEdit: + value: 15 + unit: Day queryDelay: value: 6 unit: Minute diff --git a/manifest/v1alpha/direct/examples/azure-prometheus.yaml b/manifest/v1alpha/direct/examples/azure-prometheus.yaml index a9451c7e..36aa340b 100644 --- a/manifest/v1alpha/direct/examples/azure-prometheus.yaml +++ b/manifest/v1alpha/direct/examples/azure-prometheus.yaml @@ -19,6 +19,12 @@ spec: defaultDuration: value: 15 unit: Day + triggeredBySloCreation: + value: 15 + unit: Day + triggeredBySloEdit: + value: 15 + unit: Day queryDelay: value: 1 unit: Second diff --git a/manifest/v1alpha/direct/examples/cloud-watch.yaml b/manifest/v1alpha/direct/examples/cloud-watch.yaml index a84b018c..f6f11fdc 100644 --- a/manifest/v1alpha/direct/examples/cloud-watch.yaml +++ b/manifest/v1alpha/direct/examples/cloud-watch.yaml @@ -16,6 +16,12 @@ spec: defaultDuration: value: 7 unit: Day + triggeredBySloCreation: + value: 7 + unit: Day + triggeredBySloEdit: + value: 7 + unit: Day queryDelay: value: 2 unit: Minute diff --git a/manifest/v1alpha/direct/examples/datadog.yaml b/manifest/v1alpha/direct/examples/datadog.yaml index 71de31ca..a3d29f41 100644 --- a/manifest/v1alpha/direct/examples/datadog.yaml +++ b/manifest/v1alpha/direct/examples/datadog.yaml @@ -18,6 +18,12 @@ spec: defaultDuration: value: 15 unit: Day + triggeredBySloCreation: + value: 15 + unit: Day + triggeredBySloEdit: + value: 15 + unit: Day queryDelay: value: 2 unit: Minute diff --git a/manifest/v1alpha/direct/examples/dynatrace.yaml b/manifest/v1alpha/direct/examples/dynatrace.yaml index 52e0235d..85748694 100644 --- a/manifest/v1alpha/direct/examples/dynatrace.yaml +++ b/manifest/v1alpha/direct/examples/dynatrace.yaml @@ -17,6 +17,12 @@ spec: defaultDuration: value: 14 unit: Day + triggeredBySloCreation: + value: 14 + unit: Day + triggeredBySloEdit: + value: 14 + unit: Day queryDelay: value: 3 unit: Minute diff --git a/manifest/v1alpha/direct/examples/google-cloud-monitoring.yaml b/manifest/v1alpha/direct/examples/google-cloud-monitoring.yaml index a0dede52..c88de6f8 100644 --- a/manifest/v1alpha/direct/examples/google-cloud-monitoring.yaml +++ b/manifest/v1alpha/direct/examples/google-cloud-monitoring.yaml @@ -16,6 +16,12 @@ spec: defaultDuration: value: 15 unit: Day + triggeredBySloCreation: + value: 15 + unit: Day + triggeredBySloEdit: + value: 15 + unit: Day queryDelay: value: 3 unit: Minute diff --git a/manifest/v1alpha/direct/examples/honeycomb.yaml b/manifest/v1alpha/direct/examples/honeycomb.yaml index d2d32289..a0105782 100644 --- a/manifest/v1alpha/direct/examples/honeycomb.yaml +++ b/manifest/v1alpha/direct/examples/honeycomb.yaml @@ -16,6 +16,12 @@ spec: defaultDuration: value: 3 unit: Day + triggeredBySloCreation: + value: 3 + unit: Day + triggeredBySloEdit: + value: 3 + unit: Day queryDelay: value: 6 unit: Minute diff --git a/manifest/v1alpha/direct/examples/lightstep.yaml b/manifest/v1alpha/direct/examples/lightstep.yaml index 14491c33..9126e757 100644 --- a/manifest/v1alpha/direct/examples/lightstep.yaml +++ b/manifest/v1alpha/direct/examples/lightstep.yaml @@ -19,6 +19,12 @@ spec: defaultDuration: value: 15 unit: Day + triggeredBySloCreation: + value: 15 + unit: Day + triggeredBySloEdit: + value: 15 + unit: Day queryDelay: value: 3 unit: Minute diff --git a/manifest/v1alpha/direct/examples/logic-monitor.yaml b/manifest/v1alpha/direct/examples/logic-monitor.yaml index 5e06fa22..96c008fd 100644 --- a/manifest/v1alpha/direct/examples/logic-monitor.yaml +++ b/manifest/v1alpha/direct/examples/logic-monitor.yaml @@ -18,6 +18,12 @@ spec: defaultDuration: value: 15 unit: Day + triggeredBySloCreation: + value: 15 + unit: Day + triggeredBySloEdit: + value: 15 + unit: Day queryDelay: value: 3 unit: Minute diff --git a/manifest/v1alpha/direct/examples/new-relic.yaml b/manifest/v1alpha/direct/examples/new-relic.yaml index 5c143b11..68a6b587 100644 --- a/manifest/v1alpha/direct/examples/new-relic.yaml +++ b/manifest/v1alpha/direct/examples/new-relic.yaml @@ -17,6 +17,12 @@ spec: defaultDuration: value: 15 unit: Day + triggeredBySloCreation: + value: 15 + unit: Day + triggeredBySloEdit: + value: 15 + unit: Day queryDelay: value: 2 unit: Minute diff --git a/manifest/v1alpha/direct/examples/splunk.yaml b/manifest/v1alpha/direct/examples/splunk.yaml index 3edd492e..9340f8ee 100644 --- a/manifest/v1alpha/direct/examples/splunk.yaml +++ b/manifest/v1alpha/direct/examples/splunk.yaml @@ -17,6 +17,12 @@ spec: defaultDuration: value: 15 unit: Day + triggeredBySloCreation: + value: 15 + unit: Day + triggeredBySloEdit: + value: 15 + unit: Day queryDelay: value: 6 unit: Minute diff --git a/manifest/v1alpha/direct/validation.go b/manifest/v1alpha/direct/validation.go index 628f6a23..a740f67d 100644 --- a/manifest/v1alpha/direct/validation.go +++ b/manifest/v1alpha/direct/validation.go @@ -366,6 +366,22 @@ var historicalDataRetrievalValidationRule = govy.NewRule(func(spec Spec) error { errors.Errorf("must be less than or equal to %d %s", *maxDurationAllowed.Value, maxDurationAllowed.Unit)) } + if spec.HistoricalDataRetrieval.TriggeredBySloCreation != nil && + spec.HistoricalDataRetrieval.TriggeredBySloCreation.BiggerThan(maxDurationAllowed) { + return govy.NewPropertyError( + "historicalDataRetrieval.triggeredBySloCreation", + spec.HistoricalDataRetrieval.TriggeredBySloCreation, + errors.Errorf("must be less than or equal to %d %s", + *maxDurationAllowed.Value, maxDurationAllowed.Unit)) + } + if spec.HistoricalDataRetrieval.TriggeredBySloEdit != nil && + spec.HistoricalDataRetrieval.TriggeredBySloEdit.BiggerThan(maxDurationAllowed) { + return govy.NewPropertyError( + "historicalDataRetrieval.triggeredBySloEdit", + spec.HistoricalDataRetrieval.TriggeredBySloEdit, + errors.Errorf("must be less than or equal to %d %s", + *maxDurationAllowed.Value, maxDurationAllowed.Unit)) + } return nil }) diff --git a/manifest/v1alpha/direct/validation_test.go b/manifest/v1alpha/direct/validation_test.go index 7d07568c..04e7fdb3 100644 --- a/manifest/v1alpha/direct/validation_test.go +++ b/manifest/v1alpha/direct/validation_test.go @@ -256,8 +256,10 @@ func TestValidateSpec_HistoricalDataRetrieval(t *testing.T) { } { direct := validDirect(v1alpha.Datadog) direct.Spec.HistoricalDataRetrieval = &v1alpha.HistoricalDataRetrieval{ - MaxDuration: v1alpha.HistoricalRetrievalDuration{Unit: unit, Value: ptr(0)}, - DefaultDuration: v1alpha.HistoricalRetrievalDuration{Unit: unit, Value: ptr(0)}, + MaxDuration: v1alpha.HistoricalRetrievalDuration{Unit: unit, Value: ptr(0)}, + DefaultDuration: v1alpha.HistoricalRetrievalDuration{Unit: unit, Value: ptr(0)}, + TriggeredBySloCreation: &v1alpha.HistoricalRetrievalDuration{Unit: unit, Value: ptr(0)}, + TriggeredBySloEdit: &v1alpha.HistoricalRetrievalDuration{Unit: unit, Value: ptr(0)}, } err := validate(direct) testutils.AssertNoError(t, direct, err) @@ -381,8 +383,10 @@ func TestValidateSpec_HistoricalDataRetrieval(t *testing.T) { } { direct := validDirect(v1alpha.Datadog) direct.Spec.HistoricalDataRetrieval = &v1alpha.HistoricalDataRetrieval{ - MaxDuration: v1alpha.HistoricalRetrievalDuration{Value: ptr(10), Unit: unit}, - DefaultDuration: v1alpha.HistoricalRetrievalDuration{Value: ptr(10), Unit: unit}, + MaxDuration: v1alpha.HistoricalRetrievalDuration{Value: ptr(10), Unit: unit}, + DefaultDuration: v1alpha.HistoricalRetrievalDuration{Value: ptr(10), Unit: unit}, + TriggeredBySloCreation: &v1alpha.HistoricalRetrievalDuration{Value: ptr(10), Unit: unit}, + TriggeredBySloEdit: &v1alpha.HistoricalRetrievalDuration{Value: ptr(10), Unit: unit}, } err := validate(direct) testutils.AssertNoError(t, direct, err) @@ -406,24 +410,39 @@ func TestValidateSpec_HistoricalDataRetrieval(t *testing.T) { Message: "historical data retrieval is not supported for Instana Direct", }) }) - t.Run("data retrieval default larger than max", func(t *testing.T) { - direct := validDirect(v1alpha.Datadog) - direct.Spec.HistoricalDataRetrieval = &v1alpha.HistoricalDataRetrieval{ - MaxDuration: v1alpha.HistoricalRetrievalDuration{ - Value: ptr(1), - Unit: v1alpha.HRDHour, - }, - DefaultDuration: v1alpha.HistoricalRetrievalDuration{ - Value: ptr(2), - Unit: v1alpha.HRDHour, - }, - } - err := validate(direct) - testutils.AssertContainsErrors(t, direct, err, 1, testutils.ExpectedError{ - Prop: "spec.historicalDataRetrieval.defaultDuration", - Message: "must be less than or equal to 'maxDuration' (1 Hour)", + t.Run("data retrieval default, triggeredBySloCreation and TriggeredBySloEdit larger than max", + func(t *testing.T) { + direct := validDirect(v1alpha.Datadog) + direct.Spec.HistoricalDataRetrieval = &v1alpha.HistoricalDataRetrieval{ + MaxDuration: v1alpha.HistoricalRetrievalDuration{ + Value: ptr(1), + Unit: v1alpha.HRDHour, + }, + DefaultDuration: v1alpha.HistoricalRetrievalDuration{ + Value: ptr(2), + Unit: v1alpha.HRDHour, + }, + TriggeredBySloCreation: &v1alpha.HistoricalRetrievalDuration{ + Value: ptr(10), + Unit: v1alpha.HRDHour, + }, + TriggeredBySloEdit: &v1alpha.HistoricalRetrievalDuration{ + Value: ptr(10), + Unit: v1alpha.HRDHour, + }, + } + err := validate(direct) + testutils.AssertContainsErrors(t, direct, err, 3, testutils.ExpectedError{ + Prop: "spec.historicalDataRetrieval.defaultDuration", + Message: "must be less than or equal to 'maxDuration' (1 Hour)", + }, testutils.ExpectedError{ + Prop: "spec.historicalDataRetrieval.triggeredBySloCreation", + Message: "must be less than or equal to 'maxDuration' (1 Hour)", + }, testutils.ExpectedError{ + Prop: "spec.historicalDataRetrieval.triggeredBySloEdit", + Message: "must be less than or equal to 'maxDuration' (1 Hour)", + }) }) - }) t.Run("data retrieval max greater than max allowed", func(t *testing.T) { for typ := range validDirectTypes { maxDuration, err := v1alpha.GetDataRetrievalMaxDuration(manifest.KindDirect, typ)