Skip to content

Commit

Permalink
Add Loki template support
Browse files Browse the repository at this point in the history
  • Loading branch information
hifi committed Sep 15, 2023
1 parent c60dfca commit 4b6dceb
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,25 @@ const utils = {

if(data.annotations.hasOwnProperty("logs_url")) {
logs_url = data.annotations.logs_url;
} else if (data.annotations.hasOwnProperty("logs_template")) {
const now = new Date().getTime();
const range_ms = (parseInt(data.annotations.logs_minutes) || 15) * 60 * 1000;

const left = {
"datasource": data.annotations.logs_datasource || "Loki Core",
"queries": [{
"refId": "A",
"expr": data.annotations.logs_template.replace(/\$([a-z0-9_]+)/g, function(_, label) {
return data.labels[label] || "";
}),
}],
"range": {
"from": (now - range_ms) + "",
"to": now + "",
},
};

logs_url = process.env.GRAFANA_URL + "/explore?orgId=1&left=" + encodeURIComponent(JSON.stringify(left));
}

if (process.env.ALERTMANAGER_URL != "") {
Expand Down

0 comments on commit 4b6dceb

Please sign in to comment.