Skip to content

Commit

Permalink
chore: doc updates
Browse files Browse the repository at this point in the history
  • Loading branch information
moshloop committed Jul 23, 2024
1 parent 5561cf5 commit 7889e89
Show file tree
Hide file tree
Showing 22 changed files with 535 additions and 140 deletions.
23 changes: 23 additions & 0 deletions CONVENTIONS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
1. Use an active, present tense voice
2. Do not use any salesy or marketing terms, Do not use adverbs
3. Use MDX formatting
4. Do not use the first person, Use "you" or "your team"
5. Do not use archaic language
6. Do not use oxymorons
7. Precede every command with an explanation of what the command does. After the command, provide additional details about the command, such as what the arguments do and why your reader is using them.
8. Avoid pop culture references, gender assumptions, holidays, hemisphere seasons, and other exclusionary language
9. Do not tell people how they feel
10. Explicitly tell the user to create or open each file you’ll have them use.
11. Like commands, always introduce a file or script by describing its general purpose, then explain any changes that the reader will be making in the file. Without these explanations, readers won’t be able to customize, update, or troubleshoot issues in the long run.
12. If you’re asking the reader to write code, follow the same approach for commands: introduce the code block with a high-level explanation of what it does. Then show the code, and then call out any important details.
13. Avoid adverbs and complex language
14. Use markdown codeblocks with a language and a title
15. Do not remove any "```" or "//highlight-next-line" text
16. Do not use the term "this document", when referring to the system or product being documented always use "Mission Control"
17. For examples using the following structure:
Introduction of example
Example Code
This example:
1. Using `field1` to perform A
2. Using `field2` to perform B
3. Achieves the result
132 changes: 132 additions & 0 deletions canary-checker/docs/concepts/expressions/_transform_fields.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
<Fields rows={[
{
field: "start",
description: "The time the check or event logically started (e.g if coming from an external source)",
scheme: "time.Time",
priority: 1,
required: false
},
{
field: "pass",
description: "Set to true if the health check is passing",
scheme: "bool",
priority: 2,
required: true
},
{
field: "invalid",
description: "Set to true if the check is not configured correctly, and can never pass",
scheme: "bool",
priority: 2,
required: false
},
{
field: "error",
description: "An error message to be shown, if non-empty sets `pass: false` automatically",
scheme: "string",
priority: 1,
required: false
},

{
field: "deletedAt",
description: "The time the check or event logically ended",
scheme: "time.Time",
priority: 1,
required: false
},
{
field: "duration",
description: "Time in ms to use for the duration of the check",
scheme: "int64",
priority: 2,
required: false
},

{
field: "message",
description: "Informational message to be shown to users",
scheme: "string",
priority: 1,
required: false
},

{
field: "name",
description: "Name of the check to use, the name will be used to lookup existing checks to update",
priority: 2,
scheme: "string",
required: true
},
{
field: "namespace",
description: null,
priority: 1,
scheme: "string",
required: false
},
{
field: "description",
description: null,
scheme: "string",
required: false
},
{
field: "type",
description: null,
scheme: "string",
required: false
},
{
field: "labels",
priority: 1,
description: null,
scheme: "map[string]string",
required: false
},

{
field: "detail",
description: null,
scheme: "interface{}",
required: false
},
{
field: "data",
description: null,
scheme: "map[string]interface{}",
required: false
},
{
field: "metrics",
description: "Add custom metrics to be exported",
scheme: "[[]Metric](../metrics/custom-metrics#metric)",
required: false
},
{
field: "icon",
description: null,
priority: 1,
scheme: "Icon",
required: false
},

{
field: "endpoint",
description: null,
scheme: "string",
required: false
},
{
field: "displayType",
description: null,
scheme: "string",
required: false
},
{
field: "transformDeleteStrategy",
description: "How to handle checks that were returned in a previous transformation, but not in the current ",
anyOf: ["MarkHealthy", "MarkUnhealthy", "Ignore"],
required: false
}
]}/>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
title: Transformation
---

import TransformFields from './_transform_fields.mdx'



The `transform` can be used to convert one canary check into multiple checks programmatically.

Expand Down Expand Up @@ -38,3 +41,8 @@ In the above example, the check will return multiple alerts from alertmanager. B
But if we want to display each alert as its own check in the UI, we can use the `transform` function for this. The transform function takes a `Template` as input and the output from the template expected are the checks in JSON format.

For example, if there are 9 different alerts, each alert will have its own check that can be managed and interacted with equally.

<TransformFields/>



68 changes: 68 additions & 0 deletions canary-checker/docs/reference/1-webhook.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
---
title: Webhook
---


import TransformFields from '../concepts/expressions/_transform_fields.mdx'

# <Icon name="webhook" /> Webhook

Webhooks allow you to create and update checks by sending HTTP POST or GET requests to endpoint.

