-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(admin-ui): Add system health status page
Relates to #289
- Loading branch information
1 parent
e2c6a00
commit b3411f2
Showing
14 changed files
with
220 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
packages/admin-ui/src/lib/core/src/data/utils/get-server-location.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { getAppConfig } from '../../app.config'; | ||
|
||
/** | ||
* Returns the location of the server, e.g. "http://localhost:3000" | ||
*/ | ||
export function getServerLocation(): string { | ||
const { apiHost, apiPort, adminApiPath, tokenMethod } = getAppConfig(); | ||
const host = apiHost === 'auto' ? `${location.protocol}//${location.hostname}` : apiHost; | ||
const port = apiPort | ||
? apiPort === 'auto' | ||
? location.port === '' | ||
? '' | ||
: `:${location.port}` | ||
: `:${apiPort}` | ||
: ''; | ||
return `${host}${port}`; | ||
} |
67 changes: 67 additions & 0 deletions
67
packages/admin-ui/src/lib/core/src/providers/health-check/health-check.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { HttpClient } from '@angular/common/http'; | ||
import { Injectable } from '@angular/core'; | ||
import { getServerLocation } from '@vendure/admin-ui/core'; | ||
import { merge, Observable, of, Subject, timer } from 'rxjs'; | ||
import { catchError, map, shareReplay, switchMap, throttleTime } from 'rxjs/operators'; | ||
|
||
export type SystemStatus = 'ok' | 'error'; | ||
|
||
export interface HealthCheckResult { | ||
status: SystemStatus; | ||
info: { [name: string]: HealthCheckSuccessResult }; | ||
details: { [name: string]: HealthCheckSuccessResult | HealthCheckErrorResult }; | ||
error: { [name: string]: HealthCheckErrorResult }; | ||
} | ||
|
||
export interface HealthCheckSuccessResult { | ||
status: 'up'; | ||
} | ||
|
||
export interface HealthCheckErrorResult { | ||
status: 'down'; | ||
message: string; | ||
} | ||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class HealthCheckService { | ||
status$: Observable<SystemStatus>; | ||
details$: Observable<Array<{ key: string; result: HealthCheckSuccessResult | HealthCheckErrorResult }>>; | ||
lastCheck$: Observable<Date>; | ||
|
||
private readonly pollingDelayMs = 60 * 1000; | ||
private readonly healthCheckEndpoint: string; | ||
private readonly _refresh = new Subject(); | ||
|
||
constructor(private httpClient: HttpClient) { | ||
this.healthCheckEndpoint = getServerLocation() + '/health'; | ||
|
||
const refresh$ = this._refresh.pipe(throttleTime(1000)); | ||
const result$ = merge(timer(0, this.pollingDelayMs), refresh$).pipe( | ||
switchMap(() => this.checkHealth()), | ||
shareReplay(1), | ||
); | ||
|
||
this.status$ = result$.pipe(map(res => res.status)); | ||
this.details$ = result$.pipe( | ||
map(res => | ||
Object.keys(res.details).map(key => { | ||
return { key, result: res.details[key] }; | ||
}), | ||
), | ||
); | ||
this.lastCheck$ = result$.pipe(map(res => res.lastChecked)); | ||
} | ||
|
||
refresh() { | ||
this._refresh.next(); | ||
} | ||
|
||
private checkHealth() { | ||
return this.httpClient.get<HealthCheckResult>(this.healthCheckEndpoint).pipe( | ||
catchError(err => of(err.error)), | ||
map(res => ({ ...res, lastChecked: new Date() })), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
packages/admin-ui/src/lib/settings/src/components/health-check/health-check.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<vdr-action-bar> | ||
<vdr-ab-left> | ||
<div class="system-status-header" *ngIf="healthCheckService.status$ | async as status"> | ||
<div class="status-icon"> | ||
<clr-icon | ||
[attr.shape]="status === 'ok' ? 'check-circle' : 'exclamation-circle'" | ||
[ngClass]="{ 'is-success': status === 'ok', 'is-danger': status !== 'ok' }" | ||
size="48" | ||
></clr-icon> | ||
</div> | ||
<div class="status-detail"> | ||
<ng-container *ngIf="status === 'ok'; else error"> | ||
{{ 'system.health-all-systems-up' | translate }} | ||
</ng-container> | ||
<ng-template #error> | ||
{{ 'system.health-error' | translate }} | ||
</ng-template> | ||
<div class="last-checked"> | ||
{{ 'system.health-last-checked' | translate }}: | ||
{{ healthCheckService.lastCheck$ | async | date: 'mediumTime' }} | ||
</div> | ||
</div> | ||
</div> | ||
</vdr-ab-left> | ||
<vdr-ab-right> | ||
<vdr-action-bar-items locationId="system-status"></vdr-action-bar-items> | ||
<button class="btn btn-secondary" (click)="healthCheckService.refresh()"> | ||
<clr-icon shape="refresh"></clr-icon> {{ 'system.health-refresh' | translate }} | ||
</button> | ||
</vdr-ab-right> | ||
</vdr-action-bar> | ||
|
||
<table class="table"> | ||
<thead> | ||
<tr> | ||
<th class="left"> | ||
{{ 'common.name' | translate }} | ||
</th> | ||
<th class="left"> | ||
{{ 'system.health-status' | translate }} | ||
</th> | ||
<th class="left"> | ||
{{ 'system.health-message' | translate }} | ||
</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr *ngFor="let row of healthCheckService.details$ | async"> | ||
<td class="align-middle left">{{ row.key }}</td> | ||
<td class="align-middle left"> | ||
<vdr-chip [colorType]="row.result.status === 'up' ? 'success' : 'error'"> | ||
<ng-container *ngIf="row.result.status === 'up'; else down"> | ||
<clr-icon shape="check-circle"></clr-icon> | ||
{{ 'system.health-status-up' | translate }} | ||
</ng-container> | ||
<ng-template #down> | ||
<clr-icon shape="exclamation-circle"></clr-icon> | ||
{{ 'system.health-status-down' | translate }} | ||
</ng-template> | ||
</vdr-chip> | ||
</td> | ||
<td class="align-middle left">{{ row.result.message }}</td> | ||
</tr> | ||
</tbody> | ||
</table> |
15 changes: 15 additions & 0 deletions
15
packages/admin-ui/src/lib/settings/src/components/health-check/health-check.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
@import "variables"; | ||
|
||
.system-status-header { | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: flex-start; | ||
|
||
.status-detail { | ||
font-weight: bold; | ||
} | ||
.last-checked { | ||
font-weight: normal; | ||
color: $color-grey-500; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
packages/admin-ui/src/lib/settings/src/components/health-check/health-check.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { ChangeDetectionStrategy, Component } from '@angular/core'; | ||
import { HealthCheckService } from '@vendure/admin-ui/core'; | ||
|
||
@Component({ | ||
selector: 'vdr-health-check', | ||
templateUrl: './health-check.component.html', | ||
styleUrls: ['./health-check.component.scss'], | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class HealthCheckComponent { | ||
constructor(public healthCheckService: HealthCheckService) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters