From 83a6200a1a322c7fa5b2ba9ea3a2ce80333b50dd Mon Sep 17 00:00:00 2001 From: Rishabh Singh Date: Tue, 3 May 2022 12:29:28 +0530 Subject: [PATCH] changed variable scope to instance level (#114) Signed-off-by: Rishabh Singh --- lib/ci-stack.ts | 4 +++- lib/compute/jenkins-main-node.ts | 2 +- lib/monitoring/ci-alarms.ts | 15 ++++++++------- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/ci-stack.ts b/lib/ci-stack.ts index ab03c0f3..b93fcd57 100644 --- a/lib/ci-stack.ts +++ b/lib/ci-stack.ts @@ -41,6 +41,8 @@ export interface CIStackProps extends StackProps { } export class CIStack extends Stack { + public readonly monitoring: JenkinsMonitoring; + constructor(scope: Construct, id: string, props: CIStackProps) { super(scope, id, props); @@ -121,7 +123,7 @@ export class CIStack extends Stack { useSsl, }); - const monitoring = new JenkinsMonitoring(this, externalLoadBalancer, mainJenkinsNode); + this.monitoring = new JenkinsMonitoring(this, externalLoadBalancer, mainJenkinsNode); if (additionalCommandsContext.toString() !== 'undefined') { new RunAdditionalCommands(this, additionalCommandsContext.toString()); diff --git a/lib/compute/jenkins-main-node.ts b/lib/compute/jenkins-main-node.ts index 1c41d26d..cffa6a00 100644 --- a/lib/compute/jenkins-main-node.ts +++ b/lib/compute/jenkins-main-node.ts @@ -368,7 +368,7 @@ export class JenkinsMainNode { // Download jenkins-cli from the local machine InitCommand.shellCommand('until $(curl --output /dev/null --silent --head --fail http://localhost:8080); do sleep 5; done &&' - +' wget -O "jenkins-cli.jar" http://localhost:8080/jnlpJars/jenkins-cli.jar'), + + ' wget -O "jenkins-cli.jar" http://localhost:8080/jnlpJars/jenkins-cli.jar'), InitFile.fromFileInline('/initial_jenkins.yaml', jenkinsyaml), diff --git a/lib/monitoring/ci-alarms.ts b/lib/monitoring/ci-alarms.ts index e78b8f69..4876d808 100644 --- a/lib/monitoring/ci-alarms.ts +++ b/lib/monitoring/ci-alarms.ts @@ -14,11 +14,12 @@ import { JenkinsExternalLoadBalancer } from '../network/ci-external-load-balance import { JenkinsMainNode } from '../compute/jenkins-main-node'; export class JenkinsMonitoring { + public readonly alarms: Alarm[] = []; + constructor(stack: Stack, externalLoadBalancer: JenkinsExternalLoadBalancer, mainNode: JenkinsMainNode) { const dashboard = new Dashboard(stack, 'AlarmDashboard'); - const alarms: Alarm[] = []; - alarms.push(new Alarm(stack, 'ExternalLoadBalancerUnhealthyHosts', { + this.alarms.push(new Alarm(stack, 'ExternalLoadBalancerUnhealthyHosts', { alarmDescription: 'If any hosts behind the load balancer are unhealthy', metric: externalLoadBalancer.targetGroup.metricUnhealthyHostCount(), evaluationPeriods: 3, @@ -27,7 +28,7 @@ export class JenkinsMonitoring { treatMissingData: TreatMissingData.BREACHING, })); - alarms.push(new Alarm(stack, 'MainNodeTooManyJenkinsProcessesFound', { + this.alarms.push(new Alarm(stack, 'MainNodeTooManyJenkinsProcessesFound', { alarmDescription: 'Only one jenkins process should run at any given time on the main node, there might be a cloudwatch configuration issue', metric: mainNode.ec2InstanceMetrics.foundJenkinsProcessCount.with({ statistic: 'max' }), evaluationPeriods: 3, @@ -36,7 +37,7 @@ export class JenkinsMonitoring { treatMissingData: TreatMissingData.IGNORE, })); - alarms.push(new Alarm(stack, 'MainNodeHighCpuUtilization', { + this.alarms.push(new Alarm(stack, 'MainNodeHighCpuUtilization', { alarmDescription: 'The jenkins process is using much more CPU that expected, it should be investigated for a stuck process/job', metric: mainNode.ec2InstanceMetrics.cpuTime.with({ statistic: 'max' }), evaluationPeriods: 5, @@ -45,7 +46,7 @@ export class JenkinsMonitoring { treatMissingData: TreatMissingData.IGNORE, })); - alarms.push(new Alarm(stack, 'MainNodeHighMemoryUtilization', { + this.alarms.push(new Alarm(stack, 'MainNodeHighMemoryUtilization', { alarmDescription: 'The jenkins process is using more memory than expected, it should be investigated for a large number of jobs or heavy weight jobs', metric: mainNode.ec2InstanceMetrics.memUsed.with({ statistic: 'max' }), evaluationPeriods: 5, @@ -54,7 +55,7 @@ export class JenkinsMonitoring { treatMissingData: TreatMissingData.IGNORE, })); - alarms.push(new Alarm(stack, 'MainNodeCloudwatchEvents', { + this.alarms.push(new Alarm(stack, 'MainNodeCloudwatchEvents', { alarmDescription: `Cloudwatch events have stopped being received from the main node. Use session manager to exam the host and the /opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log`, metric: mainNode.ec2InstanceMetrics.memUsed.with({ statistic: 'n' }), @@ -69,7 +70,7 @@ Use session manager to exam the host and the /opt/aws/amazon-cloudwatch-agent/lo treatMissingData: TreatMissingData.MISSING, })); - alarms + this.alarms .map((alarm) => new AlarmWidget({ alarm })) .forEach((widget) => dashboard.addWidgets(widget)); }