Skip to content

Commit

Permalink
feat: Redesign the pipeline overview
Browse files Browse the repository at this point in the history
- The "Select pipeline" step was removed. Instead, all pipeline actions
  are displayed directly on the corresponding card.
- A note that the TeamForCapella project name must match exactly was added.
- Error handling was added if Grafana Loki is not enabled.
- Make use of generated OpenAPI schema for pipelines and pipeline runs in the frontend.
  • Loading branch information
MoritzWeber0 committed Sep 12, 2024
1 parent f43efb9 commit b2ab418
Show file tree
Hide file tree
Showing 17 changed files with 277 additions and 324 deletions.
10 changes: 10 additions & 0 deletions backend/capellacollab/core/logging/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,13 @@ def __init__(self):
reason="Too many outstanding requests. Please try again later.",
err_code="LOKI_TOO_MANY_OUTSTANDING_REQUESTS",
)


class GrafanaLokiDisabled(core_exceptions.BaseError):
def __init__(self):
super().__init__(

Check warning on line 21 in backend/capellacollab/core/logging/exceptions.py

View check run for this annotation

Codecov / codecov/patch

backend/capellacollab/core/logging/exceptions.py#L21

Added line #L21 was not covered by tests
status_code=status.HTTP_400_BAD_REQUEST,
title="Grafana Loki is disabled for this instance.",
reason="To use this feature, ask your system administrator to enable Grafana Loki.",
err_code="LOKI_DISABLED",
)
9 changes: 9 additions & 0 deletions backend/capellacollab/core/logging/loki.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ class LogEntry(t.TypedDict):
timestamp: datetime.datetime


def is_loki_activated() -> bool:
return PROMTAIL_CONFIGURATION.loki_enabled


def check_loki_enabled():
if not is_loki_activated():
raise exceptions.GrafanaLokiDisabled()

Check warning on line 34 in backend/capellacollab/core/logging/loki.py

View check run for this annotation

Codecov / codecov/patch

backend/capellacollab/core/logging/loki.py#L34

Added line #L34 was not covered by tests


