Skip to content

Filter out IDEs on the backend #17324

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 10 commits into from
Apr 22, 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
14 changes: 5 additions & 9 deletions components/dashboard/src/components/SelectIDEComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
*/

import { IDEOption, IDEOptions } from "@gitpod/gitpod-protocol/lib/ide-protocol";
import { useCallback, useContext, useEffect, useState } from "react";
import { useCallback, useEffect, useState } from "react";
import { getGitpodService } from "../service/service";
import { DropDown2, DropDown2Element } from "./DropDown2";
import Editor from "../icons/Editor.svg";
import { FeatureFlagContext } from "../contexts/FeatureFlagContext";

interface SelectIDEComponentProps {
selectedIdeOption?: string;
Expand All @@ -18,15 +17,12 @@ interface SelectIDEComponentProps {
setError?: (error?: string) => void;
}

function filteredIdeOptions(ideOptions: IDEOptions, experimentalTurnedOn: boolean) {
return IDEOptions.asArray(ideOptions)
.filter((x) => !x.hidden)
.filter((x) => (x.experimental ? experimentalTurnedOn : true));
function filteredIdeOptions(ideOptions: IDEOptions) {
return IDEOptions.asArray(ideOptions).filter((x) => !x.hidden);
}

export default function SelectIDEComponent(props: SelectIDEComponentProps) {
const [ideOptions, setIdeOptions] = useState<IDEOptions>();
const { experimentalIdes } = useContext(FeatureFlagContext);

useEffect(() => {
getGitpodService().server.getIDEOptions().then(setIdeOptions);
Expand All @@ -36,7 +32,7 @@ export default function SelectIDEComponent(props: SelectIDEComponentProps) {
if (!ideOptions) {
return [];
}
const options = filteredIdeOptions(ideOptions, experimentalIdes);
const options = filteredIdeOptions(ideOptions);
const result: DropDown2Element[] = [];
for (const ide of options.filter((ide) =>
`${ide.label}${ide.title}${ide.notes}${ide.id}`.toLowerCase().includes(search.toLowerCase()),
Expand All @@ -57,7 +53,7 @@ export default function SelectIDEComponent(props: SelectIDEComponentProps) {
}
return result;
},
[experimentalIdes, ideOptions, props.useLatest],
[ideOptions, props.useLatest],
);
const internalOnSelectionChange = (id: string) => {
const { ide, useLatest } = parseId(id);
Expand Down
5 changes: 0 additions & 5 deletions components/dashboard/src/contexts/FeatureFlagContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ const defaultFeatureFlags = {
userGitAuthProviders: false,
newSignupFlow: false,
linkedinConnectionForOnboarding: false,
experimentalIdes: false,
};

const FeatureFlagContext = createContext<FeatureFlagsType>(defaultFeatureFlags);
Expand All @@ -48,7 +47,6 @@ const FeatureFlagContextProvider: React.FC = ({ children }) => {
const [userGitAuthProviders, setUserGitAuthProviders] = useState<boolean>(false);
const [newSignupFlow, setNewSignupFlow] = useState<boolean>(false);
const [linkedinConnectionForOnboarding, setLinkedinConnectionForOnboarding] = useState<boolean>(false);
const [experimentalIdes, setExperimentalIdes] = useState<boolean>(false);

useEffect(() => {
if (!user) return;
Expand All @@ -67,7 +65,6 @@ const FeatureFlagContextProvider: React.FC = ({ children }) => {
userGitAuthProviders: { defaultValue: false, setter: setUserGitAuthProviders },
newSignupFlow: { defaultValue: false, setter: setNewSignupFlow },
linkedinConnectionForOnboarding: { defaultValue: false, setter: setLinkedinConnectionForOnboarding },
experimentalIdes: { defaultValue: false, setter: setExperimentalIdes },
};

for (const [flagName, config] of Object.entries(featureFlags)) {
Expand Down Expand Up @@ -115,7 +112,6 @@ const FeatureFlagContextProvider: React.FC = ({ children }) => {
userGitAuthProviders,
newSignupFlow,
linkedinConnectionForOnboarding,
experimentalIdes,
};
}, [
enablePersonalAccessTokens,
Expand All @@ -127,7 +123,6 @@ const FeatureFlagContextProvider: React.FC = ({ children }) => {
startWithOptions,
usePublicApiWorkspacesService,
userGitAuthProviders,
experimentalIdes,
]);

return <FeatureFlagContext.Provider value={flags}>{children}</FeatureFlagContext.Provider>;
Expand Down
169 changes: 91 additions & 78 deletions components/ide-service-api/go/ide.pb.go

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion components/ide-service-api/ide.proto
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ service IDEService {
}
}

message GetConfigRequest {}
message GetConfigRequest {
User user = 1;
}

message GetConfigResponse {
string content = 1;
Expand Down
21 changes: 15 additions & 6 deletions components/ide-service-api/typescript/src/ide.pb.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 33 additions & 5 deletions components/ide-service/pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type IDEServiceServer struct {
parsedIDEConfigContent string
ideConfig *config.IDEConfig
ideConfigFileName string
experiemntsClient experiments.Client
experimentsClient experiments.Client

api.UnimplementedIDEServiceServer
}
Expand Down Expand Up @@ -87,7 +87,7 @@ func New(cfg *config.ServiceConfiguration) *IDEServiceServer {
s := &IDEServiceServer{
config: cfg,
ideConfigFileName: fn,
experiemntsClient: experiments.NewClient(),
experimentsClient: experiments.NewClient(),
}
return s
}
Expand All @@ -97,9 +97,37 @@ func (s *IDEServiceServer) register(grpcServer *grpc.Server) {
}

func (s *IDEServiceServer) GetConfig(ctx context.Context, req *api.GetConfigRequest) (*api.GetConfigResponse, error) {
return &api.GetConfigResponse{
Content: s.parsedIDEConfigContent,
}, nil
configCatClient := experiments.NewClient()
attributes := experiments.Attributes{
UserID: req.User.Id,
UserEmail: req.User.GetEmail(),
}

experimentalIdesEnabled := configCatClient.GetBoolValue(ctx, "experimentalIdes", false, attributes)

if experimentalIdesEnabled {
// We can return everything
return &api.GetConfigResponse{
Content: s.parsedIDEConfigContent,
}, nil
} else {
for key, ide := range s.ideConfig.IdeOptions.Options {
if ide.Experimental && !experimentalIdesEnabled {
delete(s.ideConfig.IdeOptions.Options, key)
}
}

parsedConfig, err := json.Marshal(s.ideConfig)
if err != nil {
log.WithError(err).Error("cannot marshal ide config")
return nil, err
}
s.parsedIDEConfigContent = string(parsedConfig)

return &api.GetConfigResponse{
Content: s.parsedIDEConfigContent,
}, nil
}
}

func (s *IDEServiceServer) readIDEConfig(ctx context.Context, isInit bool) {
Expand Down
6 changes: 3 additions & 3 deletions components/server/src/ide-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ export class IDEService {

private cacheConfig?: IDEConfig;

async getIDEConfig(): Promise<IDEConfig> {
async getIDEConfig(request: { user: { id: string; email?: string } }): Promise<IDEConfig> {
try {
let resp = await this.ideService.getConfig({});
let config: IDEConfig = JSON.parse(resp.content);
const response = await this.ideService.getConfig(request);
const config: IDEConfig = JSON.parse(response.content);
this.cacheConfig = config;
return config;
} catch (e) {
Expand Down
4 changes: 3 additions & 1 deletion components/server/src/workspace/gitpod-server-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3327,7 +3327,9 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
}

async getIDEOptions(ctx: TraceContext): Promise<IDEOptions> {
const ideConfig = await this.ideService.getIDEConfig();
const user = this.checkUser("identifyUser");
const email = User.getPrimaryEmail(user);
const ideConfig = await this.ideService.getIDEConfig({ user: { id: user.id, email } });
return ideConfig.ideOptions;
}

Expand Down