-
Notifications
You must be signed in to change notification settings - Fork 6
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
Reindex GitHub Events into maintainer inactivity data #79
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,79 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* 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
79 changes: 79 additions & 0 deletions
79
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,79 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: moving forward should this
infrastructure/lib/stacks/monitoringDashboard.ts
have inputs on the workflows to monitor?