def push_logs_to_loki(entries: list[LogEntry], labels):
# Convert the streams and labels into the Loki log format
log_data = json.dumps(
Expand Down
7 changes: 6 additions & 1 deletion backend/capellacollab/projects/toolmodels/backups/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import typing as t

import pydantic
import sqlalchemy as sa
from sqlalchemy import orm

Expand Down Expand Up @@ -30,7 +31,11 @@
class CreateBackup(core_pydantic.BaseModel):
git_model_id: int
t4c_model_id: int
include_commit_history: bool
include_commit_history: bool = pydantic.Field(
default=False,
description="With included commit history, a run can take a long time. Use with caution. The TeamForCapella commit messages are exported by default.",
deprecated="Due to the sometimes hours-long runtimes with this option enabled, we will remove it with v5.0.0. Commit messages are exported automatically.",
)
run_nightly: bool


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def get_pipeline_run_events(
injectables.get_existing_pipeline_run
),
):
loki.check_loki_enabled()
event_logs = loki.fetch_logs_from_loki(
query=f'{{pipeline_run_id="{pipeline_run.id}", job_name="{pipeline_run.reference_id}", log_type="events"}}',
start_time=pipeline_run.trigger_time,
Expand Down Expand Up @@ -147,6 +148,7 @@ def get_logs(
injectables.get_existing_pipeline_run
),
):
loki.check_loki_enabled()
logs = loki.fetch_logs_from_loki(
query=f'{{pipeline_run_id="{pipeline_run.id}", job_name="{pipeline_run.reference_id}", log_type="logs"}}',
start_time=pipeline_run.trigger_time,
Expand Down
5 changes: 0 additions & 5 deletions docs/docs/user/projects/models/backups/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,4 @@ around 3pm.

![Create a backup pipeline](./create-pipeline.png)

!!! warning

If you choose the `Include commit history`-option, backups are resource-intensive
and each backup can take up to 5 hours depending on the size!

1. Confirm your selection with the `Create` button.
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import { MatIcon } from '@angular/material/icon';
import { MatSelectionList, MatListOption } from '@angular/material/list';
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
import { combineLatest } from 'rxjs';
import { CreateBackup } from 'src/app/openapi';
import {
PipelineService,
PostPipeline,
PipelineWrapperService,
} from 'src/app/projects/models/backup-settings/service/pipeline.service';
import { T4CModelService } from 'src/app/projects/models/model-source/t4c/service/t4c-model.service';
import { GitModelService } from 'src/app/projects/project-detail/model-overview/model-detail/git-model.service';
Expand Down Expand Up @@ -59,7 +59,7 @@ export class CreateBackupComponent implements OnInit {
public t4cModelService: T4CModelService,
@Inject(MAT_DIALOG_DATA)
public data: { projectSlug: string; modelSlug: string },
private pipelineService: PipelineService,
private pipelineService: PipelineWrapperService,
private dialogRef: MatDialogRef<CreateBackupComponent>,
) {}

Expand Down Expand Up @@ -108,17 +108,17 @@ export class CreateBackupComponent implements OnInit {
createGitBackup() {
if (this.createBackupForm.valid) {
const formValue = this.createBackupForm.value;
const createBackupformValue: PostPipeline = {
gitmodelId: formValue.gitmodel![0],
t4cmodelId: formValue.t4cmodel![0],
includeCommitHistory: formValue.configuration!.includeCommitHistory!,
runNightly: formValue.configuration!.runNightly!,
const createBackupformValue: CreateBackup = {
git_model_id: formValue.gitmodel![0],
t4c_model_id: formValue.t4cmodel![0],
include_commit_history: false,
run_nightly: formValue.configuration!.runNightly!,
};
this.pipelineService
.createPipeline(
this.data.projectSlug,
this.data.modelSlug,
createBackupformValue as PostPipeline,
createBackupformValue,
)
.subscribe(() => {
this.dialogRef.close(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { ActivatedRoute, Router } from '@angular/router';
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
import { combineLatest, filter } from 'rxjs';
import { PipelineRunService } from 'src/app/projects/models/backup-settings/pipeline-runs/service/pipeline-run.service';
import { PipelineService } from 'src/app/projects/models/backup-settings/service/pipeline.service';
import { PipelineWrapperService } from 'src/app/projects/models/backup-settings/service/pipeline.service';
import { ModelWrapperService } from 'src/app/projects/models/service/model.service';
import { ProjectWrapperService } from 'src/app/projects/service/project.service';
import { TextLineSkeletonLoaderComponent } from '../../../../helpers/skeleton-loaders/text-line-skeleton-loader/text-line-skeleton-loader.component';
Expand Down Expand Up @@ -54,7 +54,7 @@ export class JobRunOverviewComponent implements OnInit, AfterViewInit {
private activatedRoute: ActivatedRoute,
private projectService: ProjectWrapperService,
private modelService: ModelWrapperService,
private pipelineService: PipelineService,
private pipelineService: PipelineWrapperService,
) {}

ngOnInit() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!--
~ SPDX-FileCopyrightText: Copyright DB InfraGO AG and contributors
~ SPDX-License-Identifier: Apache-2.0
-->

<div class="dialog">
<h2 class="text-xl font-medium">
Remove a TeamForCapella to Git backup pipeline
</h2>
<p>Do you want to delete the TeamForCapella to Git backup pipeline?</p>

<div class="flex flex-row flex-wrap items-center gap-2">
@if (userService.validateUserRole("administrator")) {
<mat-slide-toggle
[(ngModel)]="force"
aria-label="Force deletion of pipeline"
matTooltip="Delete pipeline even if T4C instance not reachable. In this case we can't revoke the pipeline credentials."
>
Force deletion
</mat-slide-toggle>
}
</div>

<div class="flex justify-between">
<button mat-flat-button type="button" (click)="onCancel()">Cancel</button>
<button mat-flat-button color="primary" type="submit">Confirm</button>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* SPDX-FileCopyrightText: Copyright DB InfraGO AG and contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { DialogRef } from '@angular/cdk/dialog';
import { CommonModule } from '@angular/common';
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { MatSlideToggle } from '@angular/material/slide-toggle';
import { UserWrapperService } from 'src/app/services/user/user.service';

@Component({
selector: 'app-pipeline-deletion-dialog',
standalone: true,
imports: [CommonModule, MatSlideToggle, FormsModule],
templateUrl: './pipeline-deletion-dialog.component.html',
styles: `
:host {
display: block;
}
`,
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class PipelineDeletionDialogComponent {
force = false;

constructor(
public userService: UserWrapperService,
private dialogRef: DialogRef,
) {}

onCancel(): void {
this.dialogRef.close(false);
}

removePipeline(backup: Pipeline): void {
this.pipelineService
.removePipeline(
this.data.projectSlug,
this.data.modelSlug,
backup.id,
this.force,
)
.subscribe(() => {
this.toastService.showSuccess(
'Backup pipeline deleted',
`The pipeline with the ID ${backup.id} has been deleted`,
);
this.closeDialog();
});
}
}
Loading

0 comments on commit b2ab418

Please sign in to comment.