Skip to content

Commit

Permalink
Alert manger controller (#138)
Browse files Browse the repository at this point in the history
* bookmark

* bookmark

* initial commit

* adding OwnerReferences to webhooks

* adding deletion logic

* adding e2e tests

* changing tests folder names

* fixing tests

* fixing test

* refactoring

* adding support for RepeatInterval

* adding support for group-by, and seperating routes to different notification-groups

* skipping alert and webhooks in a case of an error

* fixing tests
  • Loading branch information
OrNovo authored Sep 13, 2024
1 parent d761dbe commit ec4cab3
Show file tree
Hide file tree
Showing 36 changed files with 1,717 additions and 75 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ endif
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/crd | kubectl apply -f -
kubectl apply -f https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/master/example/prometheus-operator-crd-full/monitoring.coreos.com_prometheusrules.yaml
kubectl apply --server-side -f https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/main/jsonnet/prometheus-operator/alertmanagerconfigs-crd.json


.PHONY: uninstall
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
Expand Down
4 changes: 3 additions & 1 deletion apis/coralogix/v1alpha1/outboundwebhook_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,9 @@ var (
)

type Slack struct {
Digests []SlackConfigDigest `json:"digests"`
// +optional
Digests []SlackConfigDigest `json:"digests"`
// +optional
Attachments []SlackConfigAttachment `json:"attachments"`
Url string `json:"url"`
}
Expand Down
4 changes: 0 additions & 4 deletions config/crd/bases/coralogix.com_outboundwebhooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,6 @@ spec:
url:
type: string
required:
- attachments
- digests
- url
type: object
type: object
Expand Down Expand Up @@ -342,8 +340,6 @@ spec:
url:
type: string
required:
- attachments
- digests
- url
type: object
type: object
Expand Down
48 changes: 48 additions & 0 deletions config/samples/alertmanger/example-alertmanager.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
apiVersion: monitoring.coreos.com/v1alpha1
kind: AlertmanagerConfig
metadata:
name: config-example
labels:
alertmanagerConfig: example
app.coralogix.com/track-alertmanger-config: "true"
spec:
route:
groupBy:
- alertname
- cluster
- alert_group
- job
- namespace
- severity
- priority
receiver: slack-default
repeatInterval: 3h
routes:
- receiver: slack-general
matchers:
- matchType: "=~"
name: slack_channel
value: ".+"
continue: true
- receiver: opsgenie-general
groupBy:
- alertname
matchers:
- matchType: "=~"
name: opsgenie_team
value: ".+"
repeatInterval: 4m
receivers:
- name: slack-general
slackConfigs:
- apiURL:
name: "slack-webhook-secret" # Name of the Kubernetes Secret
key: "webhook-url" # Key in the Kubernetes Secret
- name: opsgenie-general
opsgenieConfigs:
- apiURL: https://api.opsgenie.com/v2/alerts
- name: slack-default
slackConfigs:
- apiURL:
name: "slack-webhook-secret" # Name of the Kubernetes Secret
key: "webhook-url" # Key in the Kubernetes Secret
8 changes: 8 additions & 0 deletions config/samples/alertmanger/slack-url-secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v1
kind: Secret
metadata:
name: slack-webhook-secret # Name of the secret
namespace: default # Namespace where the secret is created
type: Opaque
data:
webhook-url: aHR0cHM6Ly9zbGFjay5jb20vYXBpL2NoYXQucG9zdE1lc3NhZ2U= # Base64 encoded API URL
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ metadata:
role: alert-rules
app.coralogix.com/track-recording-rules: "true"
app.coralogix.com/track-alerting-rules: "true"
app.coralogix.com/managed-by-alertmanger-config: "true"
name: prometheus-example-rules
spec:
groups:
Expand All @@ -24,6 +25,7 @@ spec:
cxMinNonNullValuesPercentage: "20"
labels:
severity: critical
slack_channel: "#observability"
- name: example.rules2
interval: "70s"
rules:
Expand All @@ -37,4 +39,11 @@ spec:
annotations:
cxMinNonNullValuesPercentage: "20"
labels:
severity: info
severity: info
slack_channel: "#observability"
opsgenie_team: "team1"
- alert: app-latency
expr: histogram_quantile(0.99, sum(irate(istio_request_duration_seconds_bucket{reporter="source",destination_service=~"ingress-annotation-test-svc.example-app.svc.cluster.local"}[1m])) by (le, destination_workload)) > 0.2
for: 5m
annotations:
cxMinNonNullValuesPercentage: "20"
Loading

0 comments on commit ec4cab3

Please sign in to comment.