Skip to content

Commit cca289d

Browse files
committed
docs: Add the API spec for Events and Providers v1beta2
Signed-off-by: Stefan Prodan <[email protected]>
1 parent 35fb87d commit cca289d

File tree

5 files changed

+1252
-3
lines changed

5 files changed

+1252
-3
lines changed

docs/spec/v1beta2/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# notification.toolkit.fluxcd.io/v1beta2
2+
3+
This is the v1beta2 API specification for defining events handling and dispatching.
4+
5+
## Specification
6+
7+
* [Alerts](alerts.md)
8+
* [Events](events.md)
9+
* [Providers](providers.md)
10+
* [Receivers](receivers.md)
11+
12+
## Go Client
13+
14+
* [github.com/fluxcd/pkg/recorder](https://github.com/fluxcd/pkg/tree/main/recorder)

docs/spec/v1beta2/alerts.md

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ metadata:
1515
namespace: flux-system
1616
spec:
1717
type: slack
18+
channel: general
1819
address: https://slack.com/api/chat.postMessage
1920
secretRef:
2021
name: slack-bot-token
@@ -47,7 +48,8 @@ In the above example:
4748
- The notification-controller starts listening for events sent for
4849
all GitRepositories and Kustomizations in the `flux-system` namespace.
4950
- When an event with severity `error` is received, the controller posts
50-
a message on Slack containing the `summary` text and the reconciliation error.
51+
a message on Slack channel from `.spec.channel`,
52+
containing the `summary` text and the reconciliation error.
5153

5254
You can run this example by saving the manifests into `slack-alerts.yaml`.
5355

@@ -72,10 +74,17 @@ valid [DNS subdomain name](https://kubernetes.io/docs/concepts/overview/working-
7274
An Alert also needs a
7375
[`.spec` section](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#spec-and-status).
7476

77+
### Summary
78+
79+
`.spec.summary` is an optional field to specify a short description of the
80+
impact and affected cluster.
81+
82+
The summary max length can't be greater than 255 characters.
83+
7584
### Provider reference
7685

7786
`.spec.providerRef.name` is a required field to specify a name reference to a
78-
Provider in the same namespace as the Alert.
87+
[Provider](providers.md) in the same namespace as the Alert.
7988

8089
### Event sources
8190

@@ -142,7 +151,7 @@ To receive alerts only on errors, set the field value to `error`.
142151
`.spec.exclusionList` is an optional field to specify a list of regex expressions to filter
143152
events based on message content.
144153

145-
### Example
154+
#### Example
146155

147156
Skip alerting if the message matches a [Go regex](https://golang.org/pkg/regexp/syntax)
148157
from the exclusion list:
@@ -166,3 +175,9 @@ The above definition will not send alerts for transient Git clone errors like:
166175
```text
167176
unable to clone 'ssh://[email protected]/v3/...', error: SSH could not read data: Error waiting on socket
168177
```
178+
179+
### Suspend
180+
181+
`.spec.suspend` is an optional field to suspend the altering.
182+
When set to `true`, the controller will stop processing events.
183+
When the field is set to `false` or removed, it will resume.

docs/spec/v1beta2/events.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Events
2+
3+
The `Event` API defines the structure of the events issued by Flux controllers.
4+
5+
Flux controllers use the [fluxcd/pkg/runtime/events](https://github.com/fluxcd/pkg/tree/main/runtime/events)
6+
package to push events to the notification-controller API.
7+
8+
## Example
9+
10+
The following is an example of an event sent by kustomize-controller to report a reconciliation error.
11+
12+
```json
13+
{
14+
"involvedObject": {
15+
"apiVersion": "kustomize.toolkit.fluxcd.io/v1beta2",
16+
"kind": "Kustomization",
17+
"name": "webapp",
18+
"namespace": "apps",
19+
"uid": "7d0cdc51-ddcf-4743-b223-83ca5c699632"
20+
},
21+
"metadata": {
22+
"kustomize.toolkit.fluxcd.io/revision": "main/731f7eaddfb6af01cb2173e18f0f75b0ba780ef1"
23+
},
24+
"severity":"error",
25+
"reason": "ValidationFailed",
26+
"message":"service/apps/webapp validation error: spec.type: Unsupported value: Ingress",
27+
"reportingController":"kustomize-controller",
28+
"timestamp":"2022-10-28T07:26:19Z"
29+
}
30+
```
31+
32+
In the above example:
33+
34+
- An event is issued by kustomize-controller for a specific object, indicated in the
35+
`involvedObject` field.
36+
- The notification-controller receives the event and finds the [alerts](alerts.md)
37+
that match the `involvedObject` and `severity` values.
38+
- For all matching alerts, the controller posts the `message` and the source revision
39+
extracted from `metadata` to the alert provider API.
40+
41+
## Event structure
42+
43+
The Go type that defines the event structure can be found in the
44+
[fluxcd/pkg/runtime/events](https://github.com/fluxcd/pkg/blob/main/runtime/events/event.go)
45+
package.
46+
47+
## Rate limiting
48+
49+
Events received by notification-controller are subject to rate limiting to reduce the
50+
amount of duplicate alerts sent to external systems like Slack, Sentry, etc.
51+
52+
Events are rate limited based on `involvedObject.name`, `involvedObject.namespace`,
53+
`involvedObject.kind`, `message`, and `metadata`.
54+
The interval of the rate limit is set by default to `5m` but can be configured
55+
with the `--rate-limit-interval` controller flag.
56+
57+
The event server exposes HTTP request metrics to track the amount of rate limited events.
58+
The following promql will get the rate at which requests are rate limited:
59+
60+
```
61+
rate(gotk_event_http_request_duration_seconds_count{code="429"}[30s])
62+
```

0 commit comments

Comments
 (0)