Skip to content

Commit af075c4

Browse files
committed
refactoring fetch health data
1 parent 4e0f68d commit af075c4

9 files changed

Lines changed: 41 additions & 35 deletions

File tree

app/components/GraphNavBar/GraphNavBar.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { ApplicationContext } from '../../context/ApplicationContext'
44
import { QueryContext } from '../../context/QueryContext'
55
import { CommsContext } from '../../context/CommsContext'
66
import { HealthContext } from '../../context/HealthContext'
7-
import { Link } from 'react-router-dom';
87

98
const GraphNavBar = (props) => {
109

@@ -18,6 +17,7 @@ const GraphNavBar = (props) => {
1817
const navigate = useNavigate();
1918

2019
const routing = (route: string) => {
20+
console.log({servicesData})
2121
if (location.href.includes('communications')) {
2222
if (prevRoute === '') navigate(`${servicesData[0].microservice}`);
2323
else navigate(prevRoute);
@@ -50,7 +50,8 @@ const GraphNavBar = (props) => {
5050
);
5151
});
5252
}
53-
53+
// console.log(selectedMetrics)
54+
// console.log(buttonList)
5455
return buttonList;
5556
};
5657

app/components/TransferColumns.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ interface Params {
1616

1717
const TransferColumns = React.memo(() => {
1818
const [targetKeys, setTargetKeys] = useState<any[]>([]);
19+
// console.log({targetKeys})
1920
const [metricsPool, setMetricsPool] = useState<any[]>([]);
21+
// console.log({metricsPool})
2022
const [healthMetricsReady, setHealthMetricsReady] = useState(false);
2123
const [healthMetrics, setHealthMetrics] = useState<any[]>([]);
2224
const [eventMetricsReady, setEventMetricsReady] = useState(false);
@@ -34,6 +36,7 @@ const TransferColumns = React.memo(() => {
3436

3537
useEffect(() => {
3638
if (healthData) {
39+
console.log({healthData})
3740
setHealthMetricsReady(true);
3841
}
3942
}, [healthData]);
@@ -122,9 +125,10 @@ const TransferColumns = React.memo(() => {
122125
};
123126

124127
const createSelectedMetricsList = () => {
128+
125129
const temp: any[] = [];
126130
const categorySet = new Set();
127-
// console.log('Inside TransferColumns.txs line 124 targetKeys: ', targetKeys)
131+
128132
for (let i = 0; i < targetKeys.length; i++) {
129133
const str: string = targetKeys[i];
130134
const strArr: string[] = str.split(' | ');
@@ -209,6 +213,7 @@ const TransferColumns = React.memo(() => {
209213
checkboxSelection
210214
disableSelectionOnClick
211215
onSelectionModelChange={metricIndeces => {
216+
console.log({metricIndeces})
212217
const metrics: any[] = [];
213218
metricIndeces.forEach(el => {
214219
metrics.push(metricsPool[el].key);

app/containers/GraphsContainer/GraphsContainer.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,12 @@ const GraphsContainer: React.FC = React.memo(() => {
102102
inspect={inspect}
103103
setInspect={setInspect}
104104
/>
105-
<Header app={app} service={service} live={live} setLive={setLive} />
105+
<Header
106+
app={app}
107+
service={service}
108+
live={live}
109+
setLive={setLive}
110+
/>
106111

107112
{inspect && <Inspect />}
108113

app/context/HealthContext.tsx

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ interface HealthDataObject {
3434
const HealthContextProvider: React.FC<Props> = React.memo(({ children }) => {
3535
const [healthData, setHealthData] = useState<any>({ healthDataList: [], healthTimeList: [] });
3636
const [services, setServices] = useState<Array<string>>([]);
37+
console.log({services})
3738

3839
function tryParseJSON(jsonString: any) {
3940
try {
@@ -55,46 +56,46 @@ const HealthContextProvider: React.FC<Props> = React.memo(({ children }) => {
5556
*/
5657

5758
const fetchHealthData = useCallback(async servers => {
58-
ipcRenderer.removeAllListeners('healthResponse');
59+
// ipcRenderer.removeAllListeners('healthResponse');
5960

6061
let temp: HealthDataObject[] = [];
6162
await Promise.all(servers.map( async (service: string) => {
62-
//NOT WORKING HERE
63+
ipcRenderer.removeAllListeners('healthResponse');
64+
6365
try {
6466
const newPromise: any = await new Promise((resolve, reject) => {
6567
ipcRenderer.send('healthRequest', `${service}`);
6668
ipcRenderer.on('healthResponse', (event: Electron.Event, data: string) => {
67-
let result: object[];
68-
// console.log({data})
69-
if (JSON.stringify(data) !== '{}' && tryParseJSON(data)) {
70-
result = JSON.parse(data);
71-
// console.log({result})
72-
// console.log('HealthContext.tsx line 68 result: ', result, 'service', service, 'Obj key', Object.keys(result[0])[0]);
69+
//V14: the line does not appear necessary, leaving it here commented out in case another group runs into a problem
70+
// if (JSON.stringify(data) !== '{}' && tryParseJSON(data)) {
71+
const response = JSON.parse(data);
72+
// console.log({response})
73+
const [ dbName ] = Object.keys(response[0])
7374
//result exists, has a length prop, and the service name and database name are same
74-
if (result && result.length && `${service}` === Object.keys(result[0])[0]) {
75-
resolve(result[0]);
75+
console.log({service,dbName})
76+
//V14: this block is needed here because of unecessary calls for each service
77+
//a prior group was getting the dbName from the response object and since objects dont remember
78+
//insertion order they are running all the calls for each service in the array
79+
if (response && response.length && `${service}` === dbName) {
80+
resolve(response[0]);
7681
}
77-
}
82+
// }
7883
});
7984
})
8085
temp.push(newPromise);
81-
// console.log('HealthContext.tsx line 80 temp populates?: ', temp, serv)
8286
if (checkServicesComplete(temp, [`${service}`])) {
87+
console.log({temp})
88+
8389
setServices([`${service}`]);
8490
let transformedData: any = {};
85-
// console.log('original healthData before transformation: ', temp);
86-
// transformedData = {
87-
// healthDataList: [1,2,3,4,5],
88-
// healthTimeList: [1,2,3,4,5]
89-
// } //testing typescript, transformedDATA of type 2 arrays with basic entries?
9091
transformedData = healthTransformer(temp); //must match the setHealthData STATE format
91-
// console.log('healthData after tranformation: ', transformedData);
9292
setHealthData(transformedData);
9393
}
9494
} catch (err) {
95-
// console.log("healthcontext.tsx ERROR: ", err);
95+
console.log("healthcontext.tsx ERROR: ", err);
9696
};
9797
}
98+
9899
))
99100
} , []);
100101

@@ -104,9 +105,9 @@ const HealthContextProvider: React.FC<Props> = React.memo(({ children }) => {
104105
}
105106
const arr1: string[] = [];
106107
for (let i = 0; i < temp.length; i++) {
107-
arr1.push(Object.keys(temp[i])[0]);
108+
const [ serviceName ] = Object.keys(temp[i])
109+
arr1.push(serviceName);
108110
}
109-
// console.log('in checkServicesComplete line 139: ', arr1);
110111
return arr1.sort().toString() === servers.sort().toString();
111112
};
112113

app/context/helpers.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export function healthTransformer(healthData: HealthDataObject[]) {
4444
// grab the key string from the current service object
4545
const serviceName = Object.keys(serviceObj)[0];
4646
const serviceElements = serviceObj[serviceName];
47+
console.log(serviceObj)
4748
// console.log('serviceElements: ', serviceElements);
4849
// add the serviceName as a key on the serviceMetricsObject and assign it an empty object
4950
serviceMetricsObject[serviceName] = {};

app/index.scss

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,19 +153,12 @@ body {
153153
button {
154154
font-size: 90%;
155155
padding: 6px;
156-
// border: thin solid #24262f;
157156
border-radius: 3px;
158-
// background-color: #484e63;
159157
color: #fff;
160-
// min-width: 105px;
161158
transition: 0.2s;
162159
cursor: pointer;
163160
}
164161

165-
button:hover {
166-
// background-color: #24262f;
167-
}
168-
169162
// scrollBar styling
170163

171164
/* width */

examples/docker/auth/src/app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import eventRouter from './routes/event-router';
77
import { NotFoundError, errorHandler } from '@chronosrx/common';
88

99
import chronosConfig from './chronos-config';
10-
const Chronos = require('@chronosmicro/tracker');
10+
const Chronos = require('../chronos_npm_package/chronos.js');
1111
const chronos = new Chronos(chronosConfig);
1212

1313
chronos.propagate();

examples/docker/auth/src/chronos-config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const chronosConfig = {
1919
type: process.env.CHRONOS_DB,
2020
URI: process.env.CHRONOS_URI,
2121
},
22-
grafanaAPIKey: Bearer process.env.CHRONOS_GRAFANA_API_KEY,
22+
grafanaAPIKey: process.env.CHRONOS_GRAFANA_API_KEY,
2323
notifications: [],
2424
};
2525
export default chronosConfig;

examples/docker/client/src/server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const express = require('express');
44
const PORT = 5001;
55

66
const chronosConfig = require('./chronos-config');
7-
const Chronos = require('@chronosmicro/tracker');
7+
const Chronos = require('../chronos_npm_package/chronos.js');
88
const chronos = new Chronos(chronosConfig);
99

1010
chronos.propagate();

0 commit comments

Comments
 (0)