Skip to content

Commit

Permalink
Merge pull request #552 from Altinity/issue-458
Browse files Browse the repository at this point in the history
fix corner cases for UI alert time range
  • Loading branch information
Slach authored May 5, 2024
2 parents c993b67 + b9b00b7 commit 162c019
Show file tree
Hide file tree
Showing 3 changed files with 390 additions and 13 deletions.
339 changes: 339 additions & 0 deletions docker/grafana/dashboards/alert_from_and_to_macros_issue_458.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,339 @@
{
"annotations": {
"list": [
{
"builtIn": 1,
"datasource": {
"type": "grafana",
"uid": "-- Grafana --"
},
"enable": true,
"hide": true,
"iconColor": "rgba(0, 211, 255, 1)",
"name": "Annotations & Alerts",
"type": "dashboard"
}
]
},
"editable": true,
"fiscalYearStartMonth": 0,
"graphTooltip": 0,
"links": [],
"panels": [
{
"alert": {
"alertRuleTags": {},
"conditions": [
{
"evaluator": {
"params": [
0
],
"type": "gt"
},
"operator": {
"type": "and"
},
"query": {
"params": [
"A",
"15m",
"now"
]
},
"reducer": {
"params": [],
"type": "max"
},
"type": "query"
}
],
"executionErrorState": "alerting",
"for": "1m",
"frequency": "1m",
"handler": 1,
"name": "alert with $timeFilter macros",
"noDataState": "no_data",
"notifications": []
},
"datasource": {
"type": "vertamedia-clickhouse-datasource",
"uid": "P7E099F39B84EA795"
},
"description": "mage test build:linux && GF_UNIFIED_ALERTING_ENABLED=false GF_ALERTING_ENABLED=true npm run server\nhttps://github.com/Altinity/clickhouse-grafana/issues/458",
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisBorderShow": false,
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "",
"axisPlacement": "auto",
"barAlignment": 0,
"drawStyle": "line",
"fillOpacity": 0,
"gradientMode": "none",
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"insertNulls": false,
"lineInterpolation": "linear",
"lineWidth": 1,
"pointSize": 5,
"scaleDistribution": {
"type": "linear"
},
"showPoints": "auto",
"spanNulls": false,
"stacking": {
"group": "A",
"mode": "none"
},
"thresholdsStyle": {
"mode": "off"
}
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green"
},
{
"color": "red",
"value": 80
}
]
}
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 12,
"x": 0,
"y": 0
},
"id": 1,
"options": {
"legend": {
"calcs": [],
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"mode": "single",
"sort": "none"
}
},
"targets": [
{
"add_metadata": false,
"database": "default",
"datasource": {
"type": "vertamedia-clickhouse-datasource",
"uid": "P7E099F39B84EA795"
},
"dateColDataType": "EventDate",
"dateTimeColDataType": "EventTime",
"dateTimeType": "DATETIME",
"editorMode": "builder",
"extrapolate": true,
"format": "time_series",
"formattedQuery": "/* UI alerts with `timeFilter` */ SELECT $timeSeries as t, count() FROM $table WHERE $timeFilter GROUP BY t ORDER BY t",
"interval": "",
"intervalFactor": 1,
"query": "/* UI alerts with `timeFilter` */ SELECT $timeSeries as t, count() FROM $table WHERE $timeFilter GROUP BY t ORDER BY t",
"rawQuery": "/* UI alerts with `timeFilter` */\nSELECT (intDiv(toUInt32(EventTime), 15) * 15) * 1000 as t, count() FROM default.test_alerts WHERE EventTime >= toDateTime(1714858479) AND EventTime <= toDateTime(1714880079) GROUP BY t ORDER BY t",
"refId": "A",
"round": "0s",
"skip_comments": true,
"table": "test_alerts"
}
],
"thresholds": [
{
"colorMode": "critical",
"op": "gt",
"value": 0,
"visible": true
}
],
"title": "alert with timeFilter macro",
"type": "timeseries"
},
{
"alert": {
"alertRuleTags": {},
"conditions": [
{
"evaluator": {
"params": [
0
],
"type": "gt"
},
"operator": {
"type": "and"
},
"query": {
"params": [
"A",
"15m",
"now"
]
},
"reducer": {
"params": [],
"type": "max"
},
"type": "query"
}
],
"executionErrorState": "alerting",
"for": "1m",
"frequency": "1m",
"handler": 1,
"name": "alert with from and to macro alert",
"noDataState": "no_data",
"notifications": []
},
"datasource": {
"type": "vertamedia-clickhouse-datasource",
"uid": "P7E099F39B84EA795"
},
"description": "https://github.com/Altinity/clickhouse-grafana/issues/458",
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisBorderShow": false,
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "",
"axisPlacement": "auto",
"barAlignment": 0,
"drawStyle": "line",
"fillOpacity": 0,
"gradientMode": "none",
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"insertNulls": false,
"lineInterpolation": "linear",
"lineWidth": 1,
"pointSize": 5,
"scaleDistribution": {
"type": "linear"
},
"showPoints": "auto",
"spanNulls": false,
"stacking": {
"group": "A",
"mode": "none"
},
"thresholdsStyle": {
"mode": "off"
}
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "red",
"value": 80
}
]
}
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 12,
"x": 12,
"y": 0
},
"id": 2,
"options": {
"legend": {
"calcs": [],
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"mode": "single",
"sort": "none"
}
},
"targets": [
{
"add_metadata": false,
"database": "default",
"datasource": {
"type": "vertamedia-clickhouse-datasource",
"uid": "P7E099F39B84EA795"
},
"dateColDataType": "EventDate",
"dateTimeColDataType": "EventTime",
"dateTimeType": "DATETIME",
"editorMode": "builder",
"extrapolate": true,
"format": "time_series",
"formattedQuery": "/* UI alerts with `from` and `to` */ SELECT $timeSeries as t, count() FROM $table WHERE $timeFilter GROUP BY t ORDER BY t",
"interval": "15s",
"intervalFactor": 1,
"query": "/* UI alerts with `from` and `to` */ SELECT $timeSeries as t, count() FROM $table WHERE EventTime>=$from AND EventTime<=$to GROUP BY t ORDER BY t",
"rawQuery": "/* UI alerts with `from` and `to` */ SELECT (intDiv(toUInt32(EventTime), 15) * 15) * 1000 as t, count() FROM default.test_alerts WHERE EventTime >= 1714858479 AND EventTime <= 1714880079 GROUP BY t ORDER BY t",
"refId": "A",
"round": "0s",
"showFormattedSQL": true,
"skip_comments": true,
"table": "test_alerts"
}
],
"thresholds": [
{
"colorMode": "critical",
"op": "gt",
"value": 0,
"visible": true
}
],
"title": "alert with from and to macro",
"type": "timeseries"
}
],
"schemaVersion": 39,
"tags": [],
"templating": {
"list": []
},
"time": {
"from": "now-6h",
"to": "now"
},
"timepicker": {},
"timezone": "browser",
"title": "alerts from and to from UI issue-458",
"uid": "issue_458_alert_time_range_from_ui",
"version": 1,
"weekStart": ""
}
2 changes: 1 addition & 1 deletion pkg/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (ds *ClickHouseDatasource) QueryData(
}
jsonErr := json.Unmarshal(query.JSON, &q)
if jsonErr != nil {
return onErr(fmt.Errorf("unable to parse json %s into Query struct Error: %w", query.JSON, jsonErr))
return onErr(fmt.Errorf("unable to parse json, to Query error: %v, to EvalQuery error: %v, source JSON: %s", jsonErr, evalJsonErr, query.JSON))
}
wg.Go(func() error {
response.Responses[q.RefId] = ds.executeQuery(req.PluginContext, wgCtx, &q)
Expand Down
Loading

0 comments on commit 162c019

Please sign in to comment.