-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Github Automation App to monitor the critical workflows
Signed-off-by: Prudhvi Godithi <[email protected]>
- Loading branch information
1 parent
6a23bf1
commit e0919e3
Showing
6 changed files
with
180 additions
and
4 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
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,48 @@ | ||
/** | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
import {Duration, Stack} from "aws-cdk-lib"; | ||
import {Construct} from "constructs"; | ||
import {Alarm, ComparisonOperator, Metric, TreatMissingData} from "aws-cdk-lib/aws-cloudwatch"; | ||
|
||
export interface AlarmProps { | ||
readonly namespace: string; | ||
readonly metricName: string; | ||
readonly workflows: string[]; | ||
} | ||
|
||
export class GitHubWorkflowMonitorAlarms extends Stack { | ||
readonly workflowAlarmsArn: string[] = []; | ||
readonly metricName: string | ||
constructor(scope: Construct, id: string, props: AlarmProps) { | ||
super(scope, id); | ||
props.workflows.forEach(workflow => { | ||
const dimensionValue = workflow; | ||
const workflowMetric = new Metric({ | ||
namespace: props.namespace, | ||
metricName: props.metricName, | ||
dimensionsMap: { | ||
Workflow: dimensionValue, | ||
}, | ||
period: Duration.minutes(5), | ||
statistic: 'Sum', | ||
}); | ||
|
||
const alarm = new Alarm (this, `OpenSearchMetrics-GitHubApp-${dimensionValue.replace(/\s+/g, '')}-FailuresAlarm`, { | ||
alarmName: `OpenSearchMetrics-GitHubApp-${dimensionValue.replace(/\s+/g, '')}-FailuresAlarm`, | ||
metric: workflowMetric, | ||
threshold: 3, | ||
evaluationPeriods: 1, | ||
comparisonOperator: ComparisonOperator.GREATER_THAN_OR_EQUAL_TO_THRESHOLD, | ||
alarmDescription: `Alarm for ${workflow} failures`, | ||
actionsEnabled: true, | ||
}); | ||
this.workflowAlarmsArn.push(alarm.alarmArn) | ||
}); | ||
} | ||
} |
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
63 changes: 63 additions & 0 deletions
63
infrastructure/test/githubWorkflowMonitorAlarms-stack.test.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,63 @@ | ||
/** | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
import {App} from "aws-cdk-lib"; | ||
import {VpcStack} from "../lib/stacks/vpc"; | ||
import {OpenSearchMetricsSecretsStack} from "../lib/stacks/secrets"; | ||
import {GitHubWorkflowMonitorAlarms} from "../lib/stacks/gitHubWorkflowMonitorAlarms"; | ||
import {GitHubAutomationApp} from "../lib/stacks/gitHubAutomationApp"; | ||
import Project from "../lib/enums/project"; | ||
import {Match, Template} from "aws-cdk-lib/assertions"; | ||
|
||
test('OpenSearch Workflow Monitor Alarms test ', () => { | ||
const app = new App(); | ||
|
||
const gitHubWorkflowMonitorAlarms = new GitHubWorkflowMonitorAlarms(app, "Test-OpenSearchMetrics-GitHubWorkflowMonitor-Alarms", { | ||
namespace: 'GitHubActions', | ||
metricName: 'WorkflowRunFailures', | ||
workflows: [ | ||
'Publish snapshots to Apache Maven repositories', | ||
'Publish snapshots to maven', | ||
'Run performance benchmark on pull request', | ||
], | ||
}); | ||
|
||
const template = Template.fromStack(gitHubWorkflowMonitorAlarms); | ||
|
||
|
||
template.hasResourceProperties('AWS::CloudWatch::Alarm', { | ||
AlarmName: 'OpenSearchMetrics-GitHubApp-Publishsnapshotstomaven-FailuresAlarm', | ||
Namespace: 'GitHubActions', | ||
MetricName: 'WorkflowRunFailures', | ||
Dimensions: Match.arrayWith([{ | ||
Name: 'Workflow', | ||
Value: 'Publish snapshots to maven' | ||
}]), | ||
ComparisonOperator: 'GreaterThanOrEqualToThreshold', | ||
EvaluationPeriods: 1, | ||
Threshold: 3, | ||
Period: 300, | ||
Statistic: 'Sum' | ||
}); | ||
|
||
template.hasResourceProperties('AWS::CloudWatch::Alarm', { | ||
AlarmName: 'OpenSearchMetrics-GitHubApp-Runperformancebenchmarkonpullrequest-FailuresAlarm', | ||
Namespace: 'GitHubActions', | ||
MetricName: 'WorkflowRunFailures', | ||
Dimensions: Match.arrayWith([{ | ||
Name: 'Workflow', | ||
Value: 'Run performance benchmark on pull request' | ||
}]), | ||
ComparisonOperator: 'GreaterThanOrEqualToThreshold', | ||
EvaluationPeriods: 1, | ||
Threshold: 3, | ||
Period: 300, | ||
Statistic: 'Sum' | ||
}); | ||
|
||
}); |