Chronos
Chronos copied to clipboard
Chronos npm microservices refactor
Types of changes
- [x] Bugfix (change which fixes an issue)
- [ ] New feature (change which adds functionality)
- [x] Refactor (change which changes the codebase without affecting its external behavior)
- [ ] Non-breaking change (fix or feature that would cause existing functionality to work as expected)
- [x] Breaking change (fix or feature that would cause existing functionality to not work as expected)
Purpose
- The microservices portion of the app was not passing data and was completely non functional
- It seems that prior teams working on chronos broke the microservices functionality by changing code in key places
- No data was being stored in any of the associated databases.
- Now data is being stored in each of the microservices (health data), the communications data base (commsData) and the individual metrics database (savedMetrics)
- Graphs and data are now being displayed correctly in the microservices portion of the app
Approach
-
Dug into the local chronos npm package code and found that inside of the track function a number of helper function were being called asyncrounously
-
Inside of the the mongo.health function there was another function being called (collectHealthData) that was collecting system information health data.
-
The problem was that each of these functions (that were being called as methods on the systeminformation library) were all async. The thenables of these functions were pushing data inside an empty array declared at the top of the parent function.
-
At the end of the parent function this array was being filtered and then return synchrounsly.
-
Because the parent function was not async and the system information functions were not being awaited, the top level array meant to collect the health information was not being given a chance to actually populate.
-
I changed the parent function to an async function and awaited each of the systeminformation method calls which fixed the issue and successfully returned the data
-
Additonally I refactored code inside of the npm package and was able to remove a few layers of nested async calls which has significantly improved the performance of the app.
-
Lastly when the graphs container is rendered a 'health request' event is sent to electron that grabs the data stored from the npm package portion of the code.
-
A function called mongoFetch then gets called which is responsible for aggregating all the data from each of the services in the database into useable data for the frontend.
-
I found a side effect in this function that was causing the last blockage of data for microservices.
-
There is a part of the mongoFetch function that grabs an api key from grafana that is stored in env files in the DOCKER side of app. In microservices grafana is not used so that data comes back as undefined.
-
There is currently no check in that function to differentiate between docker and microservices so when the graphs container makes the call to electron an error would occur because that function expects that grafana key to populated as an object with properties.
-
I commented out the portion of this code relating to grafana temporarily and will add logic block to run code if the app is containerized or not.