5
5
*/
6
6
7
7
import * as express from "express" ;
8
- import { WorkspaceHealthMonitoring } from "./workspace/workspace-health-monitoring" ;
9
- import { TraceContext } from "@gitpod/gitpod-protocol/lib/util/tracing" ;
10
- import { log } from "@gitpod/gitpod-protocol/lib/util/logging" ;
11
- import { injectable , inject } from "inversify" ;
8
+ import { injectable } from "inversify" ;
12
9
import { registerServerMetrics } from "../../src/prometheus-metrics" ;
13
10
import * as prometheusClient from "prom-client" ;
14
11
import { registerDBMetrics } from "@gitpod/gitpod-db/lib" ;
15
12
16
13
@injectable ( )
17
- export class MonitoringEndpointsAppEE extends WorkspaceHealthMonitoring {
18
- @inject ( WorkspaceHealthMonitoring ) protected readonly workspaceHealthMonitoring : WorkspaceHealthMonitoring ;
19
-
14
+ export class MonitoringEndpointsAppEE {
20
15
public create ( ) : express . Application {
21
16
const registry = prometheusClient . register ;
22
17
@@ -34,53 +29,6 @@ export class MonitoringEndpointsAppEE extends WorkspaceHealthMonitoring {
34
29
}
35
30
} ) ;
36
31
37
- monApp . get ( "/workspace-health" , async ( req , res ) => {
38
- try {
39
- const result = await checkWorkspaceHealth ( { } , this . workspaceHealthMonitoring , ! ! req . query . extra ) ;
40
- if ( result . unhealthy > 0 ) {
41
- console . warn ( "not all workspaces are healthy" , result ) ;
42
- res . status ( 406 ) . send ( result ) ;
43
- } else {
44
- res . status ( 200 ) . send ( result ) ;
45
- }
46
- } catch ( err ) {
47
- log . debug ( "failed to check workspace health" , err ) ;
48
- res . status ( 500 ) . send ( err ) ;
49
- }
50
- } ) ;
51
-
52
32
return monApp ;
53
33
}
54
34
}
55
-
56
- async function checkWorkspaceHealth (
57
- ctx : TraceContext ,
58
- workspaceHealthMonitoring : WorkspaceHealthMonitoring ,
59
- extra : boolean = false ,
60
- ) {
61
- const span = TraceContext . startSpan ( "checkWorkspaceHealth" , ctx ) ;
62
- const result = await workspaceHealthMonitoring . probeAllRunningWorkspaces ( { span } ) ;
63
- const numUnhealthy = result
64
- . map ( ( r ) => ( r . ok ? 0 : 1 ) )
65
- . reduce ( ( acc : number , cur : number ) => ( acc + cur ) as number , 0 ) ;
66
- let returnValue = {
67
- status :
68
- numUnhealthy > 0 ? ( numUnhealthy == result . length ? "unhealthy" : "partially healthy" ) : "fully healthy" ,
69
- healthy : result . length - numUnhealthy ,
70
- unhealthy : numUnhealthy ,
71
- total : result . length ,
72
- timestamp : Date . now ( ) ,
73
- } ;
74
- if ( extra && numUnhealthy > 0 ) {
75
- span . finish ( ) ;
76
- return {
77
- ...returnValue ,
78
- extra : {
79
- unhealthyWorkspaces : result . filter ( ( r ) => ! r . ok ) ,
80
- notRunningWorkspaces : result . filter ( ( r ) => r . status !== "running" ) ,
81
- } ,
82
- } ;
83
- }
84
- span . finish ( ) ;
85
- return returnValue ;
86
- }
0 commit comments