Problems using Prometheus as datasource
Closed this issue · 1 comments
vchurkin commented
Hey, I've tried to use dsl for prometheus, but faced several issues when building first graph panel of my dashboard.
Here's the DSL I was trying to use with issues described in comments:
dashboard(title = "...") {
...
panels {
graphPanel(title = "Sandbox simulations") {
...
metrics(object : Datasource { // ISSUE 1: datasource name is set by admin, why PromQL is predefined?
override fun asDatasourceName() = "Prometheus"
}) {
prometheusMetric("ERROR - {{ step }} - {{ namespace }}") {
//ISSUE 2: can't set refId for prometheus metric
rangeVector(
metricName = "sandbox_simulation_counter_total",
labels = mapOf("status" to "ERROR"),
interval = "1m"
).increase().sum(by = listOf("namespace", "step"))
}
}
alert("Sandbox simulations alert") {
conditions {
max(AlertQuery(
// ISSUE 3: don't need metric field, but it's nonnull
metric = object : DashboardMetric {
override fun toJson(): JSONObject {
return JSONObject()
}
},
// ISSUE 4: why can't set params with dsl properly?
params = *arrayOf("A", "1m", "now")
).isAbove(0))
}
notificationIds.add(1) // ISSUE 5: can't use uid for notification channels, they are more convenient to use than id-s
}
}
}
}
Here ISSUE 2 is a blocker, because I can't set up alert without refId. All the other issues have workarounds here in the code, but should be fixed in my opinion too.
To clarify issues 3-5 about alerts, I can give you an example of working alert JSON representation that I need to be generated:
"alert": {
"alertRuleTags": {},
"conditions": [
{
"evaluator": {
"params": [
0
],
"type": "gt"
},
"operator": {
"type": "and"
},
"query": {
"params": [
"B",
"1m",
"now"
]
},
"reducer": {
"params": [],
"type": "max"
},
"type": "query"
}
],
"executionErrorState": "alerting",
"for": "0m",
"frequency": "1m",
"handler": 1,
"message": "",
"name": "Sandbox simulations alert",
"noDataState": "ok",
"notifications": [
{
"uid": "1MIp76yGk"
}
]
}