-
Notifications
You must be signed in to change notification settings - Fork 903
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(google): differentiate among autohealing health check kinds
- Loading branch information
1 parent
467cb42
commit b920442
Showing
9 changed files
with
171 additions
and
18 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
83 changes: 83 additions & 0 deletions
83
app/scripts/modules/google/src/healthCheck/healthCheckUtils.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,83 @@ | ||
import { IGceHealthCheck, IGceHealthCheckKind } from 'google/domain'; | ||
import { | ||
parseHealthCheckUrl, | ||
getHealthCheckOptions, | ||
getDuplicateHealthCheckNames, | ||
} from 'google/healthCheck/healthCheckUtils'; | ||
|
||
describe('Health check display utils', () => { | ||
let healthChecks: IGceHealthCheck[]; | ||
beforeEach(() => { | ||
healthChecks = getSampleHealthChecks(); | ||
}); | ||
describe('parseHealthCheckUrl', () => { | ||
it('extracts name and kind from health check url', () => { | ||
healthChecks.forEach(hc => { | ||
expect(parseHealthCheckUrl(hc.selfLink)).toEqual({ | ||
healthCheckName: hc.name, | ||
healthCheckKind: hc.kind, | ||
}); | ||
}); | ||
}); | ||
}); | ||
describe('getHealthCheckOptions', () => { | ||
it('adds appropriate displayName to each health check, including kind when name is duplicate', () => { | ||
expect(getHealthCheckOptions(healthChecks).map(hc => hc.displayName)).toEqual([ | ||
'hello (healthCheck)', | ||
'hello (httpsHealthCheck)', | ||
'ping', | ||
]); | ||
}); | ||
}); | ||
describe('getDuplicateHealthCheckNames', () => { | ||
it('returns list of names that occur more than once in list of health checks', () => { | ||
const duplicates = getDuplicateHealthCheckNames(healthChecks); | ||
expect(duplicates.size).toEqual(1); | ||
expect(duplicates.has('hello')).toBeTruthy(); | ||
}); | ||
}); | ||
}); | ||
|
||
function getSampleHealthChecks(): IGceHealthCheck[] { | ||
return [ | ||
{ | ||
account: 'my-gce-account', | ||
checkIntervalSec: 1, | ||
healthCheckType: 'HTTP', | ||
healthyThreshold: 1, | ||
kind: IGceHealthCheckKind.healthCheck, | ||
name: 'hello', | ||
port: 8080, | ||
requestPath: '/hello', | ||
selfLink: 'https://www.googleapis.com/compute/beta/projects/my-project/global/healthChecks/hello', | ||
timeoutSec: 1, | ||
unhealthyThreshold: 1, | ||
}, | ||
{ | ||
account: 'my-gce-account', | ||
checkIntervalSec: 1, | ||
healthCheckType: 'HTTPS', | ||
healthyThreshold: 1, | ||
kind: IGceHealthCheckKind.httpsHealthCheck, | ||
name: 'hello', | ||
port: 8080, | ||
requestPath: '/hello', | ||
selfLink: 'https://www.googleapis.com/compute/beta/projects/my-project/global/httpsHealthChecks/hello', | ||
timeoutSec: 1, | ||
unhealthyThreshold: 1, | ||
}, | ||
{ | ||
account: 'my-gce-account', | ||
checkIntervalSec: 1, | ||
healthCheckType: 'HTTP', | ||
healthyThreshold: 1, | ||
kind: IGceHealthCheckKind.httpHealthCheck, | ||
name: 'ping', | ||
port: 8080, | ||
requestPath: '/ping', | ||
selfLink: 'https://www.googleapis.com/compute/beta/projects/my-project/global/httpHealthChecks/ping', | ||
timeoutSec: 1, | ||
unhealthyThreshold: 1, | ||
}, | ||
]; | ||
} |
47 changes: 47 additions & 0 deletions
47
app/scripts/modules/google/src/healthCheck/healthCheckUtils.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,47 @@ | ||
import { IGceHealthCheck, IGceHealthCheckKind } from 'google/domain'; | ||
|
||
export interface IGceHealthCheckOption { | ||
displayName: string; | ||
kind: IGceHealthCheckKind; | ||
name: string; | ||
selfLink: string; | ||
} | ||
|
||
export function parseHealthCheckUrl(url: string): { healthCheckName: string; healthCheckKind: IGceHealthCheckKind } { | ||
const healthCheckPathParts = url.split('/'); | ||
if (healthCheckPathParts.length < 2) { | ||
throw new Error(`Health check url ${url} missing expected segments.`); | ||
} | ||
const healthCheckName = healthCheckPathParts[healthCheckPathParts.length - 1]; | ||
const healthCheckKind = healthCheckPathParts[healthCheckPathParts.length - 2].slice(0, -1); | ||
return { | ||
healthCheckName, | ||
healthCheckKind: healthCheckKind as IGceHealthCheckKind, | ||
}; | ||
} | ||
|
||
export function getHealthCheckOptions(healthChecks: IGceHealthCheck[]): IGceHealthCheckOption[] { | ||
const duplicateNames = getDuplicateHealthCheckNames(healthChecks); | ||
return healthChecks.map(hc => { | ||
const isNameDupe = duplicateNames.has(hc.name); | ||
return { | ||
displayName: isNameDupe ? `${hc.name} (${hc.kind})` : hc.name, | ||
kind: hc.kind, | ||
name: hc.name, | ||
selfLink: hc.selfLink, | ||
}; | ||
}); | ||
} | ||
|
||
export function getDuplicateHealthCheckNames(healthChecks: IGceHealthCheck[]): Set<string> { | ||
const allNames = new Set(); | ||
const duplicateNames = new Set(); | ||
healthChecks.forEach(hc => { | ||
if (allNames.has(hc.name)) { | ||
duplicateNames.add(hc.name); | ||
} else { | ||
allNames.add(hc.name); | ||
} | ||
}); | ||
return duplicateNames; | ||
} |
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
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