Skip to content
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

feat(logs): Log anomaly detection #28243

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { App, RemovalPolicy, Stack, StackProps } from 'aws-cdk-lib';
import { IntegTest } from '@aws-cdk/integ-tests-alpha';
import { LogAnomalyDetector, LogGroup, EvaluationFrequency } from 'aws-cdk-lib/aws-logs';
// import { LogGroup, EvaluationFrequency } from 'aws-cdk-lib/aws-logs';

class TestStack extends Stack {
constructor(scope: App, id: string, props?: StackProps) {
super(scope, id, props);

const logGroup = new LogGroup(this, 'LogGroup', {
removalPolicy: RemovalPolicy.DESTROY,
});

new LogAnomalyDetector(this, 'MyAnomalyDetector', {
detectorName: 'MyDetector',
evaluationFrequency: EvaluationFrequency.FIVE_MIN,
filterPattern: 'ERROR',
logGroupArnList: [logGroup.logGroupArn],
});

// const logGroup2 = new LogGroup(this, 'LogGroup2', {
// removalPolicy: RemovalPolicy.DESTROY,
// });

// logGroup2.addAnomalyDetector('MyAnomalyDetector2', {
// detectorName: 'MyDetector',
// evaluationFrequency: EvaluationFrequency.TEN_MIN,
// filterPattern: 'WARN',
// });

}
}

const app = new App();
const testCase = new TestStack(app, 'aws-cdk-anomaly-detector-integ');

new IntegTest(app, 'anomaly-detector', {
testCases: [testCase],
});
app.synth();

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"Resources": {
"LogGroupF5B46931": {
"Type": "AWS::Logs::LogGroup",
"Properties": {
"RetentionInDays": 731
},
"UpdateReplacePolicy": "Delete",
"DeletionPolicy": "Delete"
},
"MetricFilter1B93B6E5": {
"Type": "AWS::Logs::MetricFilter",
"Properties": {
"FilterPattern": "{ $.latency = \"*\" }",
"LogGroupName": {
"Ref": "LogGroupF5B46931"
},
"MetricTransformations": [
{
"Dimensions": [
{
"Key": "ErrorCode",
"Value": "$.errorCode"
}
],
"MetricName": "Latency",
"MetricNamespace": "MyApp",
"MetricValue": "$.latency"
}
]
}
}
},
"Parameters": {
"BootstrapVersion": {
"Type": "AWS::SSM::Parameter::Value<String>",
"Default": "/cdk-bootstrap/hnb659fds/version",
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
}
},
"Rules": {
"CheckBootstrapVersion": {
"Assertions": [
{
"Assert": {
"Fn::Not": [
{
"Fn::Contains": [
[
"1",
"2",
"3",
"4",
"5"
],
{
"Ref": "BootstrapVersion"
}
]
}
]
},
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
}
]
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading