Skip to content

Inject new IApplicationCluster dependency into server and wsman-bridge #14084

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions components/server/src/container-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { EnvvarPrefixParser } from "./workspace/envvar-prefix-context-parser";
import {
IWorkspaceManagerClientCallMetrics,
WorkspaceManagerClientProvider,
IApplicationClusterProvider,
} from "@gitpod/ws-manager/lib/client-provider";
import {
WorkspaceManagerClientProviderCompositeSource,
Expand Down Expand Up @@ -208,6 +209,7 @@ export const productionContainerModule = new ContainerModule((bind, unbind, isBo

bind(TracingManager).toSelf().inSingletonScope();

bind(IApplicationClusterProvider).toDynamicValue(newApplicationClusterProvider).inSingletonScope();
bind(WorkspaceManagerClientProvider).toSelf().inSingletonScope();
bind(WorkspaceManagerClientProviderCompositeSource).toSelf().inSingletonScope();
bind(WorkspaceManagerClientProviderSource).to(WorkspaceManagerClientProviderEnvSource).inSingletonScope();
Expand Down Expand Up @@ -299,3 +301,9 @@ export const productionContainerModule = new ContainerModule((bind, unbind, isBo

bind(UsageService).toSelf().inSingletonScope();
});

function newApplicationClusterProvider(): IApplicationClusterProvider {
return {
getApplicationCluster: () => process.env.GITPOD_INSTALLATION_SHORTNAME ?? "",
Copy link
Member

Choose a reason for hiding this comment

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

Can we read from Config here? See here for an example.

};
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
ImageBuilderClientProvider,
PromisifiedImageBuilderClient,
} from "@gitpod/image-builder/lib";
import { WorkspaceManagerClientProvider } from "@gitpod/ws-manager/lib/client-provider";
import { IApplicationClusterProvider, WorkspaceManagerClientProvider } from "@gitpod/ws-manager/lib/client-provider";
import {
WorkspaceManagerClientProviderCompositeSource,
WorkspaceManagerClientProviderSource,
Expand All @@ -27,6 +27,9 @@ export class WorkspaceClusterImagebuilderClientProvider implements ImageBuilderC
@inject(WorkspaceManagerClientProvider) protected readonly clientProvider: WorkspaceManagerClientProvider;
@inject(ImageBuilderClientCallMetrics) @optional() protected readonly clientCallMetrics: IClientCallMetrics;

@inject(IApplicationClusterProvider)
protected readonly _applicationClusterProvider: IApplicationClusterProvider;

// gRPC connections can be used concurrently, even across services.
// Thus it makes sense to cache them rather than create a new connection for each request.
protected readonly connectionCache = new Map<string, ImageBuilderClient>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import "reflect-metadata";
import { Container } from "inversify";
import { suite, test } from "@testdeck/mocha";
import * as chai from "chai";
import { IWorkspaceClusterStartSet, WorkspaceManagerClientProvider } from "./client-provider";
import {
IApplicationClusterProvider,
IWorkspaceClusterStartSet,
WorkspaceManagerClientProvider,
} from "./client-provider";
import {
WorkspaceManagerClientProviderCompositeSource,
WorkspaceManagerClientProviderSource,
Expand All @@ -26,6 +30,10 @@ class TestClientProvider {

public before() {
const c = new Container();
c
.bind(IApplicationClusterProvider)
.toDynamicValue((): IApplicationClusterProvider => ({ getApplicationCluster: () => "xx01" }))
.inSingletonScope;
c.bind(WorkspaceManagerClientProvider).toSelf().inSingletonScope();
c.bind(WorkspaceManagerClientProviderCompositeSource).toSelf().inSingletonScope();
c.bind(WorkspaceManagerClientProviderSource)
Expand Down
8 changes: 8 additions & 0 deletions components/ws-manager-api/typescript/src/client-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ import { linearBackoffStrategy, PromisifiedWorkspaceManagerClient } from "./prom

export const IWorkspaceManagerClientCallMetrics = Symbol("IWorkspaceManagerClientCallMetrics");

export const IApplicationClusterProvider = Symbol("IApplicationClusterProvider");
export interface IApplicationClusterProvider {
getApplicationCluster: () => string;
}

@injectable()
export class WorkspaceManagerClientProvider implements Disposable {
@inject(WorkspaceManagerClientProviderCompositeSource)
Expand All @@ -30,6 +35,9 @@ export class WorkspaceManagerClientProvider implements Disposable {
@optional()
protected readonly clientCallMetrics: IClientCallMetrics;

@inject(IApplicationClusterProvider)
protected readonly _applicationClusterProvider: IApplicationClusterProvider;

// gRPC connections maintain their connectivity themselves, i.e. they reconnect when neccesary.
// They can also be used concurrently, even across services.
// Thus it makes sense to cache them rather than create a new connection for each request.
Expand Down
8 changes: 8 additions & 0 deletions components/ws-manager-bridge/src/container-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { filePathTelepresenceAware } from "@gitpod/gitpod-protocol/lib/env";
import {
WorkspaceManagerClientProvider,
IWorkspaceManagerClientCallMetrics,
IApplicationClusterProvider,
} from "@gitpod/ws-manager/lib/client-provider";
import {
WorkspaceManagerClientProviderCompositeSource,
Expand Down Expand Up @@ -51,6 +52,7 @@ export const containerModule = new ContainerModule((bind) => {
bind(IClientCallMetrics).to(PrometheusClientCallMetrics).inSingletonScope();
bind(IWorkspaceManagerClientCallMetrics).toService(IClientCallMetrics);

bind(IApplicationClusterProvider).toDynamicValue(newApplicationClusterProvider).inSingletonScope();
bind(WorkspaceManagerClientProvider).toSelf().inSingletonScope();
bind(WorkspaceManagerClientProviderCompositeSource).toSelf().inSingletonScope();
bind(WorkspaceManagerClientProviderSource).to(WorkspaceManagerClientProviderConfigSource).inSingletonScope();
Expand Down Expand Up @@ -96,3 +98,9 @@ export const containerModule = new ContainerModule((bind) => {
// transient to make sure we're creating a separate instance every time we ask for it
bind(WorkspaceInstanceController).to(WorkspaceInstanceControllerImpl).inTransientScope();
});

function newApplicationClusterProvider(): IApplicationClusterProvider {
return {
getApplicationCluster: () => process.env.GITPOD_INSTALLATION_SHORTNAME ?? "",
};
}