Skip to content

Commit

Permalink
Alert sensitivity grafana cloud (#604)
Browse files Browse the repository at this point in the history
* Alert sensitivity grafana cloud

* Add alert sens to test

* Add description

* Add description

* Add description
  • Loading branch information
MuneebAijaz authored Aug 28, 2024
1 parent 15f803d commit b6c00b2
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
6 changes: 6 additions & 0 deletions api/v1alpha1/endpointmonitor_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,12 @@ type GrafanaConfig struct {
// or services. These agents periodically send requests to predefined URLs and record the responses,
// checking for expected outcomes and measuring performance.
Probes []string `json:"probes,omitempty"`

// The alertSensitivity value defaults to none if there are no alerts or can be set to low, medium,
// or high to correspond to the check alert levels.
// +kubebuilder:validation:Enum=none;low;medium;high
// +kubebuilder:default=none
AlertSensitivity string `json:"alertSensitivity,omitempty"`
}

// URLSource represents the set of resources to fetch the URL from
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,17 @@ spec:
grafanaConfig:
description: Configuration for Grafana Cloud Monitor Provider
properties:
alertSensitivity:
default: none
description: The alertSensitivity value defaults to none if there
are no alerts or can be set to low, medium, or high to correspond
to the check alert levels.
enum:
- none
- low
- medium
- high
type: string
frequency:
description: The frequency value specifies how often the check
runs in milliseconds
Expand Down
7 changes: 6 additions & 1 deletion pkg/monitors/grafana/grafana-monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,13 @@ func (service *GrafanaMonitorService) CreateSyntheticCheck(monitor models.Monito
var probeToSet []synthetic_monitoring.Probe
var configProbeNames []string
var frequency int64 = service.frequency
var alertSensitivity string
providerConfig, _ := monitor.Config.(*endpointmonitorv1alpha1.GrafanaConfig)
if providerConfig != nil {
// load configs from EndpointMonitor CR
if providerConfig.AlertSensitivity != "" {
alertSensitivity = providerConfig.AlertSensitivity
}
if providerConfig.Frequency > 0 {
frequency = providerConfig.Frequency
}
Expand Down Expand Up @@ -156,6 +160,7 @@ func (service *GrafanaMonitorService) CreateSyntheticCheck(monitor models.Monito
},
},
BasicMetricsOnly: true,
AlertSensitivity: alertSensitivity,
}, nil
}

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

Expand Down
7 changes: 4 additions & 3 deletions pkg/monitors/grafana/grafana-monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ func TestAddMonitorWithCorrectValues(t *testing.T) {
service.Setup(*provider)

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

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

if monitor.Name != m.Name || monitor.URL != m.URL || monitorConfig.Frequency != providerConfig.Frequency || reflect.DeepEqual(monitorConfig.Probes, providerConfig.Probes) {
if monitor.Name != m.Name || monitor.URL != m.URL || monitorConfig.Frequency != providerConfig.Frequency || reflect.DeepEqual(monitorConfig.Probes, providerConfig.Probes) || monitorConfig.AlertSensitivity != providerConfig.AlertSensitivity {
t.Error("URL, name, frequency and probes should be the same", monitor, m)
}
service.Remove(*monitor)
Expand Down

0 comments on commit b6c00b2

Please sign in to comment.