Skip to content

Revert "[prebuilds] no prebuilds for inactive repos" #9959

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 1 commit into from
May 12, 2022
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
16 changes: 0 additions & 16 deletions components/gitpod-db/src/typeorm/workspace-db-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,22 +356,6 @@ export abstract class AbstractTypeORMWorkspaceDBImpl implements WorkspaceDB {
return workspaceRepo.find({ ownerId: userId });
}

public async getWorkspaceCountByCloneURL(
cloneURL: string,
sinceLastDays: number = 7,
type: string = "regular",
): Promise<number> {
const workspaceRepo = await this.getWorkspaceRepo();
const since = new Date();
since.setDate(since.getDate() - sinceLastDays);
return workspaceRepo
.createQueryBuilder("ws")
.where('context->"$.repository.cloneUrl" = :cloneURL', { cloneURL })
.andWhere("creationTime > :since", { since: since.toISOString() })
.andWhere("type = :type", { type })
.getCount();
}

public async findCurrentInstance(workspaceId: string): Promise<MaybeWorkspaceInstance> {
const workspaceInstanceRepo = await this.getWorkspaceInstanceRepo();
const qb = workspaceInstanceRepo
Expand Down
48 changes: 1 addition & 47 deletions components/gitpod-db/src/workspace-db.spec.db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const expect = chai.expect;
import { suite, test, timeout } from "mocha-typescript";
import { fail } from "assert";

import { WorkspaceInstance, Workspace, PrebuiltWorkspace, CommitContext } from "@gitpod/gitpod-protocol";
import { WorkspaceInstance, Workspace, PrebuiltWorkspace } from "@gitpod/gitpod-protocol";
import { testContainer } from "./test-container";
import { TypeORMWorkspaceDBImpl } from "./typeorm/workspace-db-impl";
import { TypeORM } from "./typeorm/typeorm";
Expand Down Expand Up @@ -539,52 +539,6 @@ class WorkspaceDBSpec {
expect(unabortedCount).to.eq(1);
}

@test(timeout(10000))
public async testGetWorkspaceCountForCloneURL() {
const now = new Date();
const eightDaysAgo = new Date();
eightDaysAgo.setDate(eightDaysAgo.getDate() - 8);
const activeRepo = "http://github.com/myorg/active.git";
const inactiveRepo = "http://github.com/myorg/inactive.git";
await Promise.all([
this.db.store({
id: "12345",
creationTime: eightDaysAgo.toISOString(),
description: "something",
contextURL: "http://github.com/myorg/inactive",
ownerId: "1221423",
context: <CommitContext>{
title: "my title",
repository: {
cloneUrl: inactiveRepo,
},
},
config: {},
type: "regular",
}),
this.db.store({
id: "12346",
creationTime: now.toISOString(),
description: "something",
contextURL: "http://github.com/myorg/active",
ownerId: "1221423",
context: <CommitContext>{
title: "my title",
repository: {
cloneUrl: activeRepo,
},
},
config: {},
type: "regular",
}),
]);

const inactiveCount = await this.db.getWorkspaceCountByCloneURL(inactiveRepo, 7, "regular");
expect(inactiveCount).to.eq(0, "there should be no regular workspaces in the past 7 days");
const activeCount = await this.db.getWorkspaceCountByCloneURL(activeRepo, 7, "regular");
expect(activeCount).to.eq(1, "there should be exactly one regular workspace");
}

private async storePrebuiltWorkspace(pws: PrebuiltWorkspace) {
// store the creationTime directly, before it is modified by the store function in the ORM layer
const creationTime = pws.creationTime;
Expand Down
1 change: 0 additions & 1 deletion components/gitpod-db/src/workspace-db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ export interface WorkspaceDB {
findInstancesByPhaseAndRegion(phase: string, region: string): Promise<WorkspaceInstance[]>;

getWorkspaceCount(type?: String): Promise<Number>;
getWorkspaceCountByCloneURL(cloneURL: string, sinceLastDays?: number, type?: string): Promise<number>;
getInstanceCount(type?: string): Promise<number>;

findAllWorkspaceInstances(
Expand Down
19 changes: 0 additions & 19 deletions components/server/ee/src/prebuilds/prebuild-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,6 @@ export class PrebuildManager {
prebuild.error =
"Project is inactive. Please start a new workspace for this project to re-enable prebuilds.";
await this.workspaceDB.trace({ span }).storePrebuiltWorkspace(prebuild);
} else if (!project && (await this.shouldSkipInactiveRepository({ span }, cloneURL))) {
prebuild.state = "aborted";
prebuild.error =
"Repository is inactive. Please create a project for this repository to re-enable prebuilds.";
await this.workspaceDB.trace({ span }).storePrebuiltWorkspace(prebuild);
} else {
span.setTag("starting", true);
const projectEnvVars = await projectEnvVarsPromise;
Expand Down Expand Up @@ -361,18 +356,4 @@ export class PrebuildManager {
const inactiveProjectTime = 1000 * 60 * 60 * 24 * 7 * 1; // 1 week
return now - lastUse > inactiveProjectTime;
}

private async shouldSkipInactiveRepository(ctx: TraceContext, cloneURL: string): Promise<boolean> {
const span = TraceContext.startSpan("shouldSkipInactiveRepository", ctx);
try {
return (
(await this.workspaceDB
.trace({ span })
.getWorkspaceCountByCloneURL(cloneURL, 7 /* last week */, "regular")) === 0
);
} catch (error) {
log.error("cannot compute activity for repository", { cloneURL }, error);
return false;
}
}
}