Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check healthcheck before version for discprov selection in libs #60

Merged
merged 1 commit into from
Sep 17, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 27 additions & 20 deletions libs/src/services/ethContracts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,32 +150,39 @@ class EthContracts {
try {
selectedDiscoveryProvider = await Utils.promiseFight(
discoveryProviders.map(async (discprov) => {
const {
data: { service: serviceName, version: serviceVersion }
} = await axios({ url: urlJoin(discprov.endpoint, 'version'), method: 'get' })
try {
const healthResp = await axios({ url: urlJoin(discprov.endpoint, 'health_check'), method: 'get' })
if (healthResp.status !== 200) throw new Error(`Discprov healthcheck failed ${discprov.endpoint}`)

// Compare chain service name
if (!this.expectedServiceVersions.hasOwnProperty(serviceName)) {
throw new Error(`Invalid service name: ${serviceName}`)
}
const {
data: { service: serviceName, version: serviceVersion }
} = await axios({ url: urlJoin(discprov.endpoint, 'version'), method: 'get' })

if (serviceName !== spType) {
throw new Error(`Invalid service type: ${serviceName}. Expected ${spType}`)
}
// Compare chain service name
if (!this.expectedServiceVersions.hasOwnProperty(serviceName)) {
throw new Error(`Invalid service name: ${serviceName}`)
}

if (!semver.valid(serviceVersion)) {
throw new Error(`Invalid semver version found - ${serviceVersion}`)
}
if (serviceName !== spType) {
throw new Error(`Invalid service type: ${serviceName}. Expected ${spType}`)
}

let expectedVersion = this.expectedServiceVersions[serviceName]
if (expectedVersion !== serviceVersion) {
let validSPVersion = this.isValidSPVersion(expectedVersion, serviceVersion)
if (!validSPVersion) {
throw new Error(`Invalid service version: ${serviceName}. Expected ${expectedVersion}, found ${serviceVersion}`)
if (!semver.valid(serviceVersion)) {
throw new Error(`Invalid semver version found - ${serviceVersion}`)
}
}

return discprov.endpoint
let expectedVersion = this.expectedServiceVersions[serviceName]
if (expectedVersion !== serviceVersion) {
let validSPVersion = this.isValidSPVersion(expectedVersion, serviceVersion)
if (!validSPVersion) {
throw new Error(`Invalid service version: ${serviceName}. Expected ${expectedVersion}, found ${serviceVersion}`)
}
}

return discprov.endpoint
} catch (err) {
throw new Error(err)
}
})
)
} catch (err) {
Expand Down