Skip to content

Commit 88d6a65

Browse files
committed
updating eksMetricsRequest again
1 parent 9ded85f commit 88d6a65

File tree

1 file changed

+42
-12
lines changed

1 file changed

+42
-12
lines changed

electron/routes/cloudbased.ts

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,8 @@ ipcMain.on(
255255
);
256256

257257
// v10 notes: Has not been reconfigured to refer to User database yet, only works for guest.
258+
// We tried dynamically pulling the grafana dashboard with just the AWS cluster URL, but did not complete it in the allotted time...
259+
// If future teams could get it rendering dynamically that would be awesome :)
258260
/**
259261
* @event eksMetricsRequest
260262
* @desc Connects user to Cloudwatch using aws-sdk and fetches data for ECS Clusters/Services
@@ -266,21 +268,49 @@ ipcMain.on('eksMetricsRequest', async (message:Electron.IpcMainEvent, username:
266268
const fileContents = JSON.parse(fs.readFileSync(settingsLocation, 'utf8'));
267269
const userAwsService = fileContents[username]?.services[appIndex];
268270
const [typeOfService, region, awsUrl, token] = [userAwsService[4], userAwsService[2], userAwsService[9], userAwsService[7]];
271+
// awsURL -> the input is actually the Grafana Dashboard URL you receive after exporting the external hostname
272+
// of the Kubernetes Service in the Grafana Namespace (see step 3 of the AWS/EKS readme)
273+
// token -> is the Bearer Token which must be generated by the admin in Grafana to use the Grafana Dashboard API.
274+
275+
// build the url for the GET request to the Grafana Dashboard with the Grafana URL. This will find the available dashboard
276+
// and return the dashboard data -> we want the completed dashboard URL which will be sent in the response to the front end
277+
// and pulled into the Grafana Iframe Component to render the graph.
269278

270279
const url = `${awsUrl}/api/search?folderIds=0`
271-
console.log("hi")
272-
const response = await fetch(url, {
280+
281+
fetch(url, {
273282
method: 'GET',
274283
headers: {
275-
"Access-Control-Allow-Origin": "*",
276-
Accept: "application/json",
277-
"Content-Type": "application/json",
278-
Authorization: `Bearer ${token}`,
279-
},
284+
'Content-Type': 'application/json',
285+
'Accept': 'application/json',
286+
'Authorization': `Bearer ${token}`,
287+
}
288+
})
289+
.then((response) => response.json())
290+
.then((data)=> {
291+
console.log('received data:', data);
292+
const appendToUrl = data[0].url;
293+
console.log(appendToUrl);
294+
const dashboardURL = `${awsUrl}${appendToUrl}`;
295+
console.log(dashboardURL);
296+
message.sender.send('eksMetricsResponse', JSON.stringify(dashboardURL));
297+
})
298+
.catch((err) => {
299+
console.log({err: 'error in grafana GET ' + err})
280300
});
281-
log.info(response);
282-
const data = await response.json();
283-
console.log(data)
284-
console.log(awsUrl)
285-
message.sender.send('eksMetricsResponse', JSON.stringify(data));
301+
302+
// const response = await fetch(url, {
303+
// method: 'GET',
304+
// headers: {
305+
// "Access-Control-Allow-Origin": "*",
306+
// Accept: "application/json",
307+
// "Content-Type": "application/json",
308+
// Authorization: `Bearer ${token}`,
309+
// },
310+
// });
311+
// log.info(response);
312+
// const data = await response.json();
313+
// console.log(data)
314+
// console.log(awsUrl)
315+
// message.sender.send('eksMetricsResponse', JSON.stringify(data));
286316
});

0 commit comments

Comments
 (0)