@@ -255,6 +255,8 @@ ipcMain.on(
255
255
) ;
256
256
257
257
// 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 :)
258
260
/**
259
261
* @event eksMetricsRequest
260
262
* @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:
266
268
const fileContents = JSON . parse ( fs . readFileSync ( settingsLocation , 'utf8' ) ) ;
267
269
const userAwsService = fileContents [ username ] ?. services [ appIndex ] ;
268
270
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.
269
278
270
279
const url = `${ awsUrl } /api/search?folderIds=0`
271
- console . log ( "hi" )
272
- const response = await fetch ( url , {
280
+
281
+ fetch ( url , {
273
282
method : 'GET' ,
274
283
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 } )
280
300
} ) ;
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));
286
316
} ) ;
0 commit comments