Skip to content

Commit 31119f5

Browse files
committed
slight adjustments to EventContext and EventContainer.
Improvements to HealthChart logic to accommodate multiple services selected.
1 parent 34797fb commit 31119f5

File tree

7 files changed

+46
-54
lines changed

7 files changed

+46
-54
lines changed

app/charts/HealthChart.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { all, solo as soloStyle } from './sizeSwitch';
66
interface HealthChartProps {
77
key: string;
88
dataType: string;
9+
serviceName: string;
910
chartData: object;
1011
categoryName: string;
1112
sizing: string;
@@ -52,21 +53,15 @@ const HealthChart: React.FC<HealthChartProps> = React.memo(props => {
5253
const arrayOfPlotlyDataObjects: PlotlyData[] = [];
5354
// iterate through the chartData
5455
for (const serviceName in chartDataObj) {
55-
console.log('SERVICENAME: ', serviceName);
5656
// define the metrics for this service
5757
const metrics = chartDataObj[serviceName];
58-
console.log('METRICS: ', metrics);
5958
// loop through the list of metrics for the current service
6059
for (const metricName in metrics) {
61-
console.log('METRICNAME: ', metricName);
6260
// define the value and time arrays; allow data to be reassignable in case we need to convert the bytes data into megabytes
6361
let dataArray = metrics[metricName].value;
64-
console.log('DATAARRAY: ', dataArray);
6562
const timeArray = metrics[metricName].time;
66-
console.log('TIMEARRAY: ', timeArray);
6763
// specifically for `Megabyte` types, convert the original data of bytes into a value of megabytes before graphing
6864
if (dataType === 'Memory in Megabytes' || dataType === 'Cache in Megabytes') {
69-
console.log('DATATYPE: ', dataType);
7065
dataArray = dataArray.map(value => (value / 1000000).toFixed(2));
7166
}
7267
// create the plotly object
@@ -80,7 +75,6 @@ const HealthChart: React.FC<HealthChartProps> = React.memo(props => {
8075
colors: ['#fc4039', '#4b54ea', '#32b44f', '#3788fc', '#9c27b0', '#febc2c'],
8176
},
8277
};
83-
console.log('PLOTLYDATAOBJECT: ', plotlyDataObject)
8478
// push the dataObject into the arrayOfPlotlyDataObjects
8579
arrayOfPlotlyDataObjects.push(plotlyDataObject);
8680
}
@@ -98,6 +92,7 @@ const HealthChart: React.FC<HealthChartProps> = React.memo(props => {
9892
const createChart = () => {
9993
const dataArray = generatePlotlyDataObjects(chartData);
10094
const serviceNames = serviceNamesAsString(chartData);
95+
console.log('serviceNames: ', serviceNames);
10196
const sizeSwitch = sizing === 'all' ? all : solo;
10297

10398
return (

app/components/Occupied.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ type ClickEvent = React.MouseEvent<HTMLElement>;
6262

6363
//v10: Memoized function, witouth any props. Should theoretically be called only once.
6464
const Occupied = React.memo(() => {
65-
console.log('Hi, inside Occupied. Memoize function invoked');
66-
6765
const { awsData, fetchAwsData, fetchAwsAppInfo, setLoadingState } = useContext(AwsContext);
6866
const { setServicesData, app, setApp } = useContext(ApplicationContext);
6967
// const { user, getApplications, deleteApp, mode } = useContext(DashboardContext);

app/components/TransferColumns.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const TransferColumns = React.memo(() => {
3737
// console.log('targetKeys: ', targetKeys);
3838
// console.log('eventData: ', eventData);
3939
// console.log('eventDataList: ', eventDataList);
40+
// console.log('event metrics: ', eventMetrics);
4041

4142
useEffect(() => {
4243
if (healthDataObject) {
@@ -71,10 +72,10 @@ const TransferColumns = React.memo(() => {
7172
}
7273
// JJ-ADDITION (CAN ALSO JUST ADD OR OPERATOR TO ABOVE CONDITIONAL)
7374
else if (service === 'kubernetesmetrics') {
74-
if (healthDataObject) {
75-
setMetricsPool(getMetrics('health', healthDataObject));
76-
} else if (healthMetricsReady) {
77-
setMetricsPool(healthMetrics);
75+
if (eventDataList && eventDataList.length > 0) {
76+
setMetricsPool(getMetrics('event', eventDataList));
77+
} else if (eventMetricsReady) {
78+
setMetricsPool(eventMetrics);
7879
}
7980
} else if (!service.includes('kafkametrics')) {
8081
if (healthDataObject) {
@@ -127,14 +128,14 @@ const TransferColumns = React.memo(() => {
127128
return pool;
128129
};
129130

130-
// Justin's alternative to getCharts (b/c getCharts is just saving the user-selected metrics into QueryContext)
131+
// Justin's alternative idea to getCharts (b/c getCharts is just saving the user-selected metrics into QueryContext)
131132
// getCharts takes data that already exists in state as an array of strings, and makes it into an array of objects, just to save it to QueryContext state
132133
// the selectedMetrics from QueryContext is used in TransferColumns, EventContainer, GraphsContainer, and HealthContainer
133134
// const saveSelectedMetrics = () => {
134135
// // iterate over the targetKeys array
135136
// }
136137

137-
const getCharts = () => {
138+
const createSelectedMetricsList = () => {
138139
const temp: any[] = [];
139140
const categorySet = new Set();
140141
console.log('targetKeys is: ', targetKeys);
@@ -157,7 +158,7 @@ const TransferColumns = React.memo(() => {
157158
temp.push(newCategory);
158159
}
159160
}
160-
console.log('temp array with requested graphs is: ', temp);
161+
console.log('temp array with requested metrics is: ', temp);
161162
setSelectedMetrics(temp);
162163
};
163164

@@ -201,7 +202,7 @@ const TransferColumns = React.memo(() => {
201202
return (
202203
<>
203204
<div id="getChartsContainer">
204-
<Button id="getCharts" onClick={getCharts} variant="contained" color="primary">
205+
<Button id="getCharts" onClick={createSelectedMetricsList} variant="contained" color="primary">
205206
Get Charts
206207
</Button>
207208
</div>
@@ -219,6 +220,7 @@ const TransferColumns = React.memo(() => {
219220
metricIndeces.forEach(el => {
220221
metrics.push(metricsPool[el].key);
221222
});
223+
console.log('targetKeys is set to: ', metrics);
222224
setTargetKeys(metrics);
223225
}}
224226
/>

app/containers/GraphsContainer.tsx

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,11 @@ interface Params {
2828
service: string;
2929
}
3030

31-
// interface GraphsContainerProps {
32-
// match: {
33-
// path: string;
34-
// url: string;
35-
// isExact: boolean;
36-
// params: Params;
37-
// };
38-
// }
39-
4031
const GraphsContainer: React.FC = React.memo(props => {
4132
const navigate = useNavigate();
4233
const { app, service } = useParams<keyof Params>() as Params;
4334
const [live, setLive] = useState<boolean>(false);
4435
const { intervalID, setIntervalID } = useContext(ApplicationContext);
45-
// const [intervalID, setIntervalID] = useState<NodeJS.Timeout | null>(null);
4636
const { servicesData, getSavedMetrics } = useContext(ApplicationContext);
4737
const { fetchHealthData, setHealthData, services } = useContext(HealthContext);
4838
const { setDockerData, dockerData } = useContext(DockerContext);
@@ -59,7 +49,7 @@ const GraphsContainer: React.FC = React.memo(props => {
5949
const serviceArray = service.split(' ');
6050
// You would think you should add "kubernetesmetrics" into the below for consistency's sake but it makes it
6151
// not work correctly, so it has been omitted
62-
const healthServiceArray = serviceArray.filter((value: string) => value !== 'kafkametrics');
52+
const healthServiceArray = serviceArray.filter((value: string) => value !== 'kafkametrics' && value !== 'kubernetesmetrics');
6353
if (live) {
6454
setIntervalID(
6555
setInterval(() => {
@@ -157,7 +147,6 @@ const GraphsContainer: React.FC = React.memo(props => {
157147

158148
const HealthAndEventButtons: JSX.Element[] = getHealthAndEventComponents();
159149
console.log('selected metrics: ', selectedMetrics);
160-
console.log('chart: ', chart);
161150

162151
return (
163152
<>

app/containers/HealthContainer.tsx

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const HealthContainer: React.FC<HealthContainerProps> = React.memo(props => {
3939
*/
4040
const filterSelectedMetricsAndHealthData = (): DataObject => {
4141
// define a filtered health data object for output
42-
// define an array of filteredMetricNames
42+
// define an array of filteredMetricNames for later use
4343
const filteredHealthData = {};
4444
const filteredMetricNames: string[] = [];
4545
// iterate over the selectedMetrics from QueryContext
@@ -113,6 +113,7 @@ const HealthContainer: React.FC<HealthContainerProps> = React.memo(props => {
113113
const typeGroupedObject = {};
114114
// iterate over the services in the healthData object
115115
for (const serviceName in filteredHealthData) {
116+
console.log('service name in datatype function: ', serviceName);
116117
// save the filtered metrics of the current service to a variable
117118
// define the types of each metric in the metrics object as an array
118119
const metrics: object = filteredHealthData[serviceName];
@@ -122,46 +123,53 @@ const HealthContainer: React.FC<HealthContainerProps> = React.memo(props => {
122123
// iterate over the types array and assign the typeGroupedObject a key of type, with a value of an object
123124
// then assign that newly created object a key of the current service and a value of an object
124125
typesArray.forEach((metricType: string) => {
125-
typeGroupedObject[metricType] = {};
126+
if (!typeGroupedObject[metricType]) {
127+
// if the metric type doesn't exist, initalize it
128+
typeGroupedObject[metricType] = {};
129+
} // if it does exist alread, add the service name to it
126130
typeGroupedObject[metricType][serviceName] = {};
127-
})
128-
// iterate over the metrics object
131+
});
132+
// iterate over the metrics object of the current service
129133
for (const metric in metrics) {
130134
// define the current metric's type
131135
const metricType: string = defineDataValueType(metric);
132136
// store the current metric and its value in the typeGrouped object at the appropriate type and serviceName
133137
typeGroupedObject[metricType][serviceName][metric] = metrics[metric];
134138
}
135139
}
136-
140+
137141
return typeGroupedObject;
138142
};
139143

140144
// function to generate charts using the type-sorted data
141145
const generateCharts = sortedData => {
142146
const chartsArray: JSX.Element[] = [];
143147
const keymaker = () => {
144-
return Math.floor(Math.random()*1000)
145-
}
146-
// iterate over the sortedData and create a chart for each data type
148+
return Math.floor(Math.random() * 1000);
149+
};
150+
// iterate over the sortedData and create a chart for each data type and each service of that data
147151
for (const dataType in sortedData) {
148-
// pass down the value of the current data type object
149-
const chartData = sortedData[dataType];
150-
console.log('dataType: ', dataType, 'chartData: ', chartData);
151-
chartsArray.push(
152-
<HealthChart
153-
key={'H' + keymaker()}
154-
dataType={dataType}
155-
chartData={sortedData[dataType]}
156-
categoryName={`${category}`}
157-
sizing={props.sizing}
158-
colourGenerator={props.colourGenerator}
159-
/>
160-
);
152+
const serviceObjects = sortedData[dataType];
153+
for (const serviceName in serviceObjects) {
154+
// pass down the value of the current data type object
155+
const chartData = serviceObjects[serviceName];
156+
console.log('dataType: ', dataType, 'chartData: ', chartData);
157+
chartsArray.push(
158+
<HealthChart
159+
key={'H' + keymaker()}
160+
dataType={dataType}
161+
serviceName={serviceName}
162+
chartData={sortedData[dataType]}
163+
categoryName={`${category}`}
164+
sizing={props.sizing}
165+
colourGenerator={props.colourGenerator}
166+
/>
167+
);
168+
}
161169
}
162170
setHealthChartsArr(chartsArray);
163171
};
164-
172+
165173
useEffect(() => {
166174
// returns an object containing only the healthData for the current category and the metrics the User selected
167175
const filteredHealthData = filterSelectedMetricsAndHealthData();

app/context/ApplicationContext.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const ApplicationContextProvider: React.FC<AppContextProps> = React.memo(props =
6060
* @params application - is the name of the card taht was clicked on
6161
*/
6262
const connectToDB = useCallback((username: string, index: number, application: string, URI: string, databaseType: string) => {
63-
console.log('Hi, inside ApplicationContext, connectToDB function was invoked.');
63+
// console.log('Hi, inside ApplicationContext, connectToDB function was invoked.');
6464
ipcRenderer.removeAllListeners('databaseConnected');
6565
ipcRenderer.send('connect', username, index, URI, databaseType);
6666
ipcRenderer.on('databaseConnected', (event: Electron.Event, data: any) => {

app/context/HealthContext.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ const HealthContextProvider: React.FC<Props> = React.memo(({ children }) => {
6262
if (checkServicesComplete(temp, serv)) {
6363
setServices(serv);
6464
let transformedData: any = {};
65-
console.log('original data before transformation: ', temp);
65+
console.log('original healthData before transformation: ', temp);
6666
transformedData = transformer(temp);
67-
console.log('data after tranformation: ', transformedData);
67+
console.log('healthData after tranformation: ', transformedData);
6868
setHealthData(transformedData);
6969
}
7070
});

0 commit comments

Comments
 (0)