Skip to content

Commit dbf73f4

Browse files
committed
Create 404 page, more API calls, comment out x axis for now
1 parent a3f561a commit dbf73f4

File tree

5 files changed

+91
-23
lines changed

5 files changed

+91
-23
lines changed

client/src/components/NotFound.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default class NotFound extends React.Component<{}> {
1111
justify = "center"
1212
style={{
1313
position: 'absolute',
14-
top: '30%',
14+
top: '35%',
1515
}}>
1616
<Grid item xs={12} md={12} lg={12}>
1717
<Typography align="center" variant="h1">404 Error</Typography>

client/src/components/ScaleControllerDashboard/ScaleControllerDashboard.tsx

+15
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,21 @@ export default class ScaleControllerDashboard extends React.Component<ScaleContr
2020
};
2121
}
2222

23+
private async getLogs() {
24+
let pod = await fetch('/api/keda/pod')
25+
.then(res => res.json())
26+
.then(({ items }) => {
27+
if (items.length > 0) {
28+
return items[0];
29+
}});
30+
31+
await fetch(`/api/namespace/${pod.metadata.namespace}/pods/${pod.metadata.name}/logs`)
32+
.then(res => res.text())
33+
.then(logs => this.formatLogs(logs))
34+
.then(logArray => this.setState({ logs: logArray }));
35+
36+
}
37+
2338
formatLogs(text: string) {
2439
let logs = text.split("\n");
2540
let scaleControllerLogs: LogModel[] = [];

client/src/components/ScaledObjectDashboard/ReplicaDisplay.tsx

+14-22
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@ import React from 'react';
22
import { Typography, Paper, Box } from '@material-ui/core';
33
import { ResponsiveBar } from '@nivo/bar';
44

5-
export default class ReplicaDisplay extends React.Component<{scaledObjectName: string, namespace:string}, {currentReplicas: number,
6-
dataset: {[key: string]: any}[], logs: string}> {
5+
export default class ReplicaDisplay extends React.Component<{scaledObjectName: string, namespace:string}, {dataset: {[key: string]: any}[], logs: string}> {
76
private numBarsInGraph:number = 100;
87

98
constructor(props: {scaledObjectName: string, namespace:string}) {
109
super(props);
1110

1211
this.state = {
13-
currentReplicas: 0,
1412
dataset: [],
1513
logs: ""
1614
}
@@ -74,15 +72,6 @@ export default class ReplicaDisplay extends React.Component<{scaledObjectName: s
7472

7573
componentWillUnmount() {
7674
}
77-
78-
async getCurrentReplicaCount() {
79-
await fetch(`/api/namespace/${this.props.namespace}/deployment/${this.props.scaledObjectName}`)
80-
.then(res => res.json())
81-
.then((data) => {
82-
let currentReplicas = (data.spec!.replicas === undefined) ? 0:data.spec!.replicas;
83-
this.setState({currentReplicas: currentReplicas });
84-
});
85-
}
8675

8776
render() {
8877

@@ -95,20 +84,23 @@ export default class ReplicaDisplay extends React.Component<{scaledObjectName: s
9584
data={this.state.dataset}
9685
keys={[this.props.scaledObjectName]}
9786
indexBy="timestamp"
98-
margin={{ top: 20, right: 0, bottom: 120, left: 20 }}
87+
margin={{ top: 20, right: 0, bottom: 20, left: 20 }}
9988
padding={0.3}
10089
colors={{ scheme: 'paired' }}
10190
axisTop={null}
10291
axisRight={null}
103-
axisBottom={{
104-
tickSize: 5,
105-
tickPadding: 5,
106-
tickRotation: 32,
107-
tickValues: 1,
108-
legend: 'timestamp',
109-
legendPosition: 'middle',
110-
legendOffset: 92.
111-
}}
92+
axisBottom={
93+
// {
94+
// tickSize: 5,
95+
// tickPadding: 5,
96+
// tickRotation: 32,
97+
// tickValues: 10,
98+
// legend: 'timestamp',
99+
// legendPosition: 'middle',
100+
// legendOffset: 92
101+
// }
102+
null
103+
}
112104
axisLeft={{
113105
tickSize: 5,
114106
tickPadding: 0,

client/src/components/ScaledObjectDashboard/ScaledObjectDetailsDashboard.tsx

+14
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,20 @@ export default class ScaledObjectDetailsDashboard extends React.Component<Scaled
4949
return roundedTimestamp;
5050
}
5151

52+
private async getLogs() {
53+
let pod = await fetch('/api/keda/pod')
54+
.then(res => res.json())
55+
.then(({ items }) => {
56+
if (items.length > 0) {
57+
return items[0];
58+
}});
59+
60+
await fetch(`/api/namespace/${pod.metadata.namespace}/pods/${pod.metadata.name}/logs`)
61+
.then(res => res.text())
62+
.then(logs => this.formatLogs(logs, pod.metadata.name, pod.metadata.namespace))
63+
64+
}
65+
5266
private formatLogs(text: string, name: string, namespace: string) {
5367
let logs = text.split("\n");
5468
let scaledObjectLogs: LogModel[] = [];

server/src/apis.ts

+47
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,33 @@ export function setupApis(app: Express) {
116116
res.send(jsonStr);
117117
});
118118

119+
app.get(`/api/namespace/:namespace/pods/:name/logs`, async (req, res) => {
120+
let namespace = req.params.namespace;
121+
let name = req.params.name;
122+
123+
if (!namespace) {
124+
namespace = 'default';
125+
}
126+
127+
const cluster = kc.getCurrentCluster();
128+
if (!cluster) {
129+
res.status(501).json({
130+
error: 'cluster not found'
131+
});
132+
return;
133+
}
134+
135+
const opts: request.Options = {
136+
url: `${cluster.server}/api/v1/namespaces/${namespace}/pods/${name}/log?tailLines=300`
137+
};
138+
kc.applyToRequest(opts);
139+
const jsonStr = await request.get(opts);
140+
141+
res.setHeader('Content-Type', 'application/json');
142+
res.send(jsonStr);
143+
});
144+
145+
119146
app.get('/api/keda', async (req, res) => {
120147
const cluster = kc.getCurrentCluster();
121148

@@ -135,6 +162,26 @@ export function setupApis(app: Express) {
135162
res.send(jsonStr);
136163
});
137164

165+
app.get('/api/keda/pod', async (req, res) => {
166+
const cluster = kc.getCurrentCluster();
167+
168+
if (!cluster) {
169+
res.status(501).json({
170+
error: 'cluster not found'
171+
});
172+
return;
173+
}
174+
175+
const opts: request.Options = {
176+
url: `${cluster.server}/api/v1/namespaces/keda/pods?labelSelector=app%3Dkeda-operator`
177+
};
178+
kc.applyToRequest(opts);
179+
let pod = await request.get(opts);
180+
181+
res.setHeader('Content-Type', 'application/json');
182+
res.send(pod);
183+
});
184+
138185
app.get('/api/logs', async (req, res) => {
139186
const cluster = kc.getCurrentCluster();
140187

0 commit comments

Comments
 (0)