Skip to content

Commit

Permalink
add playbook to send diagnostic report to Slack
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Jan 1, 2025
1 parent 13dfc92 commit deddccc
Show file tree
Hide file tree
Showing 5 changed files with 192 additions and 31 deletions.
16 changes: 10 additions & 6 deletions charts/playbooks-ai/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ Flanksource Mission Control Playbooks that uses AI action

## Values

| Key | Type | Default | Description |
| --------------------- | ------ | ------- | ----------------------------------------------------------------------------------- |
| connection | string | `""` | LLM connection: one of ollama, openai or anthropic |
| diagnose.cluster | string | `""` | name of the cluster |
| diagnose.enabled | bool | `true` | enable kubernetes diagnosing playbook |
| diagnose.systemPrompt | string | `""` | Optional system prompt for the LLM. If not provided, a default prompt will be used. |
| Key | Type | Default | Description |
| ------------------------------- | ------ | ------- | ------------------------------------------------------------------------------------------ |
| diagnose.cluster | string | `""` | name of the cluster |
| diagnose.enabled | bool | `true` | create a playbook that can diagnose an unhealthy kubernetes resource in the given cluster. |
| diagnose.systemPrompt | string | `""` | Optional system prompt for the LLM. If not provided, a default prompt will be used. |
| diganoseToSlack.cluster | string | `""` | name of the cluster |
| diganoseToSlack.enabled | bool | `true` | and send the diagnosis to slack. |
| diganoseToSlack.slackConnection | string | `""` | connection string for slack |
| diganoseToSlack.systemPrompt | string | `""` | Optional system prompt for the LLM. If not provided, a default prompt will be used. |
| global.connection | string | `""` | LLM connection: one of ollama, openai or anthropic |

