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

[kwa-trials-logs] Create the LOGS tab of Trial's details page in KWA #2101

Merged
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
6 changes: 3 additions & 3 deletions pkg/new-ui/v1beta1/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -729,9 +729,9 @@ func fetchMasterPodName(clientset *kubernetes.Clientset, trial *trialsv1beta1.Tr
}

if len(podList.Items) == 0 {
return "", errors.New(`Logs for the trial could not be found.
Was 'retain: true' specified in the Experiment definition?
An example can be found here: https://github.com/kubeflow/katib/blob/7bf39225f7235ee4ba6cf285ecc2c455c6471234/examples/v1beta1/argo/argo-workflow.yaml#L33`)
return "", errors.New(`Failed to find logs for this Trial. Make sure you've set "spec.trialTemplate.retain"
field to "true" in the Experiment definition. If this error persists then the Pod's logs are not currently
persisted in the cluster.`)
}
if len(podList.Items) > 1 {
return "", errors.New("More than one master replica found")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@
></app-trial-overview>
</ng-template>
</mat-tab>

<mat-tab label="LOGS">
<ng-template matTabContent>
<app-trial-logs
[trialLogs]="trialLogs"
[logsRequestError]="logsRequestError"
></app-trial-logs>
</ng-template>
</mat-tab>

<mat-tab label="YAML">
<ng-template matTabContent>
<app-trial-yaml [trialJson]="trialDetails"></app-trial-yaml>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ let NamespaceServiceStub: Partial<NamespaceService>;
KWABackendServiceStub = {
getTrial: () => of([]),
getTrialInfo: () => of(),
getTrialLogs: () => of(),
};

NamespaceServiceStub = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export class TrialDetailsComponent implements OnInit, OnDestroy {
experimentName: string;
showTrialGraph: boolean = false;
options: {};
trialLogs: string;
logsRequestError: string;
chartData: ChartPoint[] = [];
yScaleMax = 0;
yScaleMin = 1;
Expand Down Expand Up @@ -133,6 +135,17 @@ export class TrialDetailsComponent implements OnInit, OnDestroy {
}
this.pageLoading = false;
});

this.backendService.getTrialLogs(this.trialName, this.namespace).subscribe(
logs => {
this.trialLogs = logs;
this.logsRequestError = null;
},
error => {
this.trialLogs = null;
this.logsRequestError = error;
},
);
}

private trialStatus(trial: TrialK8s): StatusEnum {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
PanelModule,
} from 'kubeflow';
import { NgxEchartsModule } from 'ngx-echarts';
import { TrialLogsModule } from './trial-logs/trial-logs.module';

@NgModule({
declarations: [TrialDetailsComponent],
Expand All @@ -36,6 +37,7 @@ import { NgxEchartsModule } from 'ngx-echarts';
NgxEchartsModule.forRoot({
echarts: () => import('echarts'),
}),
TrialLogsModule,
],
exports: [TrialDetailsComponent],
})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!--if no logs are present at all then show a warning message-->
<ng-container *ngIf="logsRequestError">
<lib-panel icon="error" color="warn">
{{ logsRequestError }}
</lib-panel>
</ng-container>

<ng-container *ngIf="!logsRequestError">
<lib-logs-viewer
class="logs-viewer"
heading="Trial Logs"
[subHeading]="''"
[logs]="logs"
></lib-logs-viewer>
</ng-container>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
lib-panel {
display: block;
margin-top: 1rem;
}

.logs-viewer {
margin-bottom: 2rem;
margin-top: 1rem;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { CommonModule } from '@angular/common';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import {
HeadingSubheadingRowModule,
KubeflowModule,
LogsViewerModule,
} from 'kubeflow';

import { TrialLogsComponent } from './trial-logs.component';

describe('TrialLogsComponent', () => {
let component: TrialLogsComponent;
let fixture: ComponentFixture<TrialLogsComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [TrialLogsComponent],
imports: [
CommonModule,
KubeflowModule,
HeadingSubheadingRowModule,
LogsViewerModule,
],
}).compileComponents();
});

beforeEach(() => {
fixture = TestBed.createComponent(TrialLogsComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Component, Input } from '@angular/core';

@Component({
selector: 'app-trial-logs',
templateUrl: './trial-logs.component.html',
styleUrls: ['./trial-logs.component.scss'],
})
export class TrialLogsComponent {
public logs: string[];

@Input() logsRequestError: string;

@Input()
set trialLogs(trialLogs: string) {
if (!trialLogs) {
return;
}

this.logs = trialLogs.split('\n');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { TrialLogsComponent } from './trial-logs.component';
import {
HeadingSubheadingRowModule,
KubeflowModule,
LogsViewerModule,
} from 'kubeflow';

@NgModule({
declarations: [TrialLogsComponent],
imports: [
CommonModule,
KubeflowModule,
HeadingSubheadingRowModule,
LogsViewerModule,
],
exports: [TrialLogsComponent],
})
export class TrialLogsModule {}
21 changes: 21 additions & 0 deletions pkg/new-ui/v1beta1/frontend/src/app/services/backend.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,25 @@ export class KWABackendService extends BackendService {
.post(url, { postData: exp })
.pipe(catchError(error => this.parseError(error)));
}

getTrialLogs(name: string, namespace: string): Observable<any> {
const url = `/katib/fetch_trial_logs/?trialName=${name}&namespace=${namespace}`;

return this.http
.get(url)
.pipe(catchError(error => this.handleError(error, false)));
}

// ---------------------------Error Handling---------------------------------

// Override common service's getBackendErrorLog
// in order to properly show the message the backend has sent
public getBackendErrorLog(error: HttpErrorResponse): string {
if (error.error === null) {
return error.message;
} else {
// Show the message the backend has sent
return error.error.log ? error.error.log : error.error;
}
}
}