Skip to content

[fga] Devx improvements #18574

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

Merged
merged 2 commits into from
Aug 23, 2023
Merged
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
15 changes: 15 additions & 0 deletions components/BUILD.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,20 @@ scripts:
query="update d_b_user set blocked=0 where name=\"$user\";"
mysql -e "$query" -u$DB_USERNAME -p$DB_PASSWORD -h 127.0.0.1 gitpod
fi

printf "\nFGA: Reset fgaRelationshipsVersion for $user...\n"
query="update d_b_user set additionalData = JSON_REMOVE(additionalData, '$.fgaRelationshipsVersion') where name=\"$user\";"
mysql -e "$query" -u$DB_USERNAME -p$DB_PASSWORD -h 127.0.0.1 gitpod
if [ $? -ne 0 ]; then
echo "error resetting fgaRelationshipsVersion"
kill $PID || true
exit 1
fi
kill $PID || true

printf "\nRestarting server and redis to pick up DB changes...\n"
kubectl rollout restart deployment/server deployment/redis
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder why we decide to put such longer bash scripts into the leeway yaml? Woudln't it be better to have such scripts written in bash files somewhere and jsut called here (if that is at all necessary)?

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 don't know. There's not much advantages I can think of, and some downsides.


- name: make-user-admin
deps:
- components/service-waiter:app
Expand Down Expand Up @@ -261,6 +273,9 @@ scripts:
fi
kill $PID || true

printf "\nRestarting server and redis to pick up DB changes...\n"
kubectl rollout restart deployment/server deployment/redis

- name: add-smith-token
deps:
- components/service-waiter:app
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import { newAlwaysReturningDefaultValueClient } from "./always-default";

let client: Client | undefined;