## Maintainers

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/flanksource/duty/main/schema/openapi/playbook.schema.json
{{- if and .Values.diganoseToSlack.enabled }}
---
apiVersion: mission-control.flanksource.com/v1
kind: Playbook
metadata:
name: send-diagnostics-to-slack
spec:
description: Use AI to diganoseToSlack unhealthy kubernetes resources and send notification to slack
configs:
- tagSelector: 'cluster={{.Values.diganoseToSlack.cluster}}'
healths:
- unhealthy
- warning
# TODO: Limit this selector to kubernetes types
parameters:
- name: prompt
label: Prompt
default: Find out why $(.config.name) is unhealthy
properties:
multiline: 'true'
actions:
- name: query
ai:
connection: '{{.Values.global.connection}}'
systemPrompt: |-
{{- if .Values.diganoseToSlack.systemPrompt }}
{{- .Values.diganoseToSlack.systemPrompt | nindent 10 }}
{{- else }}
**Role:** Seasoned Kubernetes engineer and Diagnostic Expert
**Objective:** Assist users in diagnosing issues with unhealthy Kubernetes resources by analyzing provided manifests and related resources.
**Instructions:**
1. **Resource Analysis:** Examine the manifest of the unhealthy resource thoroughly.
2. **Contextual Investigation:** Consider additional related resources provided (e.g., pods, replica sets, namespaces) to gain a comprehensive understanding of the issue.
3. **One-Time Diagnosis:** Aim to diganoseToSlack the issue in a single response without requiring follow-up questions.
**Output:** Provide a concise diagnosis and potential solutions based on the analysis.
The output should be in json using Block Kit(https://api.slack.com/block-kit) - a UI framework for Slack apps.
Do not wrap the json block in a code block (like ```json```). The output should be a valid json.
Example: output
{
"blocks": [
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": "Statefulset: alertmanager"
},
{
"type": "mrkdwn",
"text": "*Namespace*: mc"
},
{
"type": "mrkdwn",
"text": "Deployment has pods that are in a crash loop."
}
]
},
]
}
{{- end }}
prompt: '$(.params.prompt)'
changes:
since: 2d
analysis:
since: 2d
relationships:
- depth: 5
direction: all
changes:
since: 24h
analysis:
since: 30d
- name: send notificaiton
notification:
connection: {{.Values.diganoseToSlack.slackConnection}}
message: "$(getLastAction.result.markdown)"
title: Diagnosis report
{{- end}}
10 changes: 4 additions & 6 deletions charts/playbooks-ai/templates/diagnose-kubernetes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ spec:
actions:
- name: query
ai:
connection: '{{.Values.connection}}'
connection: '{{.Values.global.connection}}'
systemPrompt: |-
{{- if .Values.diagnose.systemPrompt }}
{{- .Values.diagnose.systemPrompt | nindent 10 }}
Expand All @@ -47,11 +47,9 @@ spec:
since: 2d
relationships:
- depth: 5
direction: outgoing
changes:
since: 24h
- depth: 5
direction: incoming
direction: all
changes:
since: 24h
analysis:
since: 30d
{{- end}}
69 changes: 57 additions & 12 deletions charts/playbooks-ai/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"connection": {
"default": "",
"description": "yaml-language-server: $schema=values.schema.json\nLLM connection: one of ollama, openai or anthropic",
"required": [],
"title": "connection",
"type": "string"
},
"diagnose": {
"additionalProperties": false,
"properties": {
Expand All @@ -21,7 +14,7 @@
},
"enabled": {
"default": true,
"description": "enable kubernetes diagnosing playbook",
"description": "create a playbook that can diagnose an unhealthy kubernetes resource in the given cluster.",
"required": [],
"title": "enabled",
"type": "boolean"
Expand All @@ -40,16 +33,68 @@
"title": "diagnose",
"type": "object"
},
"diganoseToSlack": {
"additionalProperties": false,
"properties": {
"cluster": {
"default": "",
"description": "name of the cluster",
"required": [],
"title": "cluster",
"type": "string"
},
"enabled": {
"default": true,
"description": "create a playbook that can diagnose an unhealthy kubernetes resource in the given cluster\nand send the diagnosis to slack.",
"required": [],
"title": "enabled",
"type": "boolean"
},
"slackConnection": {
"default": "",
"description": "connection string for slack",
"required": [],
"title": "slackConnection",
"type": "string"
},
"systemPrompt": {
"default": "",
"description": "Optional system prompt for the LLM. If not provided, a default prompt will be used.",
"required": [],
"title": "systemPrompt",
"type": "string"
}
},
"required": [
"slackConnection",
"cluster"
],
"title": "diganoseToSlack",
"type": "object"
},
"global": {
"description": "Global values are values that can be accessed from any chart or subchart by exactly the same name.",
"required": [],
"additionalProperties": false,
"description": "yaml-language-server: $schema=values.schema.json",
"properties": {
"connection": {
"default": "",
"description": "LLM connection: one of ollama, openai or anthropic",
"required": [],
"title": "connection",
"type": "string"
}
},
"required": [
"connection"
],
"title": "global",
"type": "object"
}
},
"required": [
"connection",
"diagnose"
"global",
"diagnose",
"diganoseToSlack"
],
"type": "object"
}
45 changes: 38 additions & 7 deletions charts/playbooks-ai/values.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
# yaml-language-server: $schema=values.schema.json
# @schema
# type: string
# required: true
# @schema
# -- LLM connection: one of ollama, openai or anthropic
connection: ""
global:
# @schema
# type: string
# required: true
# @schema
# -- LLM connection: one of ollama, openai or anthropic
connection: ""

diagnose:
# @schema
# type: boolean
# required: false
# @schema
# -- enable kubernetes diagnosing playbook
# -- create a playbook that can diagnose an unhealthy kubernetes resource in the given cluster.
enabled: true

# @schema
Expand All @@ -27,3 +28,33 @@ diagnose:
# @schema
# -- Optional system prompt for the LLM. If not provided, a default prompt will be used.
systemPrompt: ""

diganoseToSlack:
# @schema
# type: boolean
# required: false
# @schema
# -- create a playbook that can diagnose an unhealthy kubernetes resource in the given cluster
# -- and send the diagnosis to slack.
enabled: true

# @schema
# type: string
# required: true
# @schema
# -- connection string for slack
slackConnection: ""

# @schema
# type: string
# required: true
# @schema
# -- name of the cluster
cluster: ""

# @schema
# type: string
# required: false
# @schema
# -- Optional system prompt for the LLM. If not provided, a default prompt will be used.
systemPrompt: ""

0 comments on commit deddccc

Please sign in to comment.