Skip to content

Commit e1700af

Browse files
committed
add grafana api dynamically
1 parent cff5d70 commit e1700af

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

chronos_npm_package/controllers/mongo.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,7 @@ mongo.setQueryOnInterval = async config => {
863863
// });
864864
let allMetrics = await model.find({});
865865
console.log('allMetrics.length: ', allMetrics.length);
866-
console.log("🟡🟡🟡🟡🟡🟡🟡🟡🟡🟡🟡🟡🟡🟡🟡🟡🟡🟡🟡🟡🟡🟡🟡🟡🟡🟡🟡 start creating dashboards 🟡🟡🟡🟡🟡🟡🟡🟡🟡🟡🟡🟡🟡🟡🟡🟡🟡🟡🟡🟡🟡🟡🟡🟡🟡🟡🟡")
866+
console.log("🟡 🟡 🟡 🟡 🟡 🟡 🟡 🟡 🟡 🟡 🟡 🟡 🟡 🟡 🟡 🟡 🟡 start creating dashboards 🟡 🟡 🟡 🟡 🟡 🟡 🟡 🟡 🟡 🟡 🟡 🟡 🟡 🟡 🟡 🟡 🟡")
867867
await mongo.createGrafanaDashboards(config, allMetrics);
868868
console.log("✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ finish creating dashboards ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅")
869869
})
@@ -919,15 +919,15 @@ mongo.createGrafanaDashboards = async (config, parsedArray) => {
919919
try {
920920
console.log('In mongo.createGrafanaDashboards!!!')
921921
console.log('Calling utilities.getGrafanaDatasource()');
922-
const datasource = await utilities.getGrafanaDatasource();
922+
const datasource = await utilities.getGrafanaDatasource(config.grafanaAPIKey);
923923
//console.log('Calling utilities.promMetricsQuery()');
924924
//const parsedArray = await utilities.promMetricsQuery(config);
925925
//const datasource = await utilities.getGrafanaDatasource();
926926
// console.log("parsedArray is: ", parsedArray.slice(0, 5));
927927
// console.log('parsedArray.length is: ', parsedArray.length);
928928
for (let metric of parsedArray) {
929929
console.log(`🎉 creating dashboard 🎉`);
930-
await utilities.createGrafanaDashboard(metric, datasource, "timeseries");
930+
await utilities.createGrafanaDashboard(metric, datasource, "timeseries", config.grafanaAPIKey);
931931
}
932932

933933
// await parsedArray.forEach(async (metric, i) => {

chronos_npm_package/controllers/utilities.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,8 @@ const helpers = {
306306
createGrafanaDashboard: async (
307307
metric,
308308
datasource,
309-
graphType
309+
graphType,
310+
token
310311
) => {
311312
let uid = metric.metric.replace(/.*\/.*\//g, '')
312313
if (metric.metric.replace(/.*\/.*\//g, '').length >= 40) {
@@ -343,7 +344,7 @@ const helpers = {
343344
{
344345
headers: {
345346
'Content-Type': 'application/json',
346-
'Authorization': 'Bearer glsa_FZQR8XW4ouUyK95YgCG1bwFS6NomoqXA_546c1dc5'
347+
'Authorization': token
347348
},
348349
}
349350
);
@@ -363,14 +364,14 @@ const helpers = {
363364
}
364365
},
365366

366-
getGrafanaDatasource: async () => {
367+
getGrafanaDatasource: async (token) => {
367368
// Fetch datasource information from grafana API.
368369
// This datasource is PRECONFIGURED on launch using grafana config.
369370
console.log('In utilities.getGrafanaDatasource!!!');
370371
const datasourceResponse = await axios.get('http://grafana:3000/api/datasources', {
371372
headers: {
372373
'Content-Type': 'application/json',
373-
'Authorization': 'Bearer glsa_FZQR8XW4ouUyK95YgCG1bwFS6NomoqXA_546c1dc5'
374+
'Authorization': token
374375
},
375376
});
376377
console.log("Successfully fetched datasource from Grafana API")

electron/routes/dataHelpers.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const mongoFetch = async (
3535
try {
3636
const testModel = HealthModelFunc(serviceName);
3737
const grafanaAPIKey = await GrafanaAPIKeyModel.find({});
38+
console.log('grafanaAPIKey: ', grafanaAPIKey)
3839
let result = await testModel.aggregate(aggregator);
3940
for (let i = 0; i < result.length; i++) {
4041
result[i].token = grafanaAPIKey[0].token;

examples/kubernetes/server/chronos-config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,7 @@ module.exports = {
2424
URI: process.env.CHRONOS_URI,
2525
},
2626

27+
grafanaAPIKey: process.env.CHRONOS_GRAFANA_API_KEY,
28+
2729
notifications: [],
2830
}

0 commit comments

Comments
 (0)