From edd1f3c324deaa81f440f745fb50dcdac8890b33 Mon Sep 17 00:00:00 2001 From: Aditya Thebe Date: Wed, 17 Jul 2024 10:38:41 +0545 Subject: [PATCH 1/3] docs: config notification events --- .../docs/notifications/events/components.md | 3 +- .../docs/notifications/events/configs.md | 91 +++++++++++-------- .../reference/notifications/_notification.mdx | 32 +++---- mission-control/sidebars.js | 10 +- 4 files changed, 75 insertions(+), 61 deletions(-) diff --git a/mission-control/docs/notifications/events/components.md b/mission-control/docs/notifications/events/components.md index d6000dde..98db9b3e 100644 --- a/mission-control/docs/notifications/events/components.md +++ b/mission-control/docs/notifications/events/components.md @@ -7,8 +7,7 @@ Component status updates emit the following events - `component.healthy` - `component.unhealthy` - `component.warning` -- `component.error` -- `component.info` +- `component.unknown` ## Variables diff --git a/mission-control/docs/notifications/events/configs.md b/mission-control/docs/notifications/events/configs.md index 41199a81..0b6678b3 100644 --- a/mission-control/docs/notifications/events/configs.md +++ b/mission-control/docs/notifications/events/configs.md @@ -1,49 +1,54 @@ --- -title: Components +title: Configs --- -Component status updates emit the following events +Configs emit events when their health changes or when they are created, modified, or removed. + +**Health events** - `config.healthy` - `config.unhealthy` - `config.warning` +- `config.unknown` + +**State events** + +- `config.created` +- `config.updated` +- `config.deleted` ## Variables -| Field | Description | Schema | Optional | -| ----------- | ----------------------------- | ------------------------- | -------- | -| `config` | The component object | [`Component`](#component) | | -| `agent` | Agent details (if applicable) | [`Agent`](#agent) | `true` | -| `permalink` | A link to the health check | `string` | | - -### Component - -| Field | Description | Schema | Optional | -| ----------------- | -------------------------------------------- | ------------------- | -------- | -| `id` | The id of the component | `uuid` | | -| `description` | The description of the component | `string` | | -| `external_id` | The external id of the component | `string` | | -| `hidden` | Whether the component is hidden | `bool` | | -| `labels` | The labels of the component | `map[string]string` | `true` | -| `name` | The name of the component | `string` | | -| `namespace` | The namespace of the component | `string` | | -| `parent_id` | The id of the parent component | `uuid` | `true` | -| `properties` | The properties of the component | `map[string]string` | `true` | -| `silenced` | Whether the component is silenced | `bool` | | -| `status_reason` | The status reason of the component | `string` | | -| `status` | The status of the component | `string` | | -| `summary` | The summary of the component | `map[string]string` | `true` | -| `text` | The text of the component | `string` | | -| `topology_type` | The type of the topology | `string` | | -| `type` | The type of the component | `string` | | -| `cost_per_minute` | The cost per minute of the component | `float64` | | -| `cost_total_1d` | The cost total 1d of the component | `float64` | | -| `cost_total_7d` | The cost total 7d of the component | `float64` | | -| `cost_total_30d` | The cost total 30d of the component | `float64` | | -| `created_by` | Id of the person that created this component | `uuid` | | -| `created_at` | Created timestamp | `time.Time` | | -| `updated_at` | Updated timestamp | `time.Time` | | -| `deleted_at` | Deleted timestamp | `time.Time` | `true` | +| Field | Description | Schema | nullable | +| ----------- | ----------------------------- | ------------------- | -------- | +| `config` | The config object | [`Config`](#config) | | +| `agent` | Agent details (if applicable) | [`Agent`](#agent) | `true` | +| `permalink` | A link to the config item | `string` | | + +### Config + +| Field | Description | Schema | nullable | +| --------------- | -------------------------------- | --------------- | -------- | +| `id` | ID of the config item | `uuid` | | +| `agent_id` | ID of the agent | `uuid` | `true` | +| `config_class` | Class of the config item | `string` | | +| `config` | Configuration | `string` | `true` | +| `created_at` | Creation timestamp | `time.Time` | | +| `delete_reason` | Reason for deletion | `string` | `true` | +| `deleted_at` | Deletion timestamp | `time.Time` | `true` | +| `description` | Description | `string` | `true` | +| `external_id` | External IDs | `[]string` | `true` | +| `health` | Health | `Health` | `true` | +| `labels` | Labels | `JSONStringMap` | `true` | +| `name` | Name | `string` | `true` | +| `properties` | Properties | `Properties` | `true` | +| `ready` | Whether the config item is ready | `bool` | | +| `scraper_id` | ID of the scraper | `string` | `true` | +| `source` | Source | `string` | `true` | +| `status` | Status | `string` | `true` | +| `tags` | Tags | `JSONStringMap` | | +| `type` | Type | `string` | | +| `updated_at` | Update timestamp | `time.Time` | `true` | ### Agent @@ -55,9 +60,21 @@ Component status updates emit the following events ## Notification Defaults +**Health events** + +``` +# Title +Config {{.config.name}} health updated to {{.config.health}} + +# Body +[Reference]({{.permalink}}) +``` + +**State events** + ``` # Title -Config {{.config.name}} status updated to {{.config.status}} +Config {{.config.name}} was # Body [Reference]({{.permalink}}) diff --git a/mission-control/docs/reference/notifications/_notification.mdx b/mission-control/docs/reference/notifications/_notification.mdx index e2afbe53..8a133de8 100644 --- a/mission-control/docs/reference/notifications/_notification.mdx +++ b/mission-control/docs/reference/notifications/_notification.mdx @@ -1,22 +1,20 @@ - -| Field | Description | Scheme | Required | Templatable | -| ---------- | ------------------------------------------------------------------ | ------------------------- | -------- | ----------- | -| `events` | | [][Event](./events) | `true` || -| `to` | Notification recipient | [`Recipient`](#recipient) | `true` || -| `title` | Channel dependant e.g. subject for email | Go Template | | `true` | -| `template` |Channel dependant e.g. email body for email | Go Template | | `true` | -| `filter` | Filter out unwanted notifications | CEL | | | - +| Field | Description | Scheme | Required | Templatable | +| ---------- | --------------------------------------------------------------------------------------------------- | ----------------------------------------------------- | -------- | ----------- | +| `events` | | [[]Event](./events) | `true` | | +| `to` | Notification recipient | [`Recipient`](#recipient) | `true` | | +| `title` | Channel dependant e.g. subject for email | Go Template | | `true` | +| `template` | Channel dependant e.g. email body for email | Go Template | | `true` | +| `filter` | Filter out events. If the filter evaluates to true, the notification is processed - else discarded. | CEL | | | ### Recipient -| Field | Description | Schema | -| ------------ | ---------------------------------------------------------------- | ------------------- | -| `person` | | `UUID` or `email` of a person | -| `team` | Every member of the team with an email will receive a notification | `UUID` or `name` of team | -| `email` | Send an email to an external user | `email` | -| `connection` | Connection to external service | `connection` | -| `url` | Custom notification URL | [Channel](./channels) | -| `properties` | *Only applicable if `url` is specified* | `map[string]string` | +| Field | Description | Schema | +| ------------ | ------------------------------------------------------------------ | ----------------------------- | +| `person` | | `UUID` or `email` of a person | +| `team` | Every member of the team with an email will receive a notification | `UUID` or `name` of team | +| `email` | Send an email to an external user | `email` | +| `connection` | Connection to external service | `connection` | +| `url` | Custom notification URL | [Channel](./channels) | +| `properties` | _Only applicable if `url` is specified_ | `map[string]string` | > Only one recipient can be specified diff --git a/mission-control/sidebars.js b/mission-control/sidebars.js index 8c3c8862..cf38d09f 100644 --- a/mission-control/sidebars.js +++ b/mission-control/sidebars.js @@ -113,6 +113,11 @@ const sidebars = { slug: '/notifications/events' }, items: [ + { + type: 'doc', + id: 'notifications/events/configs', + label: 'Configs' + }, { type: 'doc', id: 'notifications/events/components', @@ -123,11 +128,6 @@ const sidebars = { id: 'notifications/events/health-checks', label: 'Health Checks' }, - // { - // type: 'doc', - // id: 'notifications/events/incidents', - // label: 'Incidents' - // } ] }, { From 38503d40bca9900f41142c1597373df1c977bf5a Mon Sep 17 00:00:00 2001 From: Aditya Thebe Date: Wed, 17 Jul 2024 11:35:41 +0545 Subject: [PATCH 2/3] examples notification for CrashLoopBackOff & CronJob failure --- .../examples/kube-job-failing.md | 18 ++++++++++++++++++ .../examples/kube-podcrashlooping.md | 19 +++++++++++++++++++ mission-control/sidebars.js | 10 ++++++++++ 3 files changed, 47 insertions(+) create mode 100644 mission-control/docs/notifications/examples/kube-job-failing.md create mode 100644 mission-control/docs/notifications/examples/kube-podcrashlooping.md diff --git a/mission-control/docs/notifications/examples/kube-job-failing.md b/mission-control/docs/notifications/examples/kube-job-failing.md new file mode 100644 index 00000000..7ada6f9b --- /dev/null +++ b/mission-control/docs/notifications/examples/kube-job-failing.md @@ -0,0 +1,18 @@ +--- +title: Kubernetes Job Failing +--- + +```yaml title="cronjob-alerts.yaml" +--- +apiVersion: mission-control.flanksource.com/v1 +kind: Notification +metadata: + name: cronjob-alerts + namespace: default +spec: + events: + - config.unhealthy + to: + connection: connection://flanksource-slack + filter: config.type == 'Kubernetes::CronJob' +``` diff --git a/mission-control/docs/notifications/examples/kube-podcrashlooping.md b/mission-control/docs/notifications/examples/kube-podcrashlooping.md new file mode 100644 index 00000000..b1f72da2 --- /dev/null +++ b/mission-control/docs/notifications/examples/kube-podcrashlooping.md @@ -0,0 +1,19 @@ +--- +title: PodCrashLooping notification +--- + +```yaml title="podcrashlooping-alerts.yaml" +--- +apiVersion: mission-control.flanksource.com/v1 +kind: Notification +metadata: + name: podcrashlooping-alerts + namespace: default +spec: + events: + - config.unhealthy + filter: config.type == 'Kubernetes::Pod' && config.status == 'CrashLoopBackOff' + to: + # use the slack connection as the recipient for this notification + connection: connection://flanksource-slack +``` diff --git a/mission-control/sidebars.js b/mission-control/sidebars.js index cf38d09f..d8e3ad44 100644 --- a/mission-control/sidebars.js +++ b/mission-control/sidebars.js @@ -139,6 +139,16 @@ const sidebars = { type: 'category', label: 'Examples', items: [ + { + type: 'doc', + id: 'notifications/examples/kube-podcrashlooping', + label: 'PodCrashLooping' + }, + { + type: 'doc', + id: 'notifications/examples/kube-job-failing', + label: 'Kubernetes Job Failing' + }, { type: 'doc', id: 'notifications/examples/slack', From 4b78472801dd58fc3b4674fe993ddd1936dc703d Mon Sep 17 00:00:00 2001 From: Aditya Thebe Date: Wed, 17 Jul 2024 20:11:07 +0545 Subject: [PATCH 3/3] chore: cleanup --- mission-control/docs/notifications/events/health-checks.md | 4 ++-- mission-control/sidebars.js | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/mission-control/docs/notifications/events/health-checks.md b/mission-control/docs/notifications/events/health-checks.md index 5e11d083..a7e11a36 100644 --- a/mission-control/docs/notifications/events/health-checks.md +++ b/mission-control/docs/notifications/events/health-checks.md @@ -2,8 +2,8 @@ Health checks emit 2 events -1. `check.passed` -2. `check.failed` +- `check.passed` +- `check.failed` ## Variables diff --git a/mission-control/sidebars.js b/mission-control/sidebars.js index d8e3ad44..fab252b1 100644 --- a/mission-control/sidebars.js +++ b/mission-control/sidebars.js @@ -149,6 +149,12 @@ const sidebars = { id: 'notifications/examples/kube-job-failing', label: 'Kubernetes Job Failing' }, + ] + }, + { + type: 'category', + label: 'Tutorials', + items: [ { type: 'doc', id: 'notifications/examples/slack',