Skip to content

Commit

Permalink
feat: add NotificationPresetName to monitor options (#1001)
Browse files Browse the repository at this point in the history
* feat: add NotificationPresetName to monitor options

In datadog, we have the possibility to toggle the "Content display in notification" for every monitor. This PR enables this.

More info in https://docs.datadoghq.com/monitors/notify/#toggle-additional-content

* pr review

Co-authored-by: Celene <[email protected]>

* Update datadogmonitor_types.go

Co-authored-by: Celene <[email protected]>

* Update datadogmonitor_types.go

Co-authored-by: Celene <[email protected]>

* Update datadogmonitor_types.go

Co-authored-by: Celene <[email protected]>

* update generated files

---------

Co-authored-by: Celene <[email protected]>
  • Loading branch information
bakayolo and celenechang authored Dec 7, 2023
1 parent c0295c5 commit 7bd890e
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 13 deletions.
12 changes: 12 additions & 0 deletions apis/datadoghq/v1alpha1/datadogmonitor_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ const (
DatadogMonitorTypeComposite DatadogMonitorType = "composite"
)

// DatadogMonitorOptionsNotificationPreset toggles the display of additional content sent in the monitor notification.
type DatadogMonitorOptionsNotificationPreset string

const (
DatadogMonitorOptionsNotificationPresetShowAll DatadogMonitorOptionsNotificationPreset = "show_all"
DatadogMonitorOptionsNotificationPresetHideQuery DatadogMonitorOptionsNotificationPreset = "hide_query"
DatadogMonitorOptionsNotificationPresetHideHandles DatadogMonitorOptionsNotificationPreset = "hide_handles"
DatadogMonitorOptionsNotificationPresetHideAll DatadogMonitorOptionsNotificationPreset = "hide_all"
)

// DatadogMonitorOptions define the optional parameters of a monitor
// +k8s:openapi-gen=true
type DatadogMonitorOptions struct {
Expand All @@ -90,6 +100,8 @@ type DatadogMonitorOptions struct {
// monitor timeframe for metric alerts or 2 minutes for service checks. If omitted, 2x the evaluation timeframe
// is used for metric alerts, and 24 hours is used for service checks.
NoDataTimeframe *int64 `json:"noDataTimeframe,omitempty"`
// An enum that toggles the display of additional content sent in the monitor notification.
NotificationPresetName DatadogMonitorOptionsNotificationPreset `json:"notificationPresetName,omitempty"`
// A Boolean indicating whether tagged users are notified on changes to this monitor.
NotifyAudit *bool `json:"notifyAudit,omitempty"`
// A Boolean indicating whether this monitor notifies when data stops reporting.
Expand Down
7 changes: 7 additions & 0 deletions apis/datadoghq/v1alpha1/zz_generated.openapi.go

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

3 changes: 3 additions & 0 deletions config/crd/bases/v1/datadoghq.com_datadogmonitors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ spec:
description: The number of minutes before a monitor notifies after data stops reporting. Datadog recommends at least 2x the monitor timeframe for metric alerts or 2 minutes for service checks. If omitted, 2x the evaluation timeframe is used for metric alerts, and 24 hours is used for service checks.
format: int64
type: integer
notificationPresetName:
description: An enum that toggles the display of additional content sent in the monitor notification.
type: string
notifyAudit:
description: A Boolean indicating whether tagged users are notified on changes to this monitor.
type: boolean
Expand Down
3 changes: 3 additions & 0 deletions config/crd/bases/v1beta1/datadoghq.com_datadogmonitors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ spec:
description: The number of minutes before a monitor notifies after data stops reporting. Datadog recommends at least 2x the monitor timeframe for metric alerts or 2 minutes for service checks. If omitted, 2x the evaluation timeframe is used for metric alerts, and 24 hours is used for service checks.
format: int64
type: integer
notificationPresetName:
description: An enum that toggles the display of additional content sent in the monitor notification.
type: string
notifyAudit:
description: A Boolean indicating whether tagged users are notified on changes to this monitor.
type: boolean
Expand Down
4 changes: 4 additions & 0 deletions controllers/datadogmonitor/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ func buildMonitor(logger logr.Logger, dm *datadoghqv1alpha1.DatadogMonitor) (*da
o.SetTimeoutH(*options.TimeoutH)
}

if options.NotificationPresetName != "" {
o.SetNotificationPresetName(datadogV1.MonitorOptionsNotificationPresets(string(options.NotificationPresetName)))
}

m := datadogV1.NewMonitor(query, monitorType)
{
m.SetName(name)
Expand Down
30 changes: 17 additions & 13 deletions controllers/datadogmonitor/monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,17 @@ func Test_buildMonitor(t *testing.T) {
"kube_cluster:test.staging",
},
Options: datadoghqv1alpha1.DatadogMonitorOptions{
EnableLogsSample: &valTrue,
EvaluationDelay: &evalDelay,
EscalationMessage: &escalationMsg,
IncludeTags: &valTrue,
Locked: &valTrue,
NewGroupDelay: &newGroupDelay,
NotifyNoData: &valTrue,
NoDataTimeframe: &noDataTimeframe,
RenotifyInterval: &renotifyInterval,
TimeoutH: &timeoutH,
EnableLogsSample: &valTrue,
EvaluationDelay: &evalDelay,
EscalationMessage: &escalationMsg,
IncludeTags: &valTrue,
Locked: &valTrue,
NewGroupDelay: &newGroupDelay,
NoDataTimeframe: &noDataTimeframe,
NotificationPresetName: "show_all",
NotifyNoData: &valTrue,
RenotifyInterval: &renotifyInterval,
TimeoutH: &timeoutH,
Thresholds: &datadoghqv1alpha1.DatadogMonitorOptionsThresholds{
Critical: &critThreshold,
Warning: &warnThreshold,
Expand Down Expand Up @@ -108,12 +109,15 @@ func Test_buildMonitor(t *testing.T) {
assert.Equal(t, *dm.Spec.Options.NewGroupDelay, monitor.Options.GetNewGroupDelay(), "discrepancy found in parameter: NewGroupDelay")
assert.Equal(t, *dm.Spec.Options.NewGroupDelay, monitorUR.Options.GetNewGroupDelay(), "discrepancy found in parameter: NewGroupDelay")

assert.Equal(t, *dm.Spec.Options.NotifyNoData, monitor.Options.GetNotifyNoData(), "discrepancy found in parameter: NotifyNoData")
assert.Equal(t, *dm.Spec.Options.NotifyNoData, monitorUR.Options.GetNotifyNoData(), "discrepancy found in parameter: NotifyNoData")

assert.Equal(t, *dm.Spec.Options.NoDataTimeframe, monitor.Options.GetNoDataTimeframe(), "discrepancy found in parameter: NoDataTimeframe")
assert.Equal(t, *dm.Spec.Options.NoDataTimeframe, monitorUR.Options.GetNoDataTimeframe(), "discrepancy found in parameter: NoDataTimeframe")

assert.Equal(t, string(dm.Spec.Options.NotificationPresetName), string(monitor.Options.GetNotificationPresetName()), "discrepancy found in parameter: NotificationPresetName")
assert.Equal(t, string(dm.Spec.Options.NotificationPresetName), string(monitorUR.Options.GetNotificationPresetName()), "discrepancy found in parameter: NotificationPresetName")

assert.Equal(t, *dm.Spec.Options.NotifyNoData, monitor.Options.GetNotifyNoData(), "discrepancy found in parameter: NotifyNoData")
assert.Equal(t, *dm.Spec.Options.NotifyNoData, monitorUR.Options.GetNotifyNoData(), "discrepancy found in parameter: NotifyNoData")

assert.Equal(t, *dm.Spec.Options.RenotifyInterval, monitor.Options.GetRenotifyInterval(), "discrepancy found in parameter: RenotifyInterval")
assert.Equal(t, *dm.Spec.Options.RenotifyInterval, monitorUR.Options.GetRenotifyInterval(), "discrepancy found in parameter: RenotifyInterval")

Expand Down

0 comments on commit 7bd890e

Please sign in to comment.