Skip to content

Commit

Permalink
Merge branch 'main' into jetbrains/phpstorm-221-5591-58
Browse files Browse the repository at this point in the history
  • Loading branch information
andreafalzetti authored May 17, 2022
2 parents e22a239 + 0780270 commit b147a29
Show file tree
Hide file tree
Showing 26 changed files with 313 additions and 28 deletions.
2 changes: 1 addition & 1 deletion WORKSPACE.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ defaultArgs:
jetbrainsBackendQualifier: stable
intellijDownloadUrl: "https://download.jetbrains.com/idea/ideaIU-2022.1.1.tar.gz"
golandDownloadUrl: "https://download.jetbrains.com/go/goland-2022.1.tar.gz"
pycharmDownloadUrl: "https://download.jetbrains.com/python/pycharm-professional-2022.1.tar.gz"
pycharmDownloadUrl: "https://download.jetbrains.com/python/pycharm-professional-2022.1.1.tar.gz"
phpstormDownloadUrl: "https://download.jetbrains.com/webide/PhpStorm-2022.1.1.tar.gz"
provenance:
enabled: true
Expand Down
1 change: 1 addition & 0 deletions components/BUILD.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ packages:
- components/supervisor-api/typescript-grpc:publish
- components/supervisor-api/typescript-grpcweb:publish
- components/ide/jetbrains/gateway-plugin:publish
- components/public-api/typescript:publish
- name: all-apps
type: generic
deps:
Expand Down
3 changes: 3 additions & 0 deletions components/common-go/baseserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/health/grpc_health_v1"
"google.golang.org/grpc/reflection"
)