```yaml title="webhook.yaml"
apiVersion: canaries.flanksource.com/v1
kind: Canary
metadata:
name: webhook
spec:
webhook:
# webhook names must be unique,
name: webhook-endpoint-1
transform:
expr: |
[{
'name': 'Webhook/' + results.json.name,
'pass': results.json.status == "healthy",
}].toJSON()
```
This example:
1. Defines a webhook named `webhook-endpoint-1` accessible via `http://<host>/webhooks/webhook-endpoint-1`
2. Transforms the incoming JSON into [check](#output)

This webhook can be called with:

```bash
curl --header "Content-Type: application/json" \
--request POST \
--data '{"name":"sample-webhook","status":"healthy"}' \
http://localhost/webhooks/webhook-endpoint-1
```


## Input

The request is available to the transformation function with these fields:

<Fields rows={[
{
field: 'results.json',
description: 'If `Content-Type: application/json` unmarshalls the request body to a JSON ',
scheme: '`JSON Object|Array`'
},
{
field: 'results.headers',

scheme: "`map[string]string`"
}, {
field: 'results.content',
description: 'Request body text, See [YAML](/reference/scripting/cel#yaml), [CSV](/reference/scripting/cel#csv)',
scheme: 'string'
}
]}/>

## Output

The return value is a list of checks

<TransformFields/>
29 changes: 26 additions & 3 deletions common/src/components/Fields.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,22 @@ export default function Fields({ common = [], rows = [], oneOf, anyOf, connectio
if (!a.required && b.required) {
return 1;
}
if (a.priority && !b.priority) {
return -1
}

if (!a.priority && b.priority) {
return 1
}
if (a.priority && b.priority && a.priority > b.priority) {
return -1
}


if (a.priority && b.priority && a.priority < b.priority) {
return 1
}

return a.field.localeCompare(b.field)
}
rows = rows.concat(common.filter(row => row.required))
Expand Down Expand Up @@ -292,9 +308,16 @@ export default function Fields({ common = [], rows = [], oneOf, anyOf, connectio
</td>
<td><ReactMarkdown>{(row.description ? row.description : "") + (row.default ? `. Defaults to \`${row.default}\`` : '')}</ReactMarkdown></td>
<td>
<ReactMarkdown>
{schemes[row.scheme] || (row.scheme ? row.scheme : 'string')}
</ReactMarkdown>
{row.anyOf &&
<code>{row.anyOf.join(' | ')}</code>
}
{!row.anyOf &&
<ReactMarkdown>
{
schemes[row.scheme] || (row.scheme ? row.scheme : 'string')
}
</ReactMarkdown>
}
</td>
</tr>
))}
Expand Down
21 changes: 13 additions & 8 deletions mission-control/docs/notifications/events/components.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@ Component status updates emit the following events
- `component.warning`
- `component.unknown`


The default notification template used is:
* **Title:** `Component {{.component.name}} is {{.component.health}}`
* **Body:**
```
### Labels:
{{range $k, $v := .component.labels}}**{{$k}}**: {{$v}}
{{end}}
[Reference]({{.permalink}})
```

The notification title and body can be changed using the variables below:

## Variables

| Field | Description | Schema | Optional |
Expand Down Expand Up @@ -54,12 +67,4 @@ Component status updates emit the following events
| `name` | The name of the agent | `string` | |
| `description` | Short description of the agent | `string` | |

## Notification Defaults

```
# Title
Component {{.component.name}} status updated to {{.component.status}}

# Body
[Reference]({{.permalink}})
```
39 changes: 22 additions & 17 deletions mission-control/docs/notifications/events/configs.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,34 @@ Configs emit events when their health changes or when they are created, modified
- `config.warning`
- `config.unknown`

The default notification template for health events is:

* **Title:** `{{.config.type}} {{.config.name}} is {{.config.health}}`
* **Body:**
```
### Labels:
{{range $k, $v := .config.labels}}**{{$k}}**: {{$v}}
{{end}}
[Reference]({{.permalink}})
```
**State events**

- `config.created`
- `config.updated`
- `config.deleted`

The default notification template for state events is:

* **Title:** `{{.config.type}} {{.config.name}} was [created/updated/deleted]`
* **Body:**
```
### Labels:
{{range $k, $v := .config.labels}}**{{$k}}**: {{$v}}
{{end}}
[Reference]({{.permalink}})
```


## Variables

| Field | Description | Schema | nullable |
Expand Down Expand Up @@ -60,22 +82,5 @@ Configs emit events when their health changes or when they are created, modified

## Notification Defaults

**Health events**

```
# Title
Config {{.config.name}} health updated to {{.config.health}}
# Body
[Reference]({{.permalink}})
```

**State events**

```
# Title
Config {{.config.name}} was <new-state>

# Body
[Reference]({{.permalink}})
```
Loading

0 comments on commit 7889e89

Please sign in to comment.