-
Notifications
You must be signed in to change notification settings - Fork 1
/
query-definitions.ts
50 lines (44 loc) · 1.78 KB
/
query-definitions.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { CfnQueryDefinition } from 'aws-cdk-lib/aws-logs';
import { Construct } from 'constructs';
export interface LogQueryDefinitionsProps {
readonly applicationLogGroupName?: string,
readonly serviceLogGroupName?: string,
readonly customQueryDefinitions?: CfnQueryDefinition[],
}
export class LogQueryDefinitions {
readonly queryDefinitions: CfnQueryDefinition[]
constructor(scope: Construct, id: string, props: LogQueryDefinitionsProps) {
this.queryDefinitions = [];
if (props.applicationLogGroupName) {
this.queryDefinitions.push(
new CfnQueryDefinition(scope, `${id}AppLogErrors`, {
name: 'ApplicationLog.Errors',
queryString: `
fields @timestamp, @message, @logStream
| parse @message "[*] *" as loggingType, loggingMessage
| filter loggingType = "ERROR"
| sort @timestamp desc
| limit 100
| display @logStream, loggingMessage`,
logGroupNames: [props.applicationLogGroupName],
}),
);
}
if (props.serviceLogGroupName) {
this.queryDefinitions.push(
new CfnQueryDefinition(scope, `${id}SerLogFaults`, {
name: 'ServiceLog.Faults',
queryString: `
fields @timestamp, @message
| filter Fault = 1
| sort @timestamp desc
| limit 100`,
logGroupNames: [props.serviceLogGroupName],
}),
);
}
if (props.customQueryDefinitions) {
this.queryDefinitions.push(...props.customQueryDefinitions);
}
}
}