Skip to content

Commit 7011d54

Browse files
authored
Merge pull request #20 from oslabs-beta/elena/testingEKS
Elena/testing eks
2 parents 6970466 + fbbfadb commit 7011d54

File tree

4 files changed

+67
-28
lines changed

4 files changed

+67
-28
lines changed

app/containers/AWSGraphsContainer.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,7 @@ const AwsGraphsContainer: React.FC = React.memo(props => {
125125
)}
126126
{typeOfService === 'AWS/EKS' && (
127127
<div>
128-
{/* <iframe src={`${awsUrl}/d/8jYcvsBVz/kubernetes-cluster-monitoring-via-prometheus?orgId=1&refresh=10s&theme=light&kiosk`} width="1300" height="1300" ></iframe> */}
129-
{/* <iframe src={`${awsUrl}/d/jPEGwyfVk/opencost?orgId=1&theme=light&kiosk`} width="1300" height="1300" ></iframe> */}
130-
131-
<iframe src={`http://a9921cff905094aa0a45e6e330684283-98913978.us-east-2.elb.amazonaws.com/d/8jYcvsBVz/kubernetes-cluster-monitoring-via-prometheus?orgId=1&refresh=10s&theme=light&kiosk`} width="1300" height="1300" ></iframe>
132-
<iframe src={`http://a9921cff905094aa0a45e6e330684283-98913978.us-east-2.elb.amazonaws.com/d/jPEGwyfVk/opencost?orgId=1&theme=light&kiosk`} width="1300" height="1300" ></iframe>
133-
134-
{/* <GrafanaIFrame {...awsAppInfo}/> */}
128+
<iframe src={`${awsEksData}?orgId=1&refresh=10s&theme=light&kiosk`} width="1300" height="1300" ></iframe>
135129
</div>
136130
)}
137131
</div>

app/modals/AwsModal.tsx

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,20 +127,20 @@ const AwsModal: React.FC<AddModalProps> = React.memo(({ setOpen }) => {
127127
</select>
128128
</div>
129129
<div>
130-
<label htmlFor="aws-access-key">
131-
Access Key<span>*</span>
130+
<label htmlFor="aws-access-key">{(typeOfService === 'AWS/EKS') ? 'Bearer Token' : 'Access Key'} <span>*</span>
132131
</label>
133132
<input
134133
id="aws-access-key"
135134
type="password"
136135
name="accessKey"
137136
value={accessKey}
138137
onChange={e => handleChange(e)}
139-
placeholder="AWS Access Key"
138+
placeholder={typeOfService === 'AWS/EKS' ? 'Grafana Bearer Token' : 'AWS Access Key'}
140139
required
141140
/>
142141
</div>
143-
<div>
142+
{(typeOfService !== 'AWS/EKS') && (
143+
<div>
144144
<label htmlFor="aws-secret-access-key">
145145
Secret Access Key<span>*</span>
146146
</label>
@@ -154,18 +154,33 @@ const AwsModal: React.FC<AddModalProps> = React.memo(({ setOpen }) => {
154154
required
155155
/>
156156
</div>
157+
)}
158+
{/* <div>
159+
<label htmlFor="aws-secret-access-key">
160+
Secret Access Key<span>*</span>
161+
</label>
162+
<input
163+
id="aws-secret-access-key"
164+
type="password"
165+
name="secretAccessKey"
166+
value={secretAccessKey}
167+
onChange={e => handleChange(e)}
168+
placeholder="AWS Secret Access Key"
169+
required
170+
/>
171+
</div> */}
172+
157173
<div>
158174
<label htmlFor="aws-url">
159-
Cluster URL<span>*</span>
175+
{(typeOfService === 'AWS/EKS') ? 'Grafana URL' : 'Access Key'}<span>*</span>
160176
</label>
161177
<input
162178
id="aws-url"
163179
type="string"
164180
name="awsUrl"
165181
value={awsUrl}
166182
onChange={e => handleChange(e)}
167-
placeholder="AWS Url"
168-
required
183+
placeholder={typeOfService === 'AWS/EKS'? 'Grafana Provided URL': 'AWS Url'}
169184
/>
170185
</div>
171186
<div>

electron/routes/cloudbased.ts

Lines changed: 43 additions & 13 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
@@ -265,22 +267,50 @@ ipcMain.on(
265267
ipcMain.on('eksMetricsRequest', async (message:Electron.IpcMainEvent, username: string, appIndex: number) => {
266268
const fileContents = JSON.parse(fs.readFileSync(settingsLocation, 'utf8'));
267269
const userAwsService = fileContents[username]?.services[appIndex];
268-
const [typeOfService, region, awsUrl] = [userAwsService[4], userAwsService[2], userAwsService[9]];
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.
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 eyJrIjoiamN4UGRKVHg3cUQyZ201N042NW41bHg5bGhJaVFlaFciLCJuIjoidGVzdEtleSIsImlkIjoxfQ=='
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
});

examples/AWS/AWS-EKS/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ This process can also be done using the AWS Command Line Interface (CLI) or the
128128
--values grafana.yaml \
129129
--set service.type=LoadBalancer
130130

131-
3. Execute these commands to get the URL. Login in with the username admin and the password EKS!sAWsome
131+
3. Execute these commands to get the URL. Login in with the username admin and the password EKS!sAWsome. The URL received after exporting the external hostname (from the command below) will be used to render the graphs in Electron.
132132

133133
export ELB=$(kubectl get svc -n grafana grafana -o jsonpath='{.status.loadBalancer.ingress[0].hostname}')
134134
echo "http://$ELB"

0 commit comments

Comments
 (0)