-
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.
Reindex GitHub Events into maintainer inactivity data
Signed-off-by: Brandon Shien <[email protected]>
- Loading branch information
Showing
19 changed files
with
1,327 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/** | ||
* 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, StackProps } from "aws-cdk-lib"; | ||
import { Rule, Schedule } from "aws-cdk-lib/aws-events"; | ||
import { SfnStateMachine } from "aws-cdk-lib/aws-events-targets"; | ||
import { JsonPath, StateMachine } from "aws-cdk-lib/aws-stepfunctions"; | ||
import { LambdaInvoke } from "aws-cdk-lib/aws-stepfunctions-tasks"; | ||
import { Construct } from 'constructs'; | ||
import { OpenSearchLambda } from "../constructs/lambda"; | ||
import { OpenSearchDomainStack } from "./opensearch"; | ||
import { VpcStack } from "./vpc"; | ||
|
||
export interface OpenSearchMaintainerInactivityWorkflowStackProps extends StackProps { | ||
readonly opensearchDomainStack: OpenSearchDomainStack; | ||
readonly vpcStack: VpcStack; | ||
readonly lambdaPackage: string | ||
} | ||
|
||
export interface WorkflowComponent { | ||
opensearchMaintainerInactivityWorkflowStateMachineName: string | ||
} | ||
|
||
export class OpenSearchMaintainerInactivityWorkflowStack extends Stack { | ||
public readonly workflowComponent: WorkflowComponent; | ||
constructor(scope: Construct, id: string, props: OpenSearchMaintainerInactivityWorkflowStackProps) { | ||
super(scope, id, props); | ||
|
||
const maintainerInactivityTask = this.createMaintainerInactivityTask( | ||
this, | ||
props.opensearchDomainStack, | ||
props.vpcStack, | ||
props.lambdaPackage | ||
); | ||
const opensearchMaintainerInactivityWorkflow = new StateMachine(this, 'OpenSearchMaintainerInactivityWorkflow', { | ||
definition: maintainerInactivityTask, | ||
timeout: Duration.minutes(15), | ||
stateMachineName: 'OpenSearchMaintainerInactivityWorkflow' | ||
}) | ||
|
||
new Rule(this, 'MaintainerInactivityWorkflow-Every-Day', { | ||
schedule: Schedule.expression('cron(15 0 * * ? *)'), | ||
targets: [new SfnStateMachine(opensearchMaintainerInactivityWorkflow)], | ||
}); | ||
|
||
this.workflowComponent = { | ||
opensearchMaintainerInactivityWorkflowStateMachineName: opensearchMaintainerInactivityWorkflow.stateMachineName | ||
} | ||
} | ||
|
||
private createMaintainerInactivityTask(scope: Construct, opensearchDomainStack: OpenSearchDomainStack, | ||
vpcStack: VpcStack, lambdaPackage: string) { | ||
const openSearchDomain = opensearchDomainStack.domain; | ||
const maintainerInactivityLambda = new OpenSearchLambda(scope, "OpenSearchMetricsMaintainerInactivityLambdaFunction", { | ||
lambdaNameBase: "OpenSearchMetricsMaintainerInactivity", | ||
handler: "org.opensearchmetrics.lambda.MaintainerInactivityLambda", | ||
lambdaZipPath: `../../../build/distributions/${lambdaPackage}`, | ||
vpc: vpcStack.vpc, | ||
securityGroup: vpcStack.securityGroup, | ||
role: opensearchDomainStack.openSearchMetricsLambdaRole, | ||
environment: { | ||
OPENSEARCH_DOMAIN_ENDPOINT: openSearchDomain.domainEndpoint, | ||
OPENSEARCH_DOMAIN_REGION: openSearchDomain.env.region, | ||
OPENSEARCH_DOMAIN_ROLE: opensearchDomainStack.fullAccessRole.roleArn, | ||
}, | ||
}).lambda; | ||
return new LambdaInvoke(scope, 'Maintainer Inactivity Lambda', { | ||
lambdaFunction: maintainerInactivityLambda, | ||
resultPath: JsonPath.DISCARD, | ||
timeout: Duration.minutes(15) | ||
}).addRetry(); | ||
} | ||
} |
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
78 changes: 78 additions & 0 deletions
78
infrastructure/test/maintainer-inactivity-workflow-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,78 @@ | ||
/** | ||
* 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 { Template } from "aws-cdk-lib/assertions"; | ||
import { OpenSearchMetricsWorkflowStack } from "../lib/stacks/metricsWorkflow"; | ||
import Project from "../lib/enums/project"; | ||
import { OpenSearchDomainStack } from "../lib/stacks/opensearch"; | ||
import { VpcStack } from "../lib/stacks/vpc"; | ||
import { ArnPrincipal } from "aws-cdk-lib/aws-iam"; | ||
import {OpenSearchS3} from "../lib/stacks/s3"; | ||
import {OpenSearchMaintainerInactivityWorkflowStack} from "../lib/stacks/maintainerInactivityWorkflow"; | ||
|
||
test('Maintainer Inactivity Workflow Stack Test', () => { | ||
const app = new App(); | ||
const vpcStack = new VpcStack(app, 'Test-OpenSearchHealth-VPC', {}); | ||
const s3Stack = new OpenSearchS3(app, "Test-OpenSearchMetrics-GitHubAutomationAppEvents-S3"); | ||
const openSearchDomainStack = new OpenSearchDomainStack(app, 'OpenSearchHealth-OpenSearch', { | ||
region: "us-east-1", | ||
account: "test-account", | ||
vpcStack: new VpcStack(app, 'OpenSearchHealth-VPC', {}), | ||
enableNginxCognito: true, | ||
jenkinsAccess: { | ||
jenkinsAccountRoles: [ | ||
new ArnPrincipal(Project.JENKINS_MASTER_ROLE), | ||
new ArnPrincipal(Project.JENKINS_AGENT_ROLE) | ||
] | ||
}, | ||
githubAutomationAppAccess: "sample-role-arn", | ||
githubEventsBucket: s3Stack.bucket, | ||
}); | ||
const openSearchMaintainerInactivityWorkflowStack = new OpenSearchMaintainerInactivityWorkflowStack(app, 'Test-OpenSearchMaintainerInactivity-Workflow', { | ||
opensearchDomainStack: openSearchDomainStack, | ||
vpcStack: vpcStack, | ||
lambdaPackage: Project.LAMBDA_PACKAGE, | ||
}); | ||
const template = Template.fromStack(openSearchMaintainerInactivityWorkflowStack); | ||
template.resourceCountIs('AWS::IAM::Role', 2); | ||
template.resourceCountIs('AWS::Lambda::Function', 1); | ||
template.hasResourceProperties('AWS::Lambda::Function', { | ||
"FunctionName": "OpenSearchMetricsMaintainerInactivityLambda", | ||
"Handler": "org.opensearchmetrics.lambda.MaintainerInactivityLambda" | ||
}); | ||
template.resourceCountIs('AWS::StepFunctions::StateMachine', 1); | ||
template.hasResourceProperties('AWS::StepFunctions::StateMachine', { | ||
"DefinitionString": { | ||
"Fn::Join": [ | ||
"", | ||
[ | ||
"{\"StartAt\":\"Maintainer Inactivity Lambda\",\"States\":{\"Maintainer Inactivity Lambda\":{\"End\":true,\"Retry\":[{\"ErrorEquals\":[\"Lambda.ClientExecutionTimeoutException\",\"Lambda.ServiceException\",\"Lambda.AWSLambdaException\",\"Lambda.SdkClientException\"],\"IntervalSeconds\":2,\"MaxAttempts\":6,\"BackoffRate\":2},{\"ErrorEquals\":[\"States.ALL\"]}],\"Type\":\"Task\",\"TimeoutSeconds\":900,\"ResultPath\":null,\"Resource\":\"arn:", | ||
{ | ||
"Ref": "AWS::Partition" | ||
}, | ||
":states:::lambda:invoke\",\"Parameters\":{\"FunctionName\":\"", | ||
{ | ||
"Fn::GetAtt": [ | ||
"OpenSearchMetricsMaintainerInactivityLambdaCB6D4475", | ||
"Arn" | ||
] | ||
}, | ||
"\",\"Payload.$\":\"$\"}}},\"TimeoutSeconds\":900}" | ||
] | ||
] | ||
}, | ||
"RoleArn": { | ||
"Fn::GetAtt": [ | ||
"OpenSearchMaintainerInactivityWorkflowRoleF9A5E625", | ||
"Arn" | ||
] | ||
}, | ||
"StateMachineName": "OpenSearchMaintainerInactivityWorkflow" | ||
}); | ||
}); |
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.