Skip to content

Commit cff83d3

Browse files
author
Mattia Moretti
authored
Enable alerting (#268)
* enable it * minor fix * onChange({ ...changedQuery }); logical fix * initial documentation * unsupported features * ready * cleaning
1 parent 4149ad2 commit cff83d3

11 files changed

+46
-39
lines changed

docs/images/Error-Alert-Label.png

32.5 KB
Loading

docs/images/WithCustomDropDown.png

-412 KB
Binary file not shown.

docs/images/alert-label.png

32.9 KB
Loading

docs/images/alert-nolabel.png

35.5 KB
Loading
41.9 KB
Loading
-424 KB
Binary file not shown.
-396 KB
Binary file not shown.

docs/using.md

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -204,32 +204,6 @@ Label(appears as the display name of the variable selected).
204204
Custom variables provide the convenience of using custom intervals for your dashboard. Please note the accepted format for intervals are within squared brackets and must include the time unit (for example [5m] to specify 5 minutes or [2h] for two hours). Following is an example of interval template variable definition:
205205
![Template variable for interval](images/Interval-Template-Var.png)
206206

207-
208-
### Windows and Resolution
209-
210-
For windows and resolution, you can use a custom or constant variable. To create a custom, select the variable type as custom.
211-
Label(appears as the display name of the variable selected)
212-
213-
Custom variables provide the convenience of selecting a value out of many values. Try replicating the data in the following screenshots for window and resolution.
214-
215-
Custom window variable
216-
![Custom variable for window](images/customWIndowVariableCreation.png)
217-
218-
219-
Custom resolution variable
220-
![Custom variable for resolution](images/customResolution%20variable%20creation.png)
221-
222-
Choose the save button to save your dashboard! DO NOT FORGET
223-
224-
225-
226-
Now, on the top of the panel, you would see windowLabel and resolutionLabel
227-
You can select the value for the variables from here and use them in
228-
the dropdowns window and resolution below the panel
229-
230-
![Custom variable window dropdown](images/WithCustomDropDown.png)
231-
232-
In case the plugin is configured to operate with multitenancy support, please make sure you are selecting **region** before **tenancy** and all the other dropdowns.
233207

234208

235209
### Dimensions
@@ -345,3 +319,44 @@ If the user selects a time range
345319
2. Less than or equal to 30 days and more than 7 days -> window will be 5m and resolution will be 5 min.
346320
3. More than 30 days -> a window will be 1h and resolution will be 1 h
347321

322+
## Alerting
323+
Version 5.5 of the metrics plugin introduces the Alerting capability.
324+
For detailed instruction how to work with alerts in Grafana, you may reference to the official documentation available at [Grafana Alerting](https://grafana.com/docs/grafana/latest/alerting/) web page.
325+
326+
The overall procedure is like the following (in Grafana 10):
327+
1. Open the dashboard you created earlier
328+
2. Edit any existing panel.
329+
3. Click on the Alert tab underneath the panel.
330+
4. Click on Create alert rule from this panel button.
331+
5. In Expressions section, in the Threshold expression C, set the threshold
332+
6. Click on Set as alert condition on Threshold expression C. Your alert should now look as follows:
333+
![Alert Threshold](images/create-alert-expression.png)
334+
Expression section showing B "reduce" with Input: A, Function: Last, Mode: Strict, C Threshold with Input: B, Is Above: 15 and Alert Condition enabled indicator
335+
Expression section showing B "reduce" with Input: A, Function: Last, Mode: Strict, C Threshold with Input: B, Is Above: 15 and Alert Condition enabled indicator
336+
7. In Set alert evaluation behavior section, click on New folder button and create a new folder to store an evaluation rule.
337+
8. Then, click on New evaluation group button and create a new evaluation group; choose a name and set the Evaluation interval.
338+
9. Click Save rule and exit button.
339+
10. Save the dashboard.
340+
341+
After some time the alert rule evaluates and transitions into Alerting state.
342+
343+
### Known limitations with Alerts
344+
#### Custom Label is incompatible with alert definition
345+
Please note that Alerting is **not** compatible with custom label function. That means you must remove any custom label in the alert definition window, if any. custom labels can stay in the panels and dashboards, must be removed only in alert definition window.
346+
If you try to set up an alert with some custom label, you will see this error:
347+
![Alert Label Error](images/Error-Alert-Label.png)
348+
349+
Therefore, if you have a panel which is using custom label, you will see an entry like this one when setting alert:
350+
![Alert Label Error](images/alert-nolabel.png)
351+
352+
Make sure to modify this alert setup removing the Legend Format entry like the following:
353+
![Alert Label Error](images/alert-label.png)
354+
355+
You do not need to remove Custom Label in the Panel. Only in the alert definition you must remove it.
356+
357+
#### Alerts and AUTO interval setting
358+
If you are setting up an alert from a panel which uses Auto Interval, this interval will always revert to 1 minute ([1m]). Auto intervals based on Time Range are not supported in alert setting.
359+
360+
#### Alerts and Template vars
361+
Template variables are not supported in alerts. If you are setting up an alert from a panel which uses template vars, the alert will take the last chosen values.
362+
Alert setting from panels which are using template variables in raw mode in is not supported. In that case you must rewrite your MQL statement when defyning the alert using explicit expressions without template vars.

src/QueryEditor.tsx

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,24 +42,17 @@ export const QueryEditor: React.FC<Props> = (props) => {
4242
if (runQuery) {
4343
const queryModel = new QueryModel(changedQuery, getTemplateSrv());
4444

45-
// for metrics
46-
if (datasource.isVariable(String(changedQuery.metric))) {
47-
let { [String(changedQuery.metric)]: var_metric } = datasource.interpolateProps({ [String(changedQuery.metric)]: changedQuery.metric });
48-
if (var_metric !== "" && var_metric !== QueryPlaceholder.Metric) {
49-
changedQuery.metric = var_metric
50-
}
51-
}
45+
onChange({ ...changedQuery });
46+
5247
if (queryModel.isQueryReady()) {
53-
5448
if (changedQuery.rawQuery === false){
5549
changedQuery.queryText = queryModel.buildQuery(String(changedQuery.queryTextRaw));
5650
} else {
5751
changedQuery.queryText = queryModel.buildQuery(String(changedQuery.metric));
5852
}
59-
60-
onChange({ ...changedQuery });
6153
onRunQuery();
6254
}
55+
6356
} else {
6457
onChange({ ...changedQuery });
6558
}
@@ -409,7 +402,6 @@ export const QueryEditor: React.FC<Props> = (props) => {
409402
const onResourceGroupChange = (data: any) => {
410403
let mn: string[] = data.value;
411404
setResourceGroupValue(data);
412-
413405
onApplyQueryChange({ ...query, resourcegroup: data.label, metricNames: mn, metric: undefined }, false);
414406
};
415407

src/plugin.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"type": "datasource",
55
"metrics": true,
66
"annotations": false,
7-
"alerting": false,
7+
"alerting": true,
88
"backend": true,
99
"executable": "oci-metrics-plugin",
1010
"info": {

0 commit comments

Comments
 (0)