export type ConfigCatClientFactory = () => Client;
export const ConfigCatClientFactory = Symbol("ConfigCatClientFactory");
export namespace Experiments {
export function configureTestingClient(config: Record<string, any>): void {
client = {
Expand Down Expand Up @@ -54,6 +52,6 @@ export function getExperimentsClientForBackend(): Client {
baseUrl: process.env.CONFIGCAT_BASE_URL,
});

client = new ConfigCatClient(configCatClient);
client = new ConfigCatClient(configCatClient, process.env.HOST_URL);
return client;
}
15 changes: 9 additions & 6 deletions components/gitpod-protocol/src/experiments/configcat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@ export const BILLING_TIER_ATTRIBUTE = "billing_tier";
export const GITPOD_HOST = "gitpod_host";

export class ConfigCatClient implements Client {
private client: IConfigCatClient;

constructor(cc: IConfigCatClient) {
this.client = cc;
}
constructor(private readonly client: IConfigCatClient, private readonly gitpodHost?: string) {}

getValueAsync<T>(experimentName: string, defaultValue: T, attributes: Attributes): Promise<T> {
return this.client.getValueAsync(experimentName, defaultValue, attributesToUser(attributes));
return this.client.getValueAsync(
experimentName,
defaultValue,
attributesToUser({
gitpodHost: this.gitpodHost,
...attributes,
}),
);
}

dispose(): void {
Expand Down
5 changes: 2 additions & 3 deletions components/server/src/auth/verification-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,17 @@ import { Config } from "../config";
import { Twilio } from "twilio";
import { ServiceContext } from "twilio/lib/rest/verify/v2/service";
import { TeamDB, UserDB, WorkspaceDB } from "@gitpod/gitpod-db/lib";
import { ConfigCatClientFactory } from "@gitpod/gitpod-protocol/lib/experiments/configcat-server";
import { ErrorCodes, ApplicationError } from "@gitpod/gitpod-protocol/lib/messaging/error";
import { VerificationInstance } from "twilio/lib/rest/verify/v2/service/verification";
import { v4 as uuidv4, validate as uuidValidate } from "uuid";
import { getExperimentsClientForBackend } from "@gitpod/gitpod-protocol/lib/experiments/configcat-server";

@injectable()
export class VerificationService {
@inject(Config) protected config: Config;
@inject(WorkspaceDB) protected workspaceDB: WorkspaceDB;
@inject(UserDB) protected userDB: UserDB;
@inject(TeamDB) protected teamDB: TeamDB;
@inject(ConfigCatClientFactory) protected readonly configCatClientFactory: ConfigCatClientFactory;

protected verifyService: ServiceContext;

Expand All @@ -45,7 +44,7 @@ export class VerificationService {
if (user.creationDate < "2022-08-22") {
return false;
}
const isPhoneVerificationEnabled = await this.configCatClientFactory().getValueAsync(
const isPhoneVerificationEnabled = await getExperimentsClientForBackend().getValueAsync(
"isPhoneVerificationEnabled",
false,
{
Expand Down
10 changes: 0 additions & 10 deletions components/server/src/container-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
import { ContainerModule } from "inversify";

import { IAnalyticsWriter } from "@gitpod/gitpod-protocol/lib/analytics";
import {
ConfigCatClientFactory,
getExperimentsClientForBackend,
} from "@gitpod/gitpod-protocol/lib/experiments/configcat-server";
import { GitpodFileParser } from "@gitpod/gitpod-protocol/lib/gitpod-file-parser";
import { PrometheusClientCallMetrics } from "@gitpod/gitpod-protocol/lib/messaging/client-call-metrics";
import { newAnalyticsWriterFromEnv } from "@gitpod/gitpod-protocol/lib/util/analytics";
Expand Down Expand Up @@ -296,12 +292,6 @@ export const productionContainerModule = new ContainerModule(
})
.inSingletonScope();

bind(ConfigCatClientFactory)
.toDynamicValue((ctx) => {
return () => getExperimentsClientForBackend();
})
.inSingletonScope();

bind(VerificationService).toSelf().inSingletonScope();

bind(UsageService).toSelf().inSingletonScope();
Expand Down
4 changes: 0 additions & 4 deletions components/server/src/ide-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

import { IDESettings, TaskConfig, User, Workspace } from "@gitpod/gitpod-protocol";
import { ConfigCatClientFactory } from "@gitpod/gitpod-protocol/lib/experiments/configcat-server";
import { IDEClient, IDEOptions } from "@gitpod/gitpod-protocol/lib/ide-protocol";
import * as IdeServiceApi from "@gitpod/ide-service-api/lib/ide.pb";
import {
Expand All @@ -29,9 +28,6 @@ export class IDEService {
@inject(AuthorizationService)
protected readonly authService: AuthorizationService;

@inject(ConfigCatClientFactory)
protected readonly configCatClientFactory: ConfigCatClientFactory;

private cacheConfig?: IDEConfig;

async getIDEConfig(request: { user: { id: string; email?: string } }): Promise<IDEConfig> {
Expand Down
11 changes: 3 additions & 8 deletions components/server/src/workspace/gitpod-server-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,7 @@ import { IDEService } from "../ide-service";
import { AttributionId } from "@gitpod/gitpod-protocol/lib/attribution";
import { CostCenterJSON } from "@gitpod/gitpod-protocol/lib/usage";
import { createCookielessId, maskIp } from "../analytics";
import {
ConfigCatClientFactory,
getExperimentsClientForBackend,
} from "@gitpod/gitpod-protocol/lib/experiments/configcat-server";
import { getExperimentsClientForBackend } from "@gitpod/gitpod-protocol/lib/experiments/configcat-server";
import { increaseDashboardErrorBoundaryCounter } from "../prometheus-metrics";
import { LinkedInService } from "../linkedin-service";
import { SnapshotService, WaitForSnapshotOptions } from "./snapshot-service";
Expand Down Expand Up @@ -235,8 +232,6 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
@inject(VerificationService) private readonly verificationService: VerificationService,
@inject(EntitlementService) private readonly entitlementService: EntitlementService,

@inject(ConfigCatClientFactory) private readonly configCatClientFactory: ConfigCatClientFactory,

@inject(Authorizer) private readonly auth: Authorizer,

@inject(BillingModes) private readonly billingModes: BillingModes,
Expand Down Expand Up @@ -672,7 +667,7 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
const user = await this.checkUser("sendPhoneNumberVerificationToken");

// Check if verify via call is enabled
const phoneVerificationByCall = await this.configCatClientFactory().getValueAsync(
const phoneVerificationByCall = await getExperimentsClientForBackend().getValueAsync(
"phoneVerificationByCall",
false,
{
Expand Down Expand Up @@ -3178,7 +3173,7 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {

private async guardWithFeatureFlag(flagName: string, user: User, teamId: string) {
// Guard method w/ a feature flag check
const isEnabled = await this.configCatClientFactory().getValueAsync(flagName, false, {
const isEnabled = await getExperimentsClientForBackend().getValueAsync(flagName, false, {
user: user,
teamId,
});
Expand Down