Skip to content
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

Stream imagebuild logs directly from pods #7899

Merged
merged 3 commits into from
Feb 2, 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
22 changes: 20 additions & 2 deletions components/dashboard/src/start/StartWorkspace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -418,11 +418,29 @@ function ImageBuildView(props: ImageBuildViewProps) {
const logsEmitter = new EventEmitter();

useEffect(() => {
const watchBuild = () => getGitpodService().server.watchWorkspaceImageBuildLogs(props.workspaceId);
let registered = false;
const watchBuild = () => {
if (registered) {
return;
}

getGitpodService().server.watchWorkspaceImageBuildLogs(props.workspaceId)
.then(() => registered = true)
.catch(err => {

if (err?.code === ErrorCodes.HEADLESS_LOG_NOT_YET_AVAILABLE) {
// wait, and then retry
setTimeout(watchBuild, 5000);
}
})
}
watchBuild();

const toDispose = getGitpodService().registerClient({
notifyDidOpenConnection: () => watchBuild(),
notifyDidOpenConnection: () => {
registered = false; // new connection, we're not registered anymore
watchBuild();
},
onWorkspaceImageBuildLogs: (info: WorkspaceImageBuild.StateInfo, content?: WorkspaceImageBuild.LogContent) => {
if (!content) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { PrimaryColumn, Column, Index, Entity } from "typeorm";

import { WorkspaceInstance, WorkspaceInstanceStatus, WorkspaceInstancePhase, WorkspaceInstanceConfiguration } from "@gitpod/gitpod-protocol";
import { WorkspaceInstance, WorkspaceInstanceStatus, WorkspaceInstancePhase, WorkspaceInstanceConfiguration, ImageBuildInfo } from "@gitpod/gitpod-protocol";
import { TypeORM } from "../typeorm";
import { Transformer } from "../transformer";

Expand Down Expand Up @@ -87,4 +87,6 @@ export class DBWorkspaceInstance implements WorkspaceInstance {
})
configuration?: WorkspaceInstanceConfiguration;

@Column("simple-json", { nullable: true })
imageBuildInfo?: ImageBuildInfo;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* 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 {MigrationInterface, QueryRunner} from "typeorm";
import { columnExists } from "./helper/helper";

export class ImageBuildInfo1643724132624 implements MigrationInterface {

public async up(queryRunner: QueryRunner): Promise<void> {
if (!(await columnExists(queryRunner, "d_b_workspace_instance", "imageBuildInfo"))) {
await queryRunner.query("ALTER TABLE d_b_workspace_instance ADD COLUMN `imageBuildInfo` text NULL");
}
}

public async down(queryRunner: QueryRunner): Promise<void> {
}

}
3 changes: 3 additions & 0 deletions components/gitpod-protocol/src/messaging/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,7 @@ export namespace ErrorCodes {

// 630 Snapshot Error
export const SNAPSHOT_ERROR = 630;

// 640 Headless logs are not available (yet)
export const HEADLESS_LOG_NOT_YET_AVAILABLE = 640;
}
20 changes: 20 additions & 0 deletions components/gitpod-protocol/src/workspace-instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ export interface WorkspaceInstance {

// instance is hard-deleted on the database and about to be collected by db-sync
readonly deleted?: boolean;

/**
* Contains information about the image build, if there was any
*/
imageBuildInfo?: ImageBuildInfo;
}

// WorkspaceInstanceStatus describes the current state of a workspace instance
Expand Down Expand Up @@ -213,3 +218,18 @@ export interface WorkspaceInstanceConfiguration {
// supervisorImage is the ref of the supervisor image this instance uses.
supervisorImage?: string;
}

/**
* Holds information about the image build (if there was one) for this WorkspaceInstance
*/
export interface ImageBuildInfo {
log?: ImageBuildLogInfo,
}

/**
* Holds information about how to access logs for this an image build
*/
export interface ImageBuildLogInfo {
url: string,
headers: { [key: string]: string },
}
135 changes: 113 additions & 22 deletions components/image-builder-api/go/imgbuilder.pb.go

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

2 changes: 1 addition & 1 deletion components/image-builder-api/go/imgbuilder_grpc.pb.go

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

2 changes: 1 addition & 1 deletion components/image-builder-api/go/mock/mock.go

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

6 changes: 6 additions & 0 deletions components/image-builder-api/imgbuilder.proto
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,10 @@ message BuildInfo {
BuildStatus status = 2;
int64 started_at = 3;
string build_id = 5;
LogInfo log_info = 6;
}

message LogInfo {
string url = 1;
map<string, string> headers = 2;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2021 Gitpod GmbH. All rights reserved.
* 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.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2021 Gitpod GmbH. All rights reserved.
* 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.
*/
Expand Down
Loading