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] aligns with latest guidelines #19038

Merged
merged 1 commit into from
Nov 14, 2023
Merged

Conversation

akosyakov
Copy link
Member

@akosyakov akosyakov commented Nov 8, 2023

Description

This PR aligns API definition and implementation with our latest guidelines.

Summary generated by Copilot

🤖 Generated by Copilot at 27a002d

This pull request updates the protobuf files and the generated code for the public API of Gitpod, to use FieldMask for partial updates, to remove optional keywords from proto3 fields, and to fix some inconsistencies and errors in the types and default values.

Related Issue(s)

Fixes #

How to test

Test that you can update org name, workspace sharing, default image, and membership without issues.

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 akosyakov force-pushed the ak/only_optional_in_update branch 4 times, most recently from 37e26af to 27c1691 Compare November 8, 2023 21:41
@roboquat roboquat added size/L and removed size/M labels Nov 8, 2023
@akosyakov akosyakov force-pushed the ak/only_optional_in_update branch 3 times, most recently from a8bd622 to 80888c3 Compare November 9, 2023 20:28
@roboquat roboquat added size/XL and removed size/L labels Nov 9, 2023
@akosyakov akosyakov force-pushed the ak/only_optional_in_update branch 4 times, most recently from f3e41f8 to da87c39 Compare November 10, 2023 09:32
@roboquat roboquat added size/XXL and removed size/XL labels Nov 10, 2023
@akosyakov akosyakov force-pushed the ak/only_optional_in_update branch from da87c39 to ce5e2de Compare November 10, 2023 09:32
@akosyakov akosyakov changed the title [public-api] only allow optional in update [public-api] aligns with latest guidelines Nov 10, 2023
@akosyakov akosyakov force-pushed the ak/only_optional_in_update branch 3 times, most recently from ffb60d1 to d1b69a9 Compare November 10, 2023 09:52
@roboquat roboquat added size/XL and removed size/XXL labels Nov 10, 2023
@akosyakov akosyakov force-pushed the ak/only_optional_in_update branch from d1b69a9 to a68f17f Compare November 10, 2023 11:19
@roboquat roboquat added size/XXL and removed size/XL labels Nov 10, 2023
@akosyakov akosyakov force-pushed the ak/only_optional_in_update branch from 95065d2 to 6af5924 Compare November 10, 2023 17:15
@akosyakov
Copy link
Member Author

akosyakov commented Nov 13, 2023

/gh run recreate-vm=true

Comment triggered a workflow run

Started workflow run: 6847733871

  • recreate_vm: true

@akosyakov akosyakov marked this pull request as ready for review November 13, 2023 10:12
@akosyakov akosyakov requested a review from a team as a code owner November 13, 2023 10:12
optional string avatar_url = 4;
optional string full_name = 5;
optional string email = 6;
string avatar_url = 4;
Copy link
Member Author

Choose a reason for hiding this comment

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

in this file I drop optional keywords from everywhere but to make update calls partial

@@ -19,15 +19,15 @@ service WorkspaceService {
rpc WatchWorkspaceStatus(WatchWorkspaceStatusRequest) returns (stream WatchWorkspaceStatusResponse) {}
}

message GetWorkspaceRequest { string id = 1; }
message GetWorkspaceRequest { string workspace_id = 1; }
Copy link
Member Author

Choose a reason for hiding this comment

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

fixing field name conventions + drop optional keywords from everywhere

@@ -366,28 +366,19 @@ export class TeamDBImpl extends TransactionalDBImpl<TeamDB> implements TeamDB {
});
}

