-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Make routes in back-end comply to Open Closed Principle #4859
Conversation
265654c
to
eecd4d5
Compare
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
cf53336
to
5c8ae0b
Compare
Conflicts have been resolved. A maintainer will review the pull request shortly. |
5c8ae0b
to
f23e559
Compare
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.
Didn't run the app, but code LGTM.
src/main/router.ts
Outdated
import logger from "./logger"; | ||
import type { LensApiResultContentType } from "./router-content-types"; | ||
import { contentTypes } from "./router-content-types"; | ||
import "../common/vars"; |
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.
Why do we need import whole package without using anything locally from it?
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.
My question exactly... There is side-effect in common/vars
which defines __static
and therefore is required. Something that is of course wrong, but out of scope in this PR.
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.
Maybe add comment/todo so that next reader knows why it's there?
@@ -326,6 +326,7 @@ | |||
"@typescript-eslint/eslint-plugin": "^5.10.1", | |||
"@typescript-eslint/parser": "^5.10.1", | |||
"ansi_up": "^5.1.0", | |||
"mock-http": "^1.1.0", |
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.
Why do we need this package / extra dependency? Can we live without it?
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.
At the moment, no.
Get rid of IncomingMessage and http.ServerResponse interface from router so that new routes can be unit tested easily even when using router in tests.
However, we can after this.
@@ -108,7 +108,7 @@ export async function upgradeRelease(name: string, chart: string, values: any, n | |||
|
|||
return { | |||
log: output, | |||
release: getRelease(name, namespace, kubeconfigPath, kubectlPath), | |||
release: await getRelease(name, namespace, kubeconfigPath, kubectlPath), |
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.
Noticed no catch
in this try...finally
, will await getRelease
throw? Or error is caught and handled somewhere else?
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.
Key difference here is that all back-end API responds go through same place which already catches fatal errors. That being said, if it fails fatally, API call is resolved with status code 422
and error message. And in this case, there is no non-fatal error to be handled. Goal is to get rid of try-catches in operational code for good (strategic places that handle errors for everything to allow error monitoring etc). Throwing is mechanism that is reserved for fatal errors which should prevent code to be executed and for non fatal errors we have better alternatives.
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
95d9152
to
ae0ecc5
Compare
Conflicts have been resolved. A maintainer will review the pull request shortly. |
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
Conflicts have been resolved. A maintainer will review the pull request shortly. |
src/main/router.ts
Outdated
interface Dependencies { | ||
routePortForward: (request: LensApiRequest) => Promise<void>; | ||
parseRequest: (request: http.IncomingMessage, _: null, options: { parse: boolean; output: string }) => Promise<{ payload: any }>; |
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.
why even have the second param?
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.
It's third-party library.
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.
Yeah but we can wrap it if we want
src/main/router.ts
Outdated
writeServerResponse(mappedResult); | ||
}; | ||
|
||
const writeServerResponseFor = |
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.
nit, all this extra whitespace makes it harder to read. Could this be a normal function or at least add some ()
?
|
||
instantiate: (): Route<GetChartResponse> => ({ | ||
method: "get", | ||
path: `${apiPrefix}/v2/charts/{repo}/{chart}`, |
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 have (what I think) is a pretty cool idea of how to make sure that this string is "correctly typed" with regards to the interface that Params
expects below but we can do that later.
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
…t interesting Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
Conflicts have been resolved. A maintainer will review the pull request shortly. |
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.
LGTM
Motivation:
Solution:
Introduce
routeInjectionToken
which any back-end route can implement by addinginjectionToken: routeInjectionToken
. Any injectable implementing saidinjectionToken
will be registered automatically.Note: base-branch is PR #4842 so let's get that merged first.
TBD later:
IncomingMessage
andhttp.ServerResponse
interface from router so that new routes can be unit tested easily even when using router in tests.