func New(name string, opts ...Option) (*Server, error) {
Expand Down Expand Up @@ -291,6 +292,8 @@ func (s *Server) initializeGRPC() error {

s.grpc = grpc.NewServer(opts...)

reflection.Register(s.grpc)

// Register health service by default
grpc_health_v1.RegisterHealthServer(s.grpc, s.options.grpcHealthCheck)

Expand Down
1 change: 1 addition & 0 deletions components/dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"private": true,
"dependencies": {
"@gitpod/gitpod-protocol": "0.1.5",
"configcat-js": "^5.7.2",
"countries-list": "^2.6.1",
"js-cookie": "^3.0.1",
"moment": "^2.29.1",
Expand Down
24 changes: 24 additions & 0 deletions components/dashboard/src/experiments/always-default.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Copyright (c) 2022 Gitpod GmbH. All rights reserved.
* Licensed under the GNU Affero General Public License (AGPL).
* See License-AGPL.txt in the project root for license information.
*/
import { Attributes, Client } from "./client";

// AlwaysReturningDefaultValueClient is an implemention of an experiments.Client which performs no lookup/network operation
// and always returns the default value for a given experimentName.
// This client is used for non-SaaS version of Gitpod, in particular for self-hosted installations where external
// network connections are not desirable or even possible.
class AlwaysReturningDefaultValueClient implements Client {
getValueAsync<T>(experimentName: string, defaultValue: T, attributes: Attributes): Promise<T> {
return Promise.resolve(defaultValue);
}

dispose(): void {
// there is nothing to dispose, no-op.
}
}

export function newAlwaysReturningDefaultValueClient(): Client {
return new AlwaysReturningDefaultValueClient();
}
55 changes: 55 additions & 0 deletions components/dashboard/src/experiments/client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* Copyright (c) 2022 Gitpod GmbH. All rights reserved.
* Licensed under the GNU Affero General Public License (AGPL).
* See License-AGPL.txt in the project root for license information.
*/

// Attributes define attributes which can be used to segment audiences.
// Set the attributes which you want to use to group audiences into.
import { newNonProductionConfigCatClient, newProductionConfigCatClient } from "./configcat";
import { newAlwaysReturningDefaultValueClient } from "./always-default";

export interface Attributes {
userID?: string;
email?: string;

// Gitpod Project ID
projectID?: string;

// Gitpod Team ID
teamID?: string;
// Gitpod Team Name
teamName?: string;
}

export interface Client {
getValueAsync<T>(experimentName: string, defaultValue: T, attributes: Attributes): Promise<T>;

// dispose will dispose of the client, no longer retrieving flags
dispose(): void;
}

let client: Client | undefined;

export function getExperimentsClient(): Client {
// We have already instantiated a client, we can just re-use it.
if (client !== undefined) {
return client;
}

const host = window.location.hostname;
if (host === "gitpod.io") {
client = newProductionConfigCatClient();
} else if (host === "gitpod-staging.com" || host.endsWith("gitpod-dev.com") || host.endsWith("gitpod-io-dev.com")) {
client = newNonProductionConfigCatClient();
} else {
// We're gonna use a client which always returns the default value.
client = newAlwaysReturningDefaultValueClient();
}

return client;
}

export const PROJECT_ID_ATTRIBUTE = "project_id";
export const TEAM_ID_ATTRIBUTE = "team_id";
export const TEAM_NAME_ATTRIBUTE = "team_name";
69 changes: 69 additions & 0 deletions components/dashboard/src/experiments/configcat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/**
* Copyright (c) 2022 Gitpod GmbH. All rights reserved.
* Licensed under the GNU Affero General Public License (AGPL).
* See License-AGPL.txt in the project root for license information.
*/

import * as configcat from "configcat-js";
import { IConfigCatClient } from "configcat-common/lib/ConfigCatClient";
import { User } from "configcat-common/lib/RolloutEvaluator";
import { Attributes, Client, PROJECT_ID_ATTRIBUTE, TEAM_ID_ATTRIBUTE, TEAM_NAME_ATTRIBUTE } from "./client";

// newProductionConfigCatClient constructs a new ConfigCat client with production configuration.
// DO NOT USE DIRECTLY! Use getExperimentsClient() instead.
export function newProductionConfigCatClient(): Client {
// clientKey is an identifier of our ConfigCat application. It is not a secret.
const clientKey = "WBLaCPtkjkqKHlHedziE9g/TwAe6YyftEGPnGxVRXd0Ig";
const client = configcat.createClient(clientKey, {
logger: configcat.createConsoleLogger(2),
});

return new ConfigCatClient(client);
}

// newNonProductionConfigCatClient constructs a new ConfigCat client with non-production configuration.
// DO NOT USE DIRECTLY! Use getExperimentsClient() instead.
export function newNonProductionConfigCatClient(): Client {
// clientKey is an identifier of our ConfigCat application. It is not a secret.
const clientKey = "WBLaCPtkjkqKHlHedziE9g/LEAOCNkbuUKiqUZAcVg7dw";
const client = configcat.createClient(clientKey, {
pollIntervalSeconds: 60 * 3, // 3 minutes
logger: configcat.createConsoleLogger(3),
});

return new ConfigCatClient(client);
}

class ConfigCatClient implements Client {
private client: IConfigCatClient;

constructor(cc: IConfigCatClient) {
this.client = cc;
}

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

dispose(): void {
return this.client.dispose();
}
}

function attributesToUser(attributes: Attributes): User {
const userID = attributes.userID || "";
const email = attributes.email || "";

const custom: { [key: string]: string } = {};
if (attributes.projectID) {
custom[PROJECT_ID_ATTRIBUTE] = attributes.projectID;
}
if (attributes.teamID) {
custom[TEAM_ID_ATTRIBUTE] = attributes.teamID;
}
if (attributes.teamName) {
custom[TEAM_NAME_ATTRIBUTE] = attributes.teamName;
}

return new User(userID, email, "", custom);
}
15 changes: 13 additions & 2 deletions components/dashboard/src/workspaces/Workspaces.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { User } from "@gitpod/gitpod-protocol";
import { useLocation } from "react-router";
import { StartWorkspaceModalContext, StartWorkspaceModalKeyBinding } from "./start-workspace-modal-context";
import SelectIDEModal from "../settings/SelectIDEModal";
import { getExperimentsClient } from "../experiments/client";

export interface WorkspacesProps {}

Expand All @@ -36,6 +37,7 @@ export default function () {
const [inactiveWorkspaces, setInactiveWorkspaces] = useState<WorkspaceInfo[]>([]);
const [workspaceModel, setWorkspaceModel] = useState<WorkspaceModel>();
const { setIsStartWorkspaceModalVisible } = useContext(StartWorkspaceModalContext);
const [isExperimentEnabled, setExperiment] = useState<boolean>(false);

useEffect(() => {
(async () => {
Expand All @@ -45,13 +47,22 @@ export default function () {
}, [teams, location]);

const isOnboardingUser = user && User.isOnboardingUser(user);
useEffect(() => {
(async () => {
if (teams && teams.length > 0) {
const isEnabled = await getExperimentsClient().getValueAsync("isMyFirstFeatureEnabled", false, {
teamName: teams[0]?.name,
});
setExperiment(isEnabled);
}
})();
}, [teams]);
console.log("Is experiment enabled? ", isExperimentEnabled);

return (
<>
<Header title="Workspaces" subtitle="Manage recent and stopped workspaces." />

{isOnboardingUser && <SelectIDEModal />}

{workspaceModel?.initialized &&
(activeWorkspaces.length > 0 || inactiveWorkspaces.length > 0 || workspaceModel.searchTerm ? (
<>
Expand Down
17 changes: 15 additions & 2 deletions components/public-api/typescript/BUILD.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,26 @@ packages:
deps:
- components/gitpod-protocol:lib
srcs:
- "src/*.ts"
- "src/*.js"
- src/**
- package.json
- tsconfig.json
config:
packaging: library
dontTest: true
commands:
build: ["yarn", "build"]
yarnLock: ${coreYarnLockBase}/../yarn.lock
tsconfig: tsconfig.json

- name: publish
type: generic
env:
- DO_PUBLISH=${publishToNPM}
argdeps:
- npmPublishTrigger
deps:
- :lib
- components/gitpod-protocol:scripts
config:
commands:
- ["node", "components-gitpod-protocol--scripts/publish.js", "${version}", "components-public-api-typescript--lib/package"]
4 changes: 0 additions & 4 deletions components/public-api/typescript/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
{
"private": true,
"name": "@gitpod/public-api",
"version": "0.1.5",
"license": "UNLICENSED",
"files": [
"client",
"lib"
],
"scripts": {
Expand All @@ -14,11 +12,9 @@
"test:brk": "yarn test --inspect-brk"
},
"dependencies": {
"@gitpod/content-service": "0.1.5",
"@gitpod/gitpod-protocol": "0.1.5",
"@grpc/grpc-js": "^1.3.7",
"google-protobuf": "^3.19.1",
"inversify": "^5.0.1",
"opentracing": "^0.14.4"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
// GENERATED CODE -- NO SERVICES IN PROTO
/**
* Copyright (c) 2022 Gitpod GmbH. All rights reserved.
* Licensed under the GNU Affero General Public License (AGPL).
* See License-AGPL.txt in the project root for license information.
*/

// GENERATED CODE -- NO SERVICES IN PROTO
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/**
* Copyright (c) 2022 Gitpod GmbH. All rights reserved.
* Licensed under the GNU Affero General Public License (AGPL).
* See License-AGPL.txt in the project root for license information.
*/

// package: gitpod.v1
// file: gitpod/v1/pagination.proto

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/**
* Copyright (c) 2022 Gitpod GmbH. All rights reserved.
* Licensed under the GNU Affero General Public License (AGPL).
* See License-AGPL.txt in the project root for license information.
*/

// source: gitpod/v1/pagination.proto
/**
* @fileoverview
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/**
* Copyright (c) 2022 Gitpod GmbH. All rights reserved.
* Licensed under the GNU Affero General Public License (AGPL).
* See License-AGPL.txt in the project root for license information.
*/

// package: gitpod.v1
// file: gitpod/v1/prebuilds.proto

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/**
* Copyright (c) 2022 Gitpod GmbH. All rights reserved.
* Licensed under the GNU Affero General Public License (AGPL).
* See License-AGPL.txt in the project root for license information.
*/

// GENERATED CODE -- DO NOT EDIT!

'use strict';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/**
* Copyright (c) 2022 Gitpod GmbH. All rights reserved.
* Licensed under the GNU Affero General Public License (AGPL).
* See License-AGPL.txt in the project root for license information.
*/

// package: gitpod.v1
// file: gitpod/v1/prebuilds.proto

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/**
* Copyright (c) 2022 Gitpod GmbH. All rights reserved.
* Licensed under the GNU Affero General Public License (AGPL).
* See License-AGPL.txt in the project root for license information.
*/

// source: gitpod/v1/prebuilds.proto
/**
* @fileoverview
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/**
* Copyright (c) 2022 Gitpod GmbH. All rights reserved.
* Licensed under the GNU Affero General Public License (AGPL).
* See License-AGPL.txt in the project root for license information.
*/

// package: gitpod.v1
// file: gitpod/v1/workspaces.proto

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/**
* Copyright (c) 2022 Gitpod GmbH. All rights reserved.
* Licensed under the GNU Affero General Public License (AGPL).
* See License-AGPL.txt in the project root for license information.
*/

// GENERATED CODE -- DO NOT EDIT!

'use strict';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/**
* Copyright (c) 2022 Gitpod GmbH. All rights reserved.
* Licensed under the GNU Affero General Public License (AGPL).
* See License-AGPL.txt in the project root for license information.
*/

// package: gitpod.v1
// file: gitpod/v1/workspaces.proto

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/**
* Copyright (c) 2022 Gitpod GmbH. All rights reserved.
* Licensed under the GNU Affero General Public License (AGPL).
* See License-AGPL.txt in the project root for license information.
*/

// source: gitpod/v1/workspaces.proto
/**
* @fileoverview
Expand Down
Loading

0 comments on commit b147a29

Please sign in to comment.