Skip to content

Commit 5332403

Browse files
committed
Event chart generator and interface defn's complete.
1 parent 6b1ce03 commit 5332403

File tree

3 files changed

+42
-77
lines changed

3 files changed

+42
-77
lines changed

app/charts/EventChart.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ import React, { useState } from 'react';
33
import Plot from 'react-plotly.js';
44
import { all, solo as soloStyle } from './sizeSwitch';
55

6+
interface ChartData {
7+
value: string[];
8+
time: string[];
9+
}
10+
611
interface EventChartProps {
712
key: string;
8-
metric: string;
9-
timeList: any;
10-
valueList: any;
11-
sizing: string;
12-
colourGenerator: Function;
13+
metricName: string;
14+
chartData: ChartData
1315
}
1416

1517
interface SoloStyles {
@@ -18,7 +20,7 @@ interface SoloStyles {
1820
}
1921

2022
const EventChart: React.FC<EventChartProps> = React.memo(props => {
21-
const { metric, timeList, valueList, sizing, colourGenerator } = props;
23+
const { metricName, chartData } = props;
2224
const [solo, setSolo] = useState<SoloStyles | null>(null);
2325

2426
setInterval(() => {

app/containers/EventContainer.tsx

Lines changed: 33 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -20,92 +20,63 @@ const EventContainer: React.FC<EventContainerProps> = React.memo(props => {
2020
// eventChartsArr contains all charts of all metrics
2121
const [eventChartsArr, setEventChartsArr] = useState<JSX.Element[]>([]);
2222

23-
24-
25-
2623
/*
27-
Chronos11 -- Unfortunately, eventData is not in a good place for UI/UX purposes.
28-
The eventData object has a key of 'Event' and a value of an object with hundreds of keys as metric names
29-
with their associated values and timestamps due to the way kubernetes metrics are being tracked/logged in the database.
24+
Chronos11 -- Unfortunately, eventData is not in a good place for UI/UX purposes. These charts are being rendered 1:1 with the list of metrics (over 500).
3025
These metrics are scraped and generated by Prometheus, and should be sent to a Grafana instance
31-
to be displayed with a Grafana dashboard, but we didn't realize this until we were too close to launch to fix it.
32-
For now, the 'selectedMetrics' array is still an array with one object on it with a key of 'event', and a value of an array with
33-
the hundreds of metric names as strings inside. The eventData is an object with the key of event, and a value of an object with
34-
the hundreds of metrics as keys, and their values as the metrics and timestamps.
26+
to be displayed with a Grafana dashboard, but we didn't realize this was happening until we were too close to launch to fix it.
3527
It would be wonderful if a future iteration could manipulate the prometheus configuration in the kubernetes example to send its data
3628
to an instance of Grafana, and integrate Grafana's dashboard into Chronos to visualize the data.
3729
*/
3830

39-
const filterSelectedEventMetricsandData = () => {
31+
const filterSelectedEventMetricsandData = eventDataObj => {
4032
const filteredEventData = {};
4133
// there's only one element in the selected metrics array for now...
42-
// selectedMetrics is... [{Event: ['hundreds', 'of', 'metric', 'names', 'as', 'strings']}]
34+
// selectedMetrics is... [{Event: ['metric', 'names', 'as', 'strings']}]
4335
// use this array of selected metrics to filter the eventData down to only the metrics we want to see
4436
const selectedArr = selectedMetrics[0].Event;
4537
// only one service... 'Event'
46-
for (const service in eventData) {
38+
for (const service in eventDataObj) {
4739
filteredEventData[service] = {};
4840
// define the object of all the metrics
49-
const serviceMetricsObject = eventData[service];
41+
const serviceMetricsObject = eventDataObj[service];
5042
// iterate through all the metrics
5143
for (const metricName in serviceMetricsObject) {
5244
// if the metric name matches a string in the selectedArr, we add it to our filtered object
5345
if (selectedArr.includes(metricName)) {
54-
filteredEventData[service][metricName] = serviceMetricsObject[metricName]
46+
filteredEventData[service][metricName] = serviceMetricsObject[metricName];
5547
}
5648
}
5749
}
5850
return filteredEventData;
59-
}
60-
61-
const generateEventCharts = () => {
62-
63-
}
51+
};
6452

53+
// iterate over the filtered event data to build an array of charts, then set the event charts array state
54+
const generateEventCharts = filteredEventDataObj => {
55+
const chartsArray: JSX.Element[] = [];
56+
const keymaker = () => {
57+
return Math.floor(Math.random() * 1000);
58+
};
59+
for (const service in filteredEventDataObj) {
60+
const metricObject = filteredEventDataObj[service];
61+
for (const metricName in metricObject) {
62+
const chartData = metricObject[metricName];
63+
chartsArray.push(
64+
<EventChart
65+
key={'E' + keymaker()}
66+
metricName={metricName}
67+
chartData={chartData}
68+
/>
69+
);
70+
}
71+
}
72+
setEventChartsArr(chartsArray);
73+
};
74+
// invoke the filter and generate functions to render charts
6575
useEffect(() => {
66-
const temp: JSX.Element[] = [];
67-
filterSelectedEventMetricsandData();
68-
// if (eventData && eventDataList.length > 0 && eventTimeList.length > 0) {
69-
// let selectedMetricsList: string[] = [];
70-
// selectedMetrics.forEach(element => {
71-
// if (Object.keys(element)[0] === 'Event') {
72-
// selectedMetricsList = element['Event'];
73-
// }
74-
// });
75-
76-
// eventDataList.forEach((element, id) => {
77-
// const metric: string = Object.keys(element)[0];
78-
// const valueList: any = Object.values(element)[0];
79-
// if (selectedMetricsList.includes(metric)) {
80-
// const newEventChart = (
81-
// <EventChart
82-
// key={`Chart${id}`}
83-
// metric={metric}
84-
// timeList={getSingleTimeList(metric)}
85-
// valueList={valueList}
86-
// sizing={props.sizing}
87-
// colourGenerator={props.colourGenerator}
88-
// />
89-
// );
90-
91-
// temp.push(newEventChart);
92-
// }
93-
// });
94-
// setEventChartsArr(temp);
95-
// }
76+
const filteredEventData = filterSelectedEventMetricsandData(eventData);
77+
generateEventCharts(filteredEventData);
9678
}, [eventData, service]);
9779

98-
// const getSingleTimeList = (metricName: string) => {
99-
// let lst = [];
100-
// for (let metric of eventTimeList) {
101-
// if (Object.keys(metric)[0] === metricName) {
102-
// lst = metric[metricName];
103-
// break;
104-
// }
105-
// }
106-
// return lst;
107-
// };
108-
10980
return (
11081
<div>
11182
{service.includes('kafkametrics') || service.includes('kubernetesmetrics')
@@ -115,4 +86,4 @@ const EventContainer: React.FC<EventContainerProps> = React.memo(props => {
11586
);
11687
});
11788

118-
export default EventContainer;
89+
export default EventContainer;

app/containers/HealthContainer.tsx

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -153,21 +153,13 @@ const HealthContainer: React.FC<HealthContainerProps> = React.memo(props => {
153153
for (const serviceName in serviceObjects) {
154154
// pass down the value of the current data type and service
155155
const chartData = serviceObjects[serviceName];
156-
console.log(
157-
'dataType: ',
158-
dataType,
159-
'service name: ',
160-
serviceName,
161-
'chartData: ',
162-
chartData
163-
);
164156
chartsArray.push(
165157
<HealthChart
166158
key={'H' + keymaker()}
167159
dataType={dataType}
168160
serviceName={serviceName}
169161
chartData={chartData}
170-
categoryName={`${category}`}
162+
categoryName={category}
171163
sizing={props.sizing}
172164
colourGenerator={props.colourGenerator}
173165
/>

0 commit comments

Comments
 (0)