Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/server health check #349

Merged
merged 16 commits into from
Dec 6, 2023
Merged

Feature/server health check #349

merged 16 commits into from
Dec 6, 2023

Conversation

ascibisz
Copy link
Contributor

@ascibisz ascibisz commented Dec 1, 2023

Problem

The server health check has existed in Octopus for a while now, time to take it in to the viewer!

One part of this ticket. The other piece of that ticket will include adding a health check call, similar to the one implemented here in the example viewer, to the simualrium-website in the early stages of the autoconversion form.

Also added in support for handling error messages octopus sends now, which is another new message type that has existed in Octopus for a bit.

Solution

Paired on this with with @interim17

Type of change

  • New feature (non-breaking change which adds functionality)

Change summary:

  • Added handling for new message types that come from octopus: ID_ERROR_MSG = 21 and ID_SERVER_HEALTHY_RESPONSE = 23
  • Added ability to request health check, using new message type ID_CHECK_HEALTH_REQUEST = 22, which octopus already knows how to handle
  • Added an example of using the health check request / response to the example viewer. Now, when you hit the "Load a smoldyn trajectory" button, a websocket connection will be initiated and health check request will be sent to octopus. The "submit" button will remain disabled until a server healthy response comes back
  • As part of the changes to the example, I updated the autoconversion request call to only initiate a new websocket connection if there isn't already one there. Previously, we just automatically created a new websocket connection, but in the case that one may already exist from the server health check, we should just reuse that one

@ascibisz ascibisz changed the base branch from main to admin/wss-for-octopus December 1, 2023 00:41
Copy link

github-actions bot commented Dec 1, 2023

jest coverage report 🧪

Total coverage

Status Category Percentage Covered / Total
🔴 Statements 40.77% 2013/4937
🔴 Branches 44.08% 831/1885
🔴 Functions 37.4% 413/1104
🔴 Lines 41% 1927/4700

Status of coverage: 🟢 - ok, 🟡 - slightly more than threshold, 🔴 - under the threshold

Show files with reduced coverage 🔻

Reduced coverage

Status Filename Statements Branches Functions Lines
🔴 src/controller 29.71% 15.32% (-1.21% 🔻) 17.54% 29.75%
🟡 src/simularium 62.32% 60.31% 50.25% (-1.48% 🔻) 63.29%
🔴 ClientSimulator.ts 22.11% 31.81% 11.76% 21.78%
🔴 LocalFileSimulator.ts 31.42% 50% 12.12% 31.34%
🔴 RemoteSimulator.ts 48.85% (-2.84% 🔻) 66.66% 27.27% (-4.3% 🔻) 52.1% (-2.52% 🔻)
🟢 WebsocketClient.ts 82.66% (+1.05% 🔼) 69.23% 69.69% (-1.27% 🔻) 83.56%

Status of coverage: 🟢 - ok, 🟡 - slightly more than threshold, 🔴 - under the threshold

@ascibisz ascibisz force-pushed the admin/wss-for-octopus branch from 075236e to 3002aed Compare December 1, 2023 00:41
@ascibisz ascibisz changed the base branch from admin/wss-for-octopus to main December 1, 2023 00:48
@ascibisz ascibisz marked this pull request as ready for review December 1, 2023 01:04
@ascibisz ascibisz requested a review from a team as a code owner December 1, 2023 01:04
@ascibisz ascibisz requested review from toloudis, meganrm, frasercl, blairlyons, interim17 and ShrimpCryptid and removed request for a team December 1, 2023 01:04
@@ -313,7 +316,7 @@ export class WebsocketClient {
jsonData: Record<string, unknown>,
requestDescription: string
): void {
if (this.socketIsValid()) {
if (this.socketIsConnected()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran into this issue when testing where the socket can be "valid" (which means the websocket's state isn't CLOSED), but not "connected" (which means the websocket's state is OPEN) if the state is PENDING, in which case sending a message throws an error. I feel like this check is trying to prevent that error, so might as well cover the PENDING case too?

@interim17
Copy link
Contributor

Can confirm I just got this working in a preliminary way in the website! More work to clean up the front end before PR but the viewer side is doing what it should do. LGTM, thanks @ascibisz !
Screenshot 2023-12-01 at 12 10 03 PM

Comment on lines 424 to 432
netConnectionConfig: NetConnectionParams
): void {
if (
!this.simulator ||
!(this.simulator instanceof RemoteSimulator) ||
!this.simulator.socketIsValid()
) {
// Only configure network if we aren't already connected to the remote server
this.configureNetwork(netConnectionConfig);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels a bit funny to have to pass the config in every time we make a check, it looks redundant on the front-end, but it does ensure we aren't querying an un-configured controller that won't respond.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it does sort of make sense that you might want to check health before a connection was made.

}
if (this.simulator && this.simulator instanceof RemoteSimulator) {
this.simulator.setHealthCheckHandler(handler);
this.simulator.checkServerHealth();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should checkServerHealth accept a callback as an arg instead of having a separate setter? Are they always called together like this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see why they are separate now, because of the message passing and receiving.

@@ -47,6 +47,9 @@ export const enum NetMessageEnum {
ID_AVAILABLE_METRICS_RESPONSE = 18,
ID_PLOT_DATA_REQUEST = 19,
ID_PLOT_DATA_RESPONSE = 20,
ID_ERROR_MSG = 21,
ID_CHECK_HEALTH_REQUEST = 22,
ID_SERVER_HEALTHY_RESPONSE = 23,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there any documentation in this repo for what these messages are supposed to mean, or their payload schema? (One thing that is nice to know is whether it's intended to go from client to server or vice versa)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There isn't... I do have it fairly well documentation in the Octopus repo though, so I should probably copy that over

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realize it's not great that it would have to be kept up in two places but it's also true that if it changes in octopus, then something would have to change over here too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah and that's true of the message types themselves. We're already in a slightly weird situation, may as well have it be a better documented weird situation!

Copy link
Contributor

@toloudis toloudis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a bunch of comments but basically this seems ok. I would love to clean up the connection logic but probably out of scope for this.

Comment on lines 460 to 462
.catch((e) => {
throw new FrontEndError(e.message, ErrorLevel.ERROR);
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Questions about error handling.

UX request is that if "server is down" we throw a styled modal.

But if the viewer can't connect this error also generates up a full screen React runtime error.

Removing this error handling yields the behavior UX asked for (just a modal), but is that not proper error handling?

@ascibisz ascibisz merged commit e3ab563 into main Dec 6, 2023
6 checks passed
@ascibisz ascibisz deleted the feature/server-health-check branch December 6, 2023 17:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants