-
Notifications
You must be signed in to change notification settings - Fork 7
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
Added workflow to index events from s3 data lake to metrics cluster #89
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
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,83 @@ | ||
/** | ||
* 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, TaskInput} 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"; | ||
import {Bucket} from "aws-cdk-lib/aws-s3"; | ||
|
||
export interface OpenSearchS3EventIndexWorkflowStackProps extends StackProps { | ||
readonly region: string; | ||
readonly opensearchDomainStack: OpenSearchDomainStack; | ||
readonly vpcStack: VpcStack; | ||
readonly lambdaPackage: string; | ||
readonly githubEventsBucket: Bucket; | ||
} | ||
|
||
export interface WorkflowComponent { | ||
opensearchS3EventIndexWorkflowStateMachineName: string | ||
} | ||
export class OpenSearchS3EventIndexWorkflowStack extends Stack { | ||
public readonly workflowComponent: WorkflowComponent; | ||
constructor(scope: Construct, id: string, props: OpenSearchS3EventIndexWorkflowStackProps) { | ||
super(scope, id, props); | ||
|
||
const s3EventIndexTask = this.createS3EventIndexTask(this, | ||
props.region, | ||
props.opensearchDomainStack, | ||
props.vpcStack, | ||
props.lambdaPackage, | ||
props.githubEventsBucket); | ||
|
||
const opensearchS3EventIndexWorkflow = new StateMachine(this, 'OpenSearchS3EventIndexWorkflow', { | ||
definition: s3EventIndexTask, | ||
timeout: Duration.minutes(15), | ||
stateMachineName: 'OpenSearchS3EventIndexWorkflow' | ||
}) | ||
|
||
new Rule(this, 'OpenSearchS3EventIndexWorkflow-Every-Day', { | ||
schedule: Schedule.expression('cron(0 0 * * ? *)'), | ||
targets: [new SfnStateMachine(opensearchS3EventIndexWorkflow)], | ||
}); | ||
|
||
this.workflowComponent = { | ||
opensearchS3EventIndexWorkflowStateMachineName: opensearchS3EventIndexWorkflow.stateMachineName | ||
} | ||
} | ||
|
||
private createS3EventIndexTask(scope: Construct, region: string, opensearchDomainStack: OpenSearchDomainStack, vpcStack: VpcStack, lambdaPackage: string, githubEventsBucket: Bucket) { | ||
const openSearchDomain = opensearchDomainStack.domain; | ||
const s3EventIndexLambda = new OpenSearchLambda(this, "OpenSearchMetricsS3EventIndexLambdaFunction", { | ||
lambdaNameBase: "OpenSearchMetricsS3EventIndex", | ||
handler: "org.opensearchmetrics.lambda.GithubEventsLambda", | ||
lambdaZipPath: `../../../build/distributions/${lambdaPackage}`, | ||
vpc: vpcStack.vpc, | ||
securityGroup: vpcStack.securityGroup, | ||
role: opensearchDomainStack.openSearchS3EventsIndexLambdaRole, | ||
environment: { | ||
S3_BUCKET_REGION: region, | ||
EVENT_BUCKET_NAME: githubEventsBucket.bucketName, | ||
OPENSEARCH_DOMAIN_ENDPOINT: openSearchDomain.domainEndpoint, | ||
OPENSEARCH_DOMAIN_REGION: openSearchDomain.env.region, | ||
OPENSEARCH_DOMAIN_ROLE: opensearchDomainStack.fullAccessRole.roleArn, | ||
} | ||
}).lambda; | ||
return new LambdaInvoke(scope, 'S3 Event Index Lambda', { | ||
lambdaFunction: s3EventIndexLambda, | ||
resultPath: JsonPath.DISCARD, | ||
payload: TaskInput.fromJsonPathAt("$"), | ||
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
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.
Please seperate this into a seperate lambda and a seperate stepfunction so that it wont mix up with existing metrics and can have its own cron and full 15 mins to execute the operation.