@@ -24,6 +24,7 @@ interface Item {
2424 instanceId ?: string ;
2525 revision : number ;
2626 name : string ;
27+ enabled : boolean ;
2728}
2829
2930interface Dependencies {
@@ -37,9 +38,9 @@ export interface SLOHealth {
3738 sloName : string ;
3839 state : State ;
3940 health : {
40- overall : TransformHealth ;
41- rollup : HealthStatus ;
42- summary : HealthStatus ;
41+ overall : HealthStatus ;
42+ rollup : TransformHealth ;
43+ summary : TransformHealth ;
4344 } ;
4445}
4546
@@ -49,11 +50,11 @@ const STALE_THRESHOLD_MINUTES = 2 * 24 * 60;
4950export async function computeHealth ( list : Item [ ] , deps : Dependencies ) : Promise < SLOHealth [ ] > {
5051 const [ summaryDocsById , transformStatsById ] = await Promise . all ( [
5152 getSummaryDocsById ( list , deps ) ,
52- getTransformStats ( list , deps ) ,
53+ getTransformStatsById ( list , deps ) ,
5354 ] ) ;
5455
5556 return list . map ( ( item ) => {
56- const health = computeTransformHealth ( transformStatsById , item ) ;
57+ const health = computeTransformsHealth ( transformStatsById , item ) ;
5758 const state = computeTransformState ( summaryDocsById , item ) ;
5859
5960 return {
@@ -92,7 +93,7 @@ async function getSummaryDocsById(list: Item[], deps: Dependencies) {
9293 return summaryDocsById ;
9394}
9495
95- async function getTransformStats (
96+ async function getTransformStatsById (
9697 list : Item [ ] ,
9798 deps : Dependencies
9899) : Promise < Dictionary < TransformGetTransformStatsTransformStats > > {
@@ -144,38 +145,47 @@ function computeTransformState(
144145
145146function getTransformHealth (
146147 transformStat ?: TransformGetTransformStatsTransformStats
147- ) : HealthStatus {
148+ ) : TransformHealth {
148149 if ( ! transformStat ) {
149150 return {
150151 status : 'missing' ,
152+ state : 'unavailable' ,
151153 } ;
152154 }
155+
156+ const transformStatus = transformStat . health ?. status ?. toLowerCase ( ) ;
153157 const transformState = transformStat . state ?. toLowerCase ( ) ;
154- return transformStat . health ?. status ?. toLowerCase ( ) === 'green'
155- ? {
156- status : 'healthy' ,
157- transformState : transformState as HealthStatus [ 'transformState' ] ,
158- }
159- : {
160- status : 'unhealthy' ,
161- transformState : transformState as HealthStatus [ 'transformState' ] ,
162- } ;
158+
159+ return {
160+ status : transformStatus === 'green' ? 'healthy' : 'unhealthy' ,
161+ state :
162+ transformState === 'started'
163+ ? 'started'
164+ : transformState === 'stopped'
165+ ? 'stopped'
166+ : 'unavailable' ,
167+ } ;
163168}
164169
165- function computeTransformHealth (
170+ function computeTransformsHealth (
166171 transformStatsById : Dictionary < TransformGetTransformStatsTransformStats > ,
167172 item : Item
168- ) : { overall : 'healthy' | 'unhealthy' ; rollup : HealthStatus ; summary : HealthStatus } {
173+ ) : { overall : HealthStatus ; rollup : TransformHealth ; summary : TransformHealth } {
169174 const rollup = getTransformHealth ( transformStatsById [ getSLOTransformId ( item . id , item . revision ) ] ) ;
170175 const summary = getTransformHealth (
171176 transformStatsById [ getSLOSummaryTransformId ( item . id , item . revision ) ]
172177 ) ;
173178
174- const overall : 'healthy' | 'unhealthy' =
179+ const rollupStateMatchesSloEnabled =
180+ ( item . enabled && rollup . state === 'started' ) || ( ! item . enabled && rollup . state === 'stopped' ) ;
181+ const summaryStateMatchesSloEnabled =
182+ ( item . enabled && rollup . state === 'started' ) || ( ! item . enabled && rollup . state === 'stopped' ) ;
183+
184+ const overall : HealthStatus =
175185 rollup . status === 'healthy' &&
176- rollup . transformState === 'started' &&
186+ rollupStateMatchesSloEnabled &&
177187 summary . status === 'healthy' &&
178- summary . transformState === 'started'
188+ summaryStateMatchesSloEnabled
179189 ? 'healthy'
180190 : 'unhealthy' ;
181191
0 commit comments