Skip to content

Commit b6c00b2

Browse files
authored
Alert sensitivity grafana cloud (#604)
* Alert sensitivity grafana cloud * Add alert sens to test * Add description * Add description * Add description
1 parent 15f803d commit b6c00b2

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

api/v1alpha1/endpointmonitor_types.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,12 @@ type GrafanaConfig struct {
394394
// or services. These agents periodically send requests to predefined URLs and record the responses,
395395
// checking for expected outcomes and measuring performance.
396396
Probes []string `json:"probes,omitempty"`
397+
398+
// The alertSensitivity value defaults to none if there are no alerts or can be set to low, medium,
399+
// or high to correspond to the check alert levels.
400+
// +kubebuilder:validation:Enum=none;low;medium;high
401+
// +kubebuilder:default=none
402+
AlertSensitivity string `json:"alertSensitivity,omitempty"`
397403
}
398404

399405
// URLSource represents the set of resources to fetch the URL from

charts/ingressmonitorcontroller/crds/endpointmonitor.stakater.com_endpointmonitors.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,17 @@ spec:
6363
grafanaConfig:
6464
description: Configuration for Grafana Cloud Monitor Provider
6565
properties:
66+
alertSensitivity:
67+
default: none
68+
description: The alertSensitivity value defaults to none if there
69+
are no alerts or can be set to low, medium, or high to correspond
70+
to the check alert levels.
71+
enum:
72+
- none
73+
- low
74+
- medium
75+
- high
76+
type: string
6677
frequency:
6778
description: The frequency value specifies how often the check
6879
runs in milliseconds

pkg/monitors/grafana/grafana-monitor.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,13 @@ func (service *GrafanaMonitorService) CreateSyntheticCheck(monitor models.Monito
111111
var probeToSet []synthetic_monitoring.Probe
112112
var configProbeNames []string
113113
var frequency int64 = service.frequency
114+
var alertSensitivity string
114115
providerConfig, _ := monitor.Config.(*endpointmonitorv1alpha1.GrafanaConfig)
115116
if providerConfig != nil {
116117
// load configs from EndpointMonitor CR
118+
if providerConfig.AlertSensitivity != "" {
119+
alertSensitivity = providerConfig.AlertSensitivity
120+
}
117121
if providerConfig.Frequency > 0 {
118122
frequency = providerConfig.Frequency
119123
}
@@ -156,6 +160,7 @@ func (service *GrafanaMonitorService) CreateSyntheticCheck(monitor models.Monito
156160
},
157161
},
158162
BasicMetricsOnly: true,
163+
AlertSensitivity: alertSensitivity,
159164
}, nil
160165
}
161166

@@ -197,7 +202,7 @@ func (service *GrafanaMonitorService) Update(monitor models.Monitor) {
197202
// Using the synthetic monitoring client to update the old check
198203
createdCheck, err := service.smClient.UpdateCheck(service.ctx, *newCheck)
199204
if err != nil {
200-
log.Error(err, "Failed to update monitor")
205+
log.Error(err, "Failed to update monitor", "monitorID", checkID)
201206
return
202207
}
203208

pkg/monitors/grafana/grafana-monitor_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ func TestAddMonitorWithCorrectValues(t *testing.T) {
2929
service.Setup(*provider)
3030

3131
m := models.Monitor{Name: "google-test", URL: "https://google.com", Config: &endpointmonitorv1alpha1.GrafanaConfig{
32-
Frequency: 20000,
33-
Probes: []string{"Singapore"},
32+
Frequency: 20000,
33+
Probes: []string{"Singapore"},
34+
AlertSensitivity: "low",
3435
}}
3536

3637
preExistingMonitor, _ := service.GetByName(m.Name)
@@ -59,7 +60,7 @@ func TestAddMonitorWithCorrectValues(t *testing.T) {
5960
monitorConfig, _ := monitor.Config.(*endpointmonitorv1alpha1.GrafanaConfig)
6061
providerConfig, _ := m.Config.(*endpointmonitorv1alpha1.GrafanaConfig)
6162

62-
if monitor.Name != m.Name || monitor.URL != m.URL || monitorConfig.Frequency != providerConfig.Frequency || reflect.DeepEqual(monitorConfig.Probes, providerConfig.Probes) {
63+
if monitor.Name != m.Name || monitor.URL != m.URL || monitorConfig.Frequency != providerConfig.Frequency || reflect.DeepEqual(monitorConfig.Probes, providerConfig.Probes) || monitorConfig.AlertSensitivity != providerConfig.AlertSensitivity {
6364
t.Error("URL, name, frequency and probes should be the same", monitor, m)
6465
}
6566
service.Remove(*monitor)

0 commit comments

Comments
 (0)