Skip to content

Commit 9354584

Browse files
committed
added comments; updated chart logic to convert bytes to megabytes.
1 parent b17e1ff commit 9354584

File tree

3 files changed

+24
-28
lines changed

3 files changed

+24
-28
lines changed

app/charts/HealthChart.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ const HealthChart: React.FC<HealthChartProps> = React.memo(props => {
5656
const metrics = chartData[serviceName];
5757
// loop through the list of metrics for the current service
5858
for (const metricName in metrics) {
59-
// define the value and time arrays
60-
const dataArray = metrics[metricName].value;
59+
// define the value and time arrays; allow data to be reassignable in case we need to convert the bytes data into megabytes
60+
let dataArray = metrics[metricName].value;
6161
const timeArray = metrics[metricName].time;
62-
// specifically for `Megabyte` types, convert the data of bytes into a value of megabytes before graphing
62+
// specifically for `Megabyte` types, convert the original data of bytes into a value of megabytes before graphing
6363
if (dataType === 'Memory in Megabytes' || 'Cache in Megabytes') {
64-
dataArray.map(value => (value / 1000000).toFixed(2));
64+
dataArray = dataArray.map(value => (value / 1000000).toFixed(2));
6565
}
6666
// create the plotly object
6767
const plotlyDataObject: PlotlyData = {
@@ -79,7 +79,6 @@ const HealthChart: React.FC<HealthChartProps> = React.memo(props => {
7979
}
8080
}
8181
// return the array of plotlyDataObject
82-
console.log('plotlyObjectArray: ', arrayOfPlotlyDataObjects);
8382
return arrayOfPlotlyDataObjects;
8483
};
8584

app/components/TransferColumns.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ const TransferColumns = React.memo(() => {
3232

3333
const currentMode = mode === 'light' ? lightAndDark.lightModeText : lightAndDark.darkModeText;
3434

35-
console.log('healthMetrics: ', healthMetrics);
36-
console.log('metricsPool: ', metricsPool);
37-
console.log('targetKeys: ', targetKeys);
38-
console.log('eventData: ', eventData);
39-
console.log('eventDataList: ', eventDataList);
35+
// console.log('healthMetrics: ', healthMetrics);
36+
// console.log('metricsPool: ', metricsPool);
37+
// console.log('targetKeys: ', targetKeys);
38+
// console.log('eventData: ', eventData);
39+
// console.log('eventDataList: ', eventDataList);
4040

4141
useEffect(() => {
4242
if (healthDataObject) {

app/containers/HealthContainer.tsx

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,18 @@ interface DataObject {
2121

2222
const HealthContainer: React.FC<HealthContainerProps> = React.memo(props => {
2323
/*
24-
Pull in all the health data via HealthContext
25-
Pull in the list of ALL user-selected metrics via QueryContext as strings, even if they don't pertain to this category.
26-
Destructure category from props. This category was passed down from the GraphsContainer and creates a new tab in Chronos to view charts pertaining only to the category.
24+
healthData - Pull in all the health data via HealthContext
25+
selectedMetrics - Pull in the list of ALL user-selected metrics via QueryContext as strings, even if they don't pertain to this category.
26+
category - Destructure category from props. This category was passed down from the GraphsContainer and creates a new tab in Chronos to view charts pertaining only to the category.
2727
Think of each <HealthContainer /> as the new tab in Chronos. It will only create charts pertaining to that category.
28-
healthChartsArr is local state that gets updated here with an array of <HealthChart />'s that display user-selected data for the category.
29-
`service` is only used to determine if we should display our health charts (because kafka and kubernetes specifically don't use HealthChart to display data).
28+
healthChartsArr - local state that gets updated with an array of <HealthChart />'s that display user-selected data.
29+
`service` - only used to determine if we should display our health charts (because kafka and kubernetes specifically don't use HealthChart to display data).
3030
*/
3131
const { healthData } = useContext(HealthContext);
3232
const { selectedMetrics } = useContext(QueryContext);
3333
const { category } = props;
3434
const { service } = useParams<keyof Params>() as Params;
3535
const [healthChartsArr, setHealthChartsArr] = useState<JSX.Element[]>([]);
36-
3736
/*
3837
This function filters the selectedMetrics array down to only metrics that match the category of this instance of HealthContainer.
3938
Once that has finished, it then filters the healthData down to the current category and the filteredMetrics.
@@ -45,12 +44,13 @@ const HealthContainer: React.FC<HealthContainerProps> = React.memo(props => {
4544
const filteredMetricNames: string[] = [];
4645
// iterate over the selectedMetrics from QueryContext
4746
selectedMetrics.forEach(metricObj => {
48-
// due to the way the data is stored, the metricObj only has one key on it; thus [0] is tacked onto the end
47+
// due to the way the data is stored, each metricObj has a key of category, and an array of selected metrics as a value
4948
const metricCategory = Object.keys(metricObj)[0];
50-
// if the current metric's category matches our category, add its array content to the filteredHealthData array
49+
const metricValuesArray = metricObj[metricCategory];
50+
// if the current metricObj's category matches our instance's current category, iterate through its array of values
5151
if (metricCategory === category) {
52-
metricObj[metricCategory].forEach(metricName => {
53-
filteredMetricNames.push(metricName);
52+
metricValuesArray.forEach(metricName => {
53+
filteredMetricNames.push(metricName); // add the metricNames to the filteredMetricNames array
5454
});
5555
}
5656
});
@@ -76,7 +76,6 @@ const HealthContainer: React.FC<HealthContainerProps> = React.memo(props => {
7676
}
7777
return filteredHealthData;
7878
};
79-
8079
// function to create a version of the healthData based on the value type
8180
// current healthData value types: GHz, bytes, temperature, percent, ticks, processes, num, latency
8281
const defineDataValueType = (metricName: string): string => {
@@ -95,7 +94,7 @@ const HealthContainer: React.FC<HealthContainerProps> = React.memo(props => {
9594
cache: 'Cache in Megabytes',
9695
latency: 'Latency',
9796
};
98-
// iterate through the dictionary and check if the key matches any part of the metricName
97+
// iterate through the dictionary and check if the key matches any part of the passed in metricName
9998
// if they match, update type variable to the value of the matching key and return
10099
let type: string = ''; // type will store the result for returning
101100
for (const [key, value] of Object.entries(typeDictionary)) {
@@ -141,15 +140,17 @@ const HealthContainer: React.FC<HealthContainerProps> = React.memo(props => {
141140
// function to generate charts using the type-sorted data
142141
const generateCharts = sortedData => {
143142
const chartsArray: JSX.Element[] = [];
144-
let keymaker = 1;
143+
const keymaker = () => {
144+
return Math.floor(Math.random()*1000)
145+
}
145146
// iterate over the sortedData and create a chart for each data type
146147
for (const dataType in sortedData) {
147148
// pass down the value of the current data type object
148149
const chartData = sortedData[dataType];
149150
console.log('dataType: ', dataType, 'chartData: ', chartData);
150151
chartsArray.push(
151152
<HealthChart
152-
key={`Chart${keymaker++}`}
153+
key={'H' + keymaker()}
153154
dataType={dataType}
154155
chartData={sortedData[dataType]}
155156
categoryName={`${category}`}
@@ -164,16 +165,12 @@ const HealthContainer: React.FC<HealthContainerProps> = React.memo(props => {
164165
useEffect(() => {
165166
// returns an object containing only the healthData for the current category and the metrics the User selected
166167
const filteredHealthData = filterSelectedMetricsAndHealthData();
167-
console.log('filteredHealthData: ', filteredHealthData)
168168
// returns an object containing the filtered data sorted by data type
169169
const typeSortedHealthData = healthDataGroupedByDataType(filteredHealthData);
170-
console.log('typeSortedHealthData: ', typeSortedHealthData);
171170
// invoking generateCharts with the sorted data will update healthChartsArr in state with the list of charts to be rendered
172171
generateCharts(typeSortedHealthData);
173-
console.log(healthChartsArr)
174172
}, [category]);
175173

176-
// return <div>{service !== 'kafkametrics' ? healthChartsArr : []}</div>;
177174
// JJ-ADDITION
178175
return (
179176
<div>

0 commit comments

Comments
 (0)