public async setOrgSettings(orgId: string, settings: Partial<OrganizationSettings>): Promise<void> {
public async setOrgSettings(orgId: string, settings: Partial<OrganizationSettings>): Promise<OrganizationSettings> {
Copy link
Member Author

Choose a reason for hiding this comment

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

moving logic into service from DB, making sure that update returns updated data

@@ -37,41 +36,18 @@ export namespace ApplicationError {
throw e;
}
}

export function fromGRPCError(e: any, data?: any): ApplicationError {
Copy link
Member Author

Choose a reason for hiding this comment

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

we should never mindlessly pump error like that, we should do proper translation and if we cannot translate use INTERNAL to iterate on it

@@ -24,7 +23,7 @@ export class ApplicationError extends Error {

export namespace ApplicationError {
export function hasErrorCode(e: any): e is Error & { code: ErrorCode; data?: any } {
return e && e.code !== undefined;
return ErrorCode.is(e["code"]);
Copy link
Member Author

Choose a reason for hiding this comment

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

not all errors with code are ApplicationError, we will consider in the past some typeorm and Node.js errors as AppilcationErorrs, while they should be Internal

@@ -5,6 +5,8 @@ breaking:
ignore:
# Do not enforce breaking change detection for the experimental package
- gitpod/experimental
# TODO enable again after landing style changes
- gitpod/v1
Copy link
Member Author

Choose a reason for hiding this comment

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

temporary since we are still using JSON-RPC shim

* See License.AGPL.txt in the project root for license information.
*/

export type DefaultWorkspaceImageValidator = (userId: string, imageRef: string) => Promise<void>;
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 moved defaulta wokrspace image validation to organizaion-service, but then it depends on workspace-service. So decouple it we use an intermediate service with lazy loading.

@@ -2358,9 +2358,6 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
const user = await this.checkAndBlockUser("updateOrgSettings");
traceAPIParams(ctx, { orgId, userId: user.id });
await this.guardTeamOperation(orgId, "update");
if (settings.defaultWorkspaceImage?.trim()) {
Copy link
Member Author

Choose a reason for hiding this comment

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

we forgot to move while doing org migration

@@ -282,7 +282,7 @@ function WorkspaceImageButton(props: {
};
}

const image = props.settings?.defaultWorkspaceImage ?? props.defaultWorkspaceImage ?? "";
const image = props.settings?.defaultWorkspaceImage || props.defaultWorkspaceImage || "";
Copy link
Member Author

Choose a reason for hiding this comment

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

This one is potentially breaking for old dashboard against new server, but affect is not significant and resolved by the page reload.

Ideally we need to deliver Huiwen's PR to stop worrying about it.

Copy link
Member Author

Choose a reason for hiding this comment

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

We discussed that a risk is pretty low, given that update is very rare operation and we deploy to cells in non working hours. Anyway we wait today for #19042 and if it takes longer then we land this one. cc @mustard-mh

Copy link
Member Author

Choose a reason for hiding this comment

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

@mustard-mh I thinkg there is not problem actually, JSON-RPC is backward compatible, i.e. returns undefined value and old dashboard is going to use old gRPC types with optional, so it should not break, does it make sense?

@akosyakov akosyakov force-pushed the ak/only_optional_in_update branch from 6af5924 to 9d28cf8 Compare November 13, 2023 11:36
if (!uuidValidate(req.organizationId)) {
throw new ConnectError("organizationId is required", Code.InvalidArgument);
}
if (typeof req.name !== "string") {
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't allow empty name?

let message = details;
// strip confusing prefix
if (details.startsWith("cannt resolve base image ref: ")) {
message = details.substring("cannt resolve base image ref: ".length);
Copy link
Contributor

@mustard-mh mustard-mh Nov 13, 2023

Choose a reason for hiding this comment

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

Respond code with be something else, see test case which use it

nit-fixing since it doesn't break UX

image

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 not sure what I should change?

Copy link
Contributor

@mustard-mh mustard-mh Nov 14, 2023

Choose a reason for hiding this comment

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

Based on the code you added, you want to remove the prefix cannot resolve image but it will not match since the respond rpc code is not grpc.status.INVALID_ARGUMENT

Nope, I read it wrong. Sorry for confusing

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 think it is covered because it is || not &&, but I agree though that explicit check for NOT_FOUND and UNAUTHORIZED makes sense here too.

We need generally align how we propagate errors thorugh the system and we don't break contracts.

@mustard-mh
Copy link
Contributor

Test with preview env, LGTM

/hold in case you want to fix comments above or wait #19042 to be deployed

@akosyakov
Copy link
Member Author

/unhold

@roboquat roboquat merged commit 0ec0037 into main Nov 14, 2023
16 checks passed
@roboquat roboquat deleted the ak/only_optional_in_update branch November 14, 2023 11:09
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.

4 participants