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

[public-api] add request context #18853

Merged
merged 5 commits into from
Oct 4, 2023
Merged

Conversation

akosyakov
Copy link
Member

@akosyakov akosyakov commented Oct 2, 2023

Description

  • This PR enhances the Public API on the server by adding log context support.
  • It introduces warning logs for unary calls exceeding 100ms, using 'getLoggedInUser' in JSON-RPC as a benchmark.
  • Additionally, it fixes a leak in server streams.
Summary generated by Copilot

🤖 Generated by Copilot at 7f9d889

This pull request refactors the server API and util modules to improve logging and error handling of gRPC calls. It adds request IDs and logging context to the server API, and removes unnecessary async and await keywords from the util module.

Related Issue(s)

Fixes #

How to test

  • Enable debug log on server.
  • Open a workspace and start a workspace.
  • Inspect server logs for public-api: done.

Documentation

Preview status

Gitpod was successfully deployed to your preview environment.

Build Options

Build
  • /werft with-werft
    Run the build with werft instead of GHA
  • leeway-no-cache
  • /werft no-test
    Run Leeway with --dont-test
Publish
  • /werft publish-to-npm
  • /werft publish-to-jb-marketplace
Installer
  • analytics=segment
  • with-dedicated-emulation
  • workspace-feature-flags
    Add desired feature flags to the end of the line above, space separated
Preview Environment / Integration Tests
  • /werft with-local-preview
    If enabled this will build install/preview
  • /werft with-preview
  • /werft with-large-vm
  • /werft with-gce-vm
    If enabled this will create the environment on GCE infra
  • with-integration-tests=all
    Valid options are all, workspace, webapp, ide, jetbrains, vscode, ssh. If enabled, with-preview and with-large-vm will be enabled.
  • with-monitoring

/hold

@akosyakov
Copy link
Member Author

akosyakov commented Oct 2, 2023

/gh run recreate-vm=true

Comment triggered a workflow run

Started workflow run: 6382224387

  • recreate_vm: true

@akosyakov
Copy link
Member Author

akosyakov commented Oct 4, 2023

/gh run recreate-vm=true

Comment triggered a workflow run

Started workflow run: 6404429130

  • recreate_vm: true

@roboquat roboquat added size/L and removed size/M labels Oct 4, 2023
@@ -13,7 +12,7 @@ const commit = require("./config.json").commit;
const originalConsoleError = console.error;

const metricsReporter = new MetricsReporter({
gitpodUrl: new GitpodHostUrl(window.location.href).withoutWorkspacePrefix().toString(),
gitpodUrl: window.location.href,
Copy link
Member Author

Choose a reason for hiding this comment

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

it was a bug introduced with recent changes

Copy link
Member Author

Choose a reason for hiding this comment

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

it does not break in gitpod.io but on preview envs trimming prefix breaks host

grpc_service: string;
grpc_method: string;
} = {
contextTimeMs: performance.now(),
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm capturing it here because otherwise i cannot handle async generators propely

async function call<T>(): Promise<T> {

const apply = async <T>(): Promise<T> => {
const verifyStartedAt = performance.now();
const user = await self.verify(context);
Copy link
Member Author

Choose a reason for hiding this comment

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

I was wondering rather add a warning and more fine grain logging inside verify generally. But i worry about negative impact form logging itself. It is probably the hottest path.

callMs = performance.now() - callStartedAt;
}
log.debug("public api: done", { grpc_code, verifyMs, callMs });
// right now p99 for getLoggetInUser is around 100ms, using it as a threshold for now
Copy link
Member Author

@akosyakov akosyakov Oct 4, 2023

Choose a reason for hiding this comment

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

this is going to be removed as soon as we figure out the issue

@@ -24,7 +24,7 @@ export class APIHelloService implements ServiceImpl<typeof HelloService> {
}
async *lotsOfReplies(req: LotsOfRepliesRequest, context: HandlerContext): AsyncGenerator<LotsOfRepliesResponse> {
let count = req.previousCount || 0;
while (true) {
while (!context.signal.aborted) {
Copy link
Member Author

Choose a reason for hiding this comment

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

it was a bug and we were leaking server streams here

@akosyakov akosyakov marked this pull request as ready for review October 4, 2023 12:32
@akosyakov akosyakov requested a review from a team as a code owner October 4, 2023 12:32
Copy link
Member

@geropl geropl left a comment

Choose a reason for hiding this comment

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

Code LGTM, tested and works ✔️

@akosyakov
Copy link
Member Author

/unhold

@roboquat roboquat merged commit 522dbfb into main Oct 4, 2023
48 checks passed
@roboquat roboquat deleted the ak/public_api_request_context branch October 4, 2023 12:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants