-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[dashboard/protocol] Pass slow-database
Sec-WebSocket-Protocol
header to websocket connections from dashboard
#14752
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ import { log } from "@gitpod/gitpod-protocol/lib/util/logging"; | |
|
||
export const gitpodHostUrl = new GitpodHostUrl(window.location.toString()); | ||
|
||
function createGitpodService<C extends GitpodClient, S extends GitpodServer>() { | ||
function createGitpodService<C extends GitpodClient, S extends GitpodServer>(useSlowDatabase: boolean = false) { | ||
if (window.top !== window.self && process.env.NODE_ENV === "production") { | ||
const connection = createWindowMessageConnection("gitpodServer", window.parent, "*"); | ||
const factory = new JsonRpcProxyFactory<S>(); | ||
|
@@ -48,6 +48,7 @@ function createGitpodService<C extends GitpodClient, S extends GitpodServer>() { | |
onListening: (socket) => { | ||
onReconnect = () => socket.reconnect(); | ||
}, | ||
subProtocol: useSlowDatabase ? "slow-database" : undefined, | ||
}); | ||
|
||
return new GitpodServiceImpl<C, S>(proxy, { onReconnect }); | ||
|
@@ -64,4 +65,13 @@ function getGitpodService(): GitpodService { | |
return service; | ||
} | ||
|
||
export { getGitpodService }; | ||
function initGitPodService(useSlowDatabase: boolean) { | ||
const w = window as any; | ||
const _gp = w._gp || (w._gp = {}); | ||
if (window.location.search.includes("service=mock")) { | ||
_gp.gitpodService = require("./service-mock").gitpodServiceMock; | ||
} | ||
_gp.gitpodService = createGitpodService(useSlowDatabase); | ||
} | ||
|
||
export { getGitpodService, initGitPodService }; | ||
Comment on lines
+68
to
+77
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would you be able to explain why we're doing this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function re-initializes the websocket connection - ie makes a new connection. The We want to be able to create a brand new connection on demand when the value of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks. Do we need the mock logic in there? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably not - I took it from |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to cause a bootstrap problem. We don't know who the user is (to evaluate the feature flag), but we're creating the connection which is parametrized on the feature flag (by user). I suspect this would result in always using "false" for the slow database argument
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The value of
useSlowDatabase
is taken from theFeatureFlagContext
. All feature flags are re-evaluated when the value ofuser
changes (the dependency array in the effect includesuser
):gitpod/components/dashboard/src/contexts/FeatureFlagContext.tsx
Lines 47 to 85 in 46c6722
Whenever the context sets the value of
useSlowDatabase
(as it will whenever the effect runs) it causes any component that consumes the context to re-render, and the dependency array in theuseEffect
here ensures that we re-initialize the websocket connection wheneverApp
renders.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess with this change, we might see nearly double the WS connections being created. Just something we should be aware of from ops side
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we'll only see two connections for the small subset of users for which the feature flag is enabled.
For everyone else, the value of
useSlowDatabase
will never change and the connection will never be re-initialized.