Skip to content

Commit 01ad655

Browse files
authored
doc: Created Resource Watcher Doc (#5193)
* Created Resource Watcher Doc * Incorporated PM Feedback * Variable Change + Fixes * Variable Change + Fixes * Incorporated CO + PM Feedback + Other Fixes
1 parent bb3790b commit 01ad655

File tree

2 files changed

+176
-0
lines changed

2 files changed

+176
-0
lines changed

docs/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
* [Overview](user-guide/jobs/overview-job.md)
105105
* [Application Groups](user-guide/application-groups.md)
106106
* [Resource Browser](user-guide/resource-browser.md)
107+
* [Resource Watcher](user-guide/resource-watcher.md)
107108
* [Charts](user-guide/deploy-chart/README.md)
108109
* [Charts Overview](user-guide/deploy-chart/overview-of-charts.md)
109110
* [Deploy & Observe](user-guide/deploy-chart/deployment-of-charts.md)

docs/user-guide/resource-watcher.md

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
# Resource Watcher
2+
3+
## Introduction [![](https://devtron-public-asset.s3.us-east-2.amazonaws.com/images/elements/EnterpriseTag.svg)](https://devtron.ai/pricing)
4+
5+
An incident response if delayed can impact businesses, revenue, and waste valuable engineering time. Devtron's Resource Watcher enables you to perform automated actions upon the occurrence of events:
6+
7+
* **Create Event** - Occurs when a new Kubernetes resource is created, for e.g., a new pod spun up to handle increased traffic.
8+
* **Update Event** - Occurs when an existing Kubernetes resource is modified, for e.g., deployment configuration tweaked to increase the replica count.
9+
* **Delete Event** - Occurs when an existing Kubernetes resource is deleted, for e.g., deletion of an orphaned pod.
10+
11+
You can make the Resource Watcher listen to the above events and accordingly run a job you wish to get done, for e.g., increasing memory, executing a script, raising Jira ticket, emailing your stakeholders, sending Slack notifications, and many more. Since manual intervention is absent, the timely response of this auto-remediation system improves your operational efficiency.
12+
13+
---
14+
15+
## Creating a Watcher
16+
17+
{% hint style="warning" %}
18+
### Who Can Perform This Action?
19+
Users need to have super-admin permission to create a watcher.
20+
{% endhint %}
21+
22+
This page allows you to create a watcher to track events and run a job. It also shows the existing list of watchers (if any).
23+
24+
1. Click **+ Create Watcher**.
25+
26+
![Figure 1: Watchers - Page](https://devtron-public-asset.s3.us-east-2.amazonaws.com/images/resource-watcher/watchers-page.jpg)
27+
28+
2. Creating a watcher consists of 4 parts, fill all the sections one by one:
29+
* [Basic Details](#basic-details)
30+
* [Namespaces to Watch](#namespaces-to-watch)
31+
* [Intercept Change in Resources](#intercept-change-in-resources)
32+
* [Execute Runbook](#execute-runbook)
33+
34+
![Figure 2: Create Watcher - Window](https://devtron-public-asset.s3.us-east-2.amazonaws.com/images/resource-watcher/create-watcher-window.jpg)
35+
36+
### Basic Details
37+
38+
Here, you can give a name and description to your watcher.
39+
40+
![Figure 3: Adding Name and Description of Watcher](https://devtron-public-asset.s3.us-east-2.amazonaws.com/images/resource-watcher/basic-details.gif)
41+
42+
### Namespaces to Watch
43+
44+
Here, you can select the [namespaces](../reference/glossary.md#namespace) whose [Kubernetes resource](../reference/glossary.md#objects) you wish to monitor for changes.
45+
46+
* You can watch the namespace(s) across **All Clusters** (existing and future).
47+
48+
![Figure 4: Choosing Namespaces of all Clusters](https://devtron-public-asset.s3.us-east-2.amazonaws.com/images/resource-watcher/all-cluster.gif)
49+
50+
* Or you can watch namespace(s) of **Specific Clusters**.
51+
52+
![Figure 5: Choosing Namespaces of Specific Clusters](https://devtron-public-asset.s3.us-east-2.amazonaws.com/images/resource-watcher/specific-cluster.gif)
53+
54+
{% hint style="info" %}
55+
In both the above options, if you choose 'Specific Namespaces', you can further decide whether to track the namespaces you enter (by clicking 'Include selections') or to track the namespaces except the ones you enter (by clicking 'Exclude selections').
56+
{% endhint %}
57+
58+
59+
### Intercept Change in Resources
60+
61+
Here, you can select the exact Kubernetes resource(s) you wish to track for changes (in the namespace(s) you selected in the previous step).
62+
63+
![Figure 6: Picking Resources to Track](https://devtron-public-asset.s3.us-east-2.amazonaws.com/images/resource-watcher/intercept-changes.gif)
64+
65+
* You can choose the resource from the **Resource kind(s) to watch** dropdown. Enter the Group/Version/Kind (GVK) if it's a custom resource definition (CRD), for e.g., `install.istio.io/v1apha1/IstioOperator`
66+
67+
* Choose the event type your watcher should listen to: `Created`, `Updated`, `Deleted`.
68+
69+
| Event Type | Description |
70+
| ---------- | ----------------------------------------------------------------------- |
71+
| Created | Triggers the watcher when your Kubernetes resource is created |
72+
| Updated | Triggers the watcher when your existing Kubernetes resource is modified |
73+
| Deleted | Triggers the watcher when your existing Kubernetes resource is deleted |
74+
75+
* Enter a [CEL expression](https://github.com/google/cel-spec/blob/master/doc/langdef.md) to catch a specific change in the resource's manifest.
76+
77+
{% hint style="info" %}
78+
* **If resource is created** - Use 'DEVTRON_FINAL_MANIFEST'
79+
* **If resource is updated** - Both 'DEVTRON_INITIAL_MANIFEST' and 'DEVTRON_FINAL_MANIFEST' can exist
80+
* **If resource is deleted** - Use 'DEVTRON_INITIAL_MANIFEST'
81+
{% endhint %}
82+
83+
**Example**: `DEVTRON_FINAL_MANIFEST.status.currentReplicas == DEVTRON_FINAL_MANIFEST.spec.maxReplicas`
84+
85+
### Execute Runbook
86+
87+
Here, you can choose a job that should trigger if your watcher intercepts any changes.
88+
89+
![Figure 7: Choosing a Job to Trigger](https://devtron-public-asset.s3.us-east-2.amazonaws.com/images/resource-watcher/execute-runbook.gif)
90+
91+
* Choose a job pipeline from the **Run Devtron Job pipeline** dropdown. If a pipeline is not selected, the watcher won't intercept matching resource changes even if your defined conditions are met.
92+
93+
* Select the environment in which the job should run. It can either be `devtron-ci` or the source environment (the intercepted namespace where the event has occurred).
94+
95+
* If the job expects input parameters, you may add its key and value under **Runtime input parameters**.
96+
97+
During a job's execution, its container can access the initial and final resource manifest through special environment variables. These variables are:
98+
* `DEVTRON_INITIAL_MANIFEST`
99+
* `DEVTRON_FINAL_MANIFEST`
100+
101+
* Click **Create Watcher**.
102+
103+
Your watcher is now ready to intercept the changes to the selected resources.
104+
105+
---
106+
107+
## Viewing Intercepted Changes
108+
109+
{% hint style="warning" %}
110+
### Who Can Perform This Action?
111+
Users need to have super-admin permission to view intercepted changes.
112+
{% endhint %}
113+
114+
### Details
115+
116+
This page allows you to view the changes to Kubernetes resources that you have selected for tracking changes.
117+
118+
![Figure 8: Intercepted Changes - Page](https://devtron-public-asset.s3.us-east-2.amazonaws.com/images/resource-watcher/intercepted-changes-page.jpg)
119+
120+
It comes with the following items to help you locate the resource, where the event has been intercepted:
121+
122+
* Searchbox
123+
* Cluster filter
124+
* Namespace filter
125+
* Action filter (event type, i.e., `Created`, `Updated`, `Deleted`)
126+
* Watcher filter (to check the intercepted changes of a specific watcher)
127+
128+
You get the following details in the results shown on the page.
129+
130+
|Field | Description |
131+
|-------|-------------|
132+
|[Change In Resource](#change-in-resource)|Describes the type of change to the Kubernetes resource along with a link to its manifest|
133+
|[Cluster/Namespace](#namespaces-to-watch) |Shows the cluster and namespace where the tracked Kubernetes resource belongs to|
134+
|Intercepted By |Shows the name of the watcher that intercepted the change|
135+
|Intercepted At |Shows the date and time when the event occurred |
136+
|[Job Execution](#execute-runbook) |Shows the status of the execution of job, e.g., `In Progress`, `Succeeded`, `Failed`|
137+
|[Logs](#job-execution-log) |Links to the job log, i.e, the `Run history` page of the job|
138+
139+
### Change in Resource
140+
141+
You can check the changes in manifest by clicking **View Manifest** in `Change In Resource` column.
142+
143+
![Figure 9a: Created Resource Manifest - Final Manifest](https://devtron-public-asset.s3.us-east-2.amazonaws.com/images/resource-watcher/view-manifest-v1.gif)
144+
145+
146+
![Figure 9b: Updated Resource - Initial and Final Manifest](https://devtron-public-asset.s3.us-east-2.amazonaws.com/images/resource-watcher/view-manifest-v2.gif)
147+
148+
149+
![Figure 9c: Deleted Resource - Initial Manifest](https://devtron-public-asset.s3.us-east-2.amazonaws.com/images/resource-watcher/view-manifest.gif)
150+
151+
### Job Execution Log
152+
153+
You can check the logs of the job executed when the Resource Watcher intercepts any change by clicking **logs**.
154+
155+
![Figure 10: Job Progress](https://devtron-public-asset.s3.us-east-2.amazonaws.com/images/resource-watcher/job-exec-log.gif)
156+
157+
---
158+
159+
## Use Cases
160+
161+
### Live Stream Traffic Surge
162+
163+
A live streaming sports application experiences a surge in viewers during a major game. The Horizontal Pod Autoscaler (HPA) might not be able to handle the unexpected traffic if it's capped at a low max replica count.
164+
165+
1. Create a watcher named 'Live Stream Scaling Alert'.
166+
2. Monitor updates to HPA resource in the application's namespace.
167+
3. When `currentReplicas` count reaches `maxReplicas`, trigger a job that contains the script to increase the replica count.
168+
169+
### Pod Health Monitoring
170+
171+
A stock trading application constantly updates stock prices for its traders. If the pods become unhealthy, traders might see incorrect stock prices leading to bad investments.
172+
173+
1. Create a watcher named 'Pod Health Monitor'.
174+
2. Track the pod workload of your application, if `DEVTRON_FINAL_MANIFEST.status.phase != 'Running'`, trigger a job that sends an Email/Slack alert with pod details.
175+

0 commit comments

Comments
 (0)