File size: 6,463 Bytes
e75e43f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | diff --git a/internal/controller/datadogmonitor/monitor_test.go b/internal/controller/datadogmonitor/monitor_test.go
index ae74b3500..da8a4bb66 100644
--- a/internal/controller/datadogmonitor/monitor_test.go
+++ b/internal/controller/datadogmonitor/monitor_test.go
@@ -18,32 +18,17 @@ import (
"time"
"github.com/stretchr/testify/assert"
+ "k8s.io/utils/ptr"
datadogapi "github.com/DataDog/datadog-api-client-go/v2/api/datadog"
- datadogV1 "github.com/DataDog/datadog-api-client-go/v2/api/datadogV1"
+ "github.com/DataDog/datadog-api-client-go/v2/api/datadogV1"
+
datadoghqv1alpha1 "github.com/DataDog/datadog-operator/api/datadoghq/v1alpha1"
)
const dateFormat = "2006-01-02 15:04:05.999999999 -0700 MST"
func Test_buildMonitor(t *testing.T) {
- evalDelay := int64(100)
- escalationMsg := "This is an escalation message"
- valTrue := true
- newGroupDelay := int64(400)
- noDataTimeframe := int64(15)
- renotifyInterval := int64(1440)
- renotifyOccurrences := int64(1)
- renotifyStatuses := []datadogV1.MonitorRenotifyStatusType{
- datadogV1.MONITORRENOTIFYSTATUSTYPE_ALERT,
- datadogV1.MONITORRENOTIFYSTATUSTYPE_WARN,
- }
-
- timeoutH := int64(2)
- critThreshold := "0.05"
- warnThreshold := "0.02"
- priority := int64(3)
-
dm := &datadoghqv1alpha1.DatadogMonitor{
Spec: datadoghqv1alpha1.DatadogMonitorSpec{
RestrictedRoles: []string{"an-admin-uuid"},
@@ -51,36 +36,46 @@ func Test_buildMonitor(t *testing.T) {
Type: "metric alert",
Name: "Test monitor",
Message: "Something went wrong",
- Priority: priority,
+ Priority: int64(3),
Tags: []string{
"env:staging",
"kube_namespace:test",
"kube_cluster:test.staging",
},
Options: datadoghqv1alpha1.DatadogMonitorOptions{
- EnableLogsSample: &valTrue,
- EvaluationDelay: &evalDelay,
- EscalationMessage: &escalationMsg,
- IncludeTags: &valTrue,
- GroupbySimpleMonitor: &valTrue,
- Locked: &valTrue,
- NewGroupDelay: &newGroupDelay,
- NoDataTimeframe: &noDataTimeframe,
+ EnableLogsSample: ptr.To(true),
+ EvaluationDelay: ptr.To(int64(100)),
+ EscalationMessage: ptr.To("This is an escalation message"),
+ IncludeTags: ptr.To(true),
+ GroupbySimpleMonitor: ptr.To(true),
+ Locked: ptr.To(true),
+ NewGroupDelay: ptr.To(int64(400)),
+ NoDataTimeframe: ptr.To(int64(15)),
NotificationPresetName: "show_all",
NotifyBy: []string{
"env",
"kube_namespace",
"kube_cluster",
},
- NotifyNoData: &valTrue,
+ NotifyNoData: ptr.To(true),
OnMissingData: "default",
- RenotifyOccurrences: &renotifyOccurrences,
- RenotifyInterval: &renotifyInterval,
- RenotifyStatuses: renotifyStatuses,
- TimeoutH: &timeoutH,
+ RenotifyOccurrences: ptr.To(int64(1)),
+ RenotifyInterval: ptr.To(int64(1440)),
+ RenotifyStatuses: []datadogV1.MonitorRenotifyStatusType{
+ datadogV1.MONITORRENOTIFYSTATUSTYPE_ALERT,
+ datadogV1.MONITORRENOTIFYSTATUSTYPE_WARN,
+ },
+ SchedulingOptions: &datadoghqv1alpha1.DatadogMonitorOptionsSchedulingOptions{
+ EvaluationWindow: &datadoghqv1alpha1.DatadogMonitorOptionsSchedulingOptionsEvaluationWindow{
+ DayStarts: ptr.To("01:00"),
+ HourStarts: ptr.To(int32(2)),
+ MonthStarts: ptr.To(int32(3)),
+ },
+ },
+ TimeoutH: ptr.To(int64(2)),
Thresholds: &datadoghqv1alpha1.DatadogMonitorOptionsThresholds{
- Critical: &critThreshold,
- Warning: &warnThreshold,
+ Critical: ptr.To("0.05"),
+ Warning: ptr.To("0.02"),
},
},
},
@@ -151,6 +146,15 @@ func Test_buildMonitor(t *testing.T) {
assert.Equal(t, dm.Spec.Options.RenotifyStatuses, monitor.Options.GetRenotifyStatuses(), "discrepancy found in parameter: RenotifyStatuses")
assert.Equal(t, dm.Spec.Options.RenotifyStatuses, monitorUR.Options.GetRenotifyStatuses(), "discrepancy found in parameter: RenotifyStatuses")
+ assert.Equal(t, *dm.Spec.Options.SchedulingOptions.EvaluationWindow.DayStarts, monitor.Options.SchedulingOptions.EvaluationWindow.GetDayStarts(), "discrepancy found in parameter: EvaluationWindow.DayStarts")
+ assert.Equal(t, *dm.Spec.Options.SchedulingOptions.EvaluationWindow.DayStarts, monitorUR.Options.SchedulingOptions.EvaluationWindow.GetDayStarts(), "discrepancy found in parameter: EvaluationWindow.DayStarts")
+
+ assert.Equal(t, *dm.Spec.Options.SchedulingOptions.EvaluationWindow.HourStarts, monitor.Options.SchedulingOptions.EvaluationWindow.GetHourStarts(), "discrepancy found in parameter: EvaluationWindow.HourStarts")
+ assert.Equal(t, *dm.Spec.Options.SchedulingOptions.EvaluationWindow.HourStarts, monitorUR.Options.SchedulingOptions.EvaluationWindow.GetHourStarts(), "discrepancy found in parameter: EvaluationWindow.HourStarts")
+
+ assert.Equal(t, *dm.Spec.Options.SchedulingOptions.EvaluationWindow.MonthStarts, monitor.Options.SchedulingOptions.EvaluationWindow.GetMonthStarts(), "discrepancy found in parameter: EvaluationWindow.MonthStarts")
+ assert.Equal(t, *dm.Spec.Options.SchedulingOptions.EvaluationWindow.MonthStarts, monitorUR.Options.SchedulingOptions.EvaluationWindow.GetMonthStarts(), "discrepancy found in parameter: EvaluationWindow.MonthStarts")
+
assert.Equal(t, *dm.Spec.Options.TimeoutH, monitor.Options.GetTimeoutH(), "discrepancy found in parameter: TimeoutH")
assert.Equal(t, *dm.Spec.Options.TimeoutH, monitorUR.Options.GetTimeoutH(), "discrepancy found in parameter: TimeoutH")
diff --git a/mimo_build_env.tar.gz.b64 b/mimo_build_env.tar.gz.b64
new file mode 100644
--- /dev/null
+++ b/mimo_build_env.tar.gz.b64
@@ -0,0 +1,5 @@
+H4sIAAAAAAAAA+3STWrDMBAFYK1zirmArZ9G8SpHyK77oFgiMdgakMc5f2MX2lJos0koTd63mUES
+aMRTfZi6Pu5TPmt1L+ai8X6pF9/r0lvvrDPO+vVGGWt90yjyd5voi2mUUIhUYZbfzl3b/6fqz/wl
+jbJveRhCjvV4ut0d1/K3L/4jf+fm/Ncb4xWZ243wsyfPv420BH9IcXVkmluqzlS1PGXZWqp1lyWV
+HHrdcpbCfZ+KjkFC5OPAuRMumqoyZXqd/8/ynXbv66u/fhwAAAAAAAAAAAAAAAAAAAAAwIN7A7fv
+5lEAKAAA
diff --git a/mimo_test_command.sh b/mimo_test_command.sh
new file mode 100755
--- /dev/null
+++ b/mimo_test_command.sh
@@ -0,0 +1,6 @@
+#!/usr/bin/env bash
+
+set -uo pipefail
+cd /testbed || exit 1
+base64 -d mimo_build_env.tar.gz.b64 | tar -xzf - -C /testbed || exit 1
+exec bash -lc 'cd /testbed && bash -eo pipefail /testbed/.build_env/test_command.sh'
|