-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added pulse check to check BE health (#647)
* added health check * minor change * addressing comments * addressing comments * ng build files
- Loading branch information
1 parent
41d597a
commit e3eb37c
Showing
12 changed files
with
112 additions
and
8 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 was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
ui/dist/ui/styles.77cd407a0323ef69.css → ui/dist/ui/styles.6d8ba0a3d523f825.css
Large diffs are not rendered by default.
Oops, something went wrong.
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
16 changes: 16 additions & 0 deletions
16
ui/src/app/services/backend-health/backend-health.service.spec.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,16 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { BackendHealthService } from './backend-health.service'; | ||
|
||
describe('BackendHealthService', () => { | ||
let service: BackendHealthService; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({}); | ||
service = TestBed.inject(BackendHealthService); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
}); |
75 changes: 75 additions & 0 deletions
75
ui/src/app/services/backend-health/backend-health.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,75 @@ | ||
import { HttpClient } from '@angular/common/http'; | ||
import { Injectable } from '@angular/core'; | ||
import { MatDialog } from '@angular/material/dialog'; | ||
import { catchError, from, interval, map, Observable, of, Subject, Subscription, takeUntil } from 'rxjs'; | ||
import { InfodialogComponent } from 'src/app/components/infodialog/infodialog.component'; | ||
import { FetchService } from '../fetch/fetch.service'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class BackendHealthService { | ||
private healthCheckSubscription: Subscription = new Subscription; | ||
private unHealthyCheckCount: number = 0; | ||
private MAX_UNHEALTHY_CHECK_ATTEMPTS: number = 5 | ||
|
||
constructor(private fetch: FetchService, | ||
private dialog: MatDialog) { } | ||
|
||
startHealthCheck() { | ||
this.healthCheckSubscription = interval(5000).subscribe(() => { | ||
this.checkBackendHealth(); | ||
}); | ||
} | ||
|
||
stopHealthCheck() { | ||
if (this.healthCheckSubscription) { | ||
this.healthCheckSubscription.unsubscribe(); | ||
} | ||
} | ||
|
||
checkBackendHealth() { | ||
this.checkHealth().subscribe( | ||
(isHealthy) => { | ||
if (!isHealthy) { | ||
if (this.unHealthyCheckCount == this.MAX_UNHEALTHY_CHECK_ATTEMPTS) { | ||
// Backend is unhealthy, open the dialog and unsubscribe | ||
this.openHealthDialog(); | ||
} | ||
this.unHealthyCheckCount++; | ||
} else { | ||
this.unHealthyCheckCount = 0; | ||
} | ||
} | ||
); | ||
} | ||
|
||
openHealthDialog() { | ||
let dialogRef = this.dialog.open(InfodialogComponent, { | ||
width: '500px', | ||
data: { | ||
message: "Please check terminal logs for more details. In case of a crash please file a <a href='https://github.com/GoogleCloudPlatform/spanner-migration-tool/issues' target='_blank' class='a-link'>github</a> issue with all the details.", | ||
type: 'error', | ||
title: 'Spanner migration tool unresponsive', | ||
} | ||
}); | ||
this.stopHealthCheck(); | ||
dialogRef.afterClosed().subscribe(() => { | ||
this.startHealthCheck(); | ||
}) | ||
} | ||
|
||
checkHealth(): Observable<boolean> { | ||
return from(this.fetch.checkBackendHealth()).pipe( | ||
map(() => true), | ||
catchError(() => { | ||
return of(false); | ||
}) | ||
); | ||
} | ||
|
||
ngOnDestroy() { | ||
// Stop health checks when the service is destroyed | ||
this.stopHealthCheck(); | ||
} | ||
} |
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