-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Export geth metrics on VM testnet (#1351)
- Loading branch information
1 parent
25b62b5
commit ba60964
Showing
20 changed files
with
314 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,19 @@ | ||
import { deploy } from '../../../lib/vm-testnet-utils' | ||
import { createClusterIfNotExists, setupCluster, switchToClusterFromEnv } from 'src/lib/cluster' | ||
import { installHelmChart } from 'src/lib/prom-to-sd-utils' | ||
import { deploy } from 'src/lib/vm-testnet-utils' | ||
import { InitialArgv } from '../../deploy/initial' | ||
|
||
export const command = 'vm-testnet' | ||
export const describe = 'upgrade a testnet on a VM' | ||
export const builder = {} | ||
|
||
export const handler = async (argv: InitialArgv) => { | ||
// set up Kubernetes cluster that will have prometheus to stackdriver statefulset | ||
const createdCluster = await createClusterIfNotExists() | ||
await switchToClusterFromEnv() | ||
await setupCluster(argv.celoEnv, createdCluster) | ||
// deploy VM testnet with Terraform | ||
await deploy(argv.celoEnv) | ||
// deploy prom to sd statefulset | ||
await installHelmChart(argv.celoEnv) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import sleep from 'sleep-promise' | ||
import { envVar, fetchEnv } from 'src/lib/env-utils' | ||
import { installGenericHelmChart, removeGenericHelmChart } from 'src/lib/helm_deploy' | ||
import { getStatefulSetReplicas, scaleResource } from 'src/lib/kubernetes' | ||
import { execCmdWithExitOnFailure } from 'src/lib/utils' | ||
import { getInternalTxNodeIPs, getInternalValidatorIPs } from 'src/lib/vm-testnet-utils' | ||
|
||
const helmChartPath = '../helm-charts/prometheus-to-sd' | ||
|
||
// This deploys a helm chart to Kubernetes that exports prometheus metrics from | ||
// VM testnets Stackdriver | ||
|
||
export async function installHelmChart(celoEnv: string) { | ||
return installGenericHelmChart( | ||
celoEnv, | ||
releaseName(celoEnv), | ||
helmChartPath, | ||
await helmParameters(celoEnv) | ||
) | ||
} | ||
|
||
export async function removeHelmRelease(celoEnv: string) { | ||
await removeGenericHelmChart(releaseName(celoEnv)) | ||
} | ||
|
||
export async function upgradeHelmChart(celoEnv: string) { | ||
console.info(`Upgrading helm release ${releaseName(celoEnv)}`) | ||
|
||
const statefulSetName = `${celoEnv}-prom-to-sd` | ||
const replicaCount = await getStatefulSetReplicas(celoEnv, statefulSetName) | ||
|
||
console.info('Scaling StatefulSet down to 0...') | ||
await scaleResource(celoEnv, 'statefulset', statefulSetName, 0) | ||
await sleep(5000) | ||
|
||
const helmParams = await helmParameters(celoEnv) | ||
|
||
const upgradeCmdArgs = `${releaseName( | ||
celoEnv | ||
)} ${helmChartPath} --namespace ${celoEnv} ${helmParams.join(' ')}` | ||
|
||
if (process.env.CELOTOOL_VERBOSE === 'true') { | ||
await execCmdWithExitOnFailure(`helm upgrade --debug --dry-run ${upgradeCmdArgs}`) | ||
} | ||
await execCmdWithExitOnFailure(`helm upgrade ${upgradeCmdArgs}`) | ||
console.info(`Helm release ${releaseName(celoEnv)} upgrade successful`) | ||
|
||
console.info(`Scaling StatefulSet back up to ${replicaCount}...`) | ||
await scaleResource(celoEnv, 'statefulset', statefulSetName, replicaCount) | ||
} | ||
|
||
async function helmParameters(celoEnv: string) { | ||
// The metrics endpoints are only exposed internally | ||
const validatorIpAddresses = await getInternalValidatorIPs(celoEnv) | ||
const validatorCount = parseInt(fetchEnv(envVar.VALIDATORS), 10) | ||
const validatorPodIds = [] | ||
for (let i = 0; i < validatorCount; i++) { | ||
validatorPodIds.push(`${celoEnv}-validator-${i}`) | ||
} | ||
|
||
const txNodeIpAddresses = await getInternalTxNodeIPs(celoEnv) | ||
const txNodeCount = parseInt(fetchEnv(envVar.TX_NODES), 10) | ||
const txNodePodIds = [] | ||
for (let i = 0; i < txNodeCount; i++) { | ||
txNodePodIds.push(`${celoEnv}-tx-node-${i}`) | ||
} | ||
|
||
const allIps = validatorIpAddresses.concat(txNodeIpAddresses) | ||
const sources = allIps.map((ip: string) => `http://${ip}:9200/metrics`) | ||
|
||
const allPodIds = validatorPodIds.concat(txNodePodIds) | ||
|
||
return [ | ||
`--set metricsSources.geth="${sources.join('\\,')}"`, | ||
`--set promtosd.scrape_interval=${fetchEnv(envVar.PROMTOSD_SCRAPE_INTERVAL)}`, | ||
`--set promtosd.export_interval=${fetchEnv(envVar.PROMTOSD_EXPORT_INTERVAL)}`, | ||
`--set promtosd.podIds="${allPodIds.join('\\,')}"`, | ||
`--set promtosd.namespaceId=${celoEnv}`, | ||
`--set replicaCount=${validatorCount + txNodeCount}`, | ||
] | ||
} | ||
|
||
function releaseName(celoEnv: string) { | ||
return `${celoEnv}-prom-to-sd` | ||
} |
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
Oops, something went wrong.