Skip to content

RFC: Log Alarm L2 Construct - #962

Open
rodrigotuna wants to merge 1 commit into
aws:mainfrom
rodrigotuna:logalarm-l2
Open

RFC: Log Alarm L2 Construct#962
rodrigotuna wants to merge 1 commit into
aws:mainfrom
rodrigotuna:logalarm-l2

Conversation

@rodrigotuna

Copy link
Copy Markdown

Tracking issue: #960

This RFC proposes a new LogAlarm L2 construct in aws-cdk-lib/aws-cloudwatch, wrapping the AWS::CloudWatch::LogAlarm CloudFormation resource. It follows the accepted PromQLAlarm precedent (extends AlarmBase, reuses existing enums, interchangeable via IAlarm).

A proof-of-concept construct with unit tests and an integration test has been implemented and deployed against a real account, confirming it creates a valid AWS::CloudWatch::LogAlarm.

See text/0960-logalarm-l2.md.

Comment thread text/0960-logalarm-l2.md
a scheduled Logs query (a query string + aggregation over one or more log groups) and compares the aggregated result
against a threshold using an M-out-of-N evaluation. It also can surface matching log lines in the alarm notification.
The construct wraps the `AWS::CloudWatch::LogAlarm` CloudFormation resource, reuses the existing
`ComparisonOperator`/`TreatMissingData` enums, and — like `Alarm` and `PromQLAlarm` — extends `AlarmBase` so it is

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please note that ComparisonOperator we use for log alarm doesn't support LessThanLowerOrGreaterThanUpperThreshold | LessThanLowerThreshold | GreaterThanUpperThreshold being supported under Metric Alarm. These operations are supported for anomaly detection metric alarm and it is not supported for log alarm.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can still use this enum and validate the parameter at synth. ( Probably, PromQL should also be doing the similar thing if they are reusing the enum ?)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see you already covered below:

comparisonOperator must be a static-threshold operator (anomaly-detection operators rejected).

Comment thread text/0960-logalarm-l2.md Outdated
## Summary

`LogAlarm` lets customers alarm directly on logs. Instead of a metric + threshold + evaluation periods, a log alarm runs
a scheduled Logs query (a query string + aggregation over one or more log groups) and compares the aggregated result

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Logs insight query

Comment thread text/0960-logalarm-l2.md Outdated
logGroupIdentifiers: [logGroup.logGroupName],
scheduledQueryRole: queryRole,
schedule: {
frequency: Duration.minutes(5),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Should we just name it as rate to align it with scheduled expression rate expression naming ?

Comment thread text/0960-logalarm-l2.md
import { Duration } from 'aws-cdk-lib';

declare const logGroup: logs.LogGroup;
declare const queryRole: iam.IRole;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we see if SQ ( as in GA) supports anything to help the role creation ? If so, customers can use that to simplify the role creationrather than having their own code to create one.

If there is one, we can also replicate the similar thing for log line role as well.

Comment thread text/0960-logalarm-l2.md
declare const logAlarm: cloudwatch.LogAlarm;
declare const topic: sns.Topic;

logAlarm.addAlarmAction(new cloudwatch_actions.SnsAction(topic));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's see if we can add validation on supported actions for log alarm as well on synth ?

Comment thread text/0960-logalarm-l2.md Outdated
### Are there any open issues that need to be addressed later?

- Alignment of `ScheduledQueryConfiguration` field constraints across the Coral model, CFN schema, and Hermes validation
(tracked in EVENTS-4979): `LogGroupIdentifiers` required→optional, `StartTimeOffset` range `[1, 2592000]`,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we just publish this with updated schema given we have already started the deployments? Or we plan to update it once we complete all deployments?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, curious if these validations will be done at L1 construct based on CFN schema being published ?

Comment thread text/0960-logalarm-l2.md
Comment thread text/0960-logalarm-l2.md
readonly treatMissingData?: TreatMissingData; // @default - service default
readonly actionLogLineCount?: number; // 0–50; requires role when > 0
readonly actionLogLineRole?: IRole;
readonly alarmActions?: IAlarmAction[];

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we have default values for these as well or we can mark default none ? We can follow what is being followed for metric alarm. Same goes for other optional parameters like actionLogLineRole

Comment thread text/0960-logalarm-l2.md
Comment thread text/0960-logalarm-l2.md Outdated
Comment thread text/0960-logalarm-l2.md
readonly actionsEnabled?: boolean; // @default true
readonly treatMissingData?: TreatMissingData; // @default - service default
readonly actionLogLineCount?: number; // 0–50
readonly actionLogLineRole?: IRole; // auto-created (trusts cloudwatch.amazonaws.com) when count > 0

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean auto created only when not passed ? Also, we plan to auto create it , would we have all required parameters in place to auto create it ? Let's also see what further reviewer has take on this.

Comment thread text/0960-logalarm-l2.md Outdated

### Why should we _not_ do this?

There is no strong reason not to. The `ScheduledQueryConfiguration` field constraints are final (`logGroupIdentifiers`

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have to mention this now given we are going with what will be the final spec?

The ScheduledQueryConfiguration field constraints are final (logGroupIdentifiers
is optional, and the startTimeOffset range is fixed), and the construct tracks the published
@aws-cdk/aws-service-spec

Comment thread text/0960-logalarm-l2.md Outdated

### Are there any open issues that need to be addressed later?

- None. The `ScheduledQueryConfiguration` field constraints are final; the L2 tracks the published

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, we may not have to mention this "The ScheduledQueryConfiguration field constraints are final; the L2 tracks the published @aws-cdk/aws-service-spec for the AWS::CloudWatch::LogAlarm schema." unless needed. It will confuse the reviewer further.

@chintan-vaghani2008

Copy link
Copy Markdown

Changes now looks good to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants