Skip to content

Conversation

@ncocchiaro
Copy link
Contributor

@ncocchiaro ncocchiaro commented Nov 18, 2025

This PR adds an additional approach for the log lambda to find the information it needs either to output debug data via chatbot or to create a log query. If an incoming alarm has the relevant information in tags then the lambda won't need to rely on parsing the alarm names, offering an option for debug configuration that can be more robust and easier to expand on in the future.

In order to achieve this, the lambda needs to assume a role in the target account that allows listing tags on the alarm resources. This is set up here via new roles in bootstrap and a change to the lambda execution role, plus new lambda code.

The original name parsing logic remains and is still used in all cases in which alarms are not tagged (currently all cases except for prover-cluster alarms, which add tags in this PR as well).

@github-actions github-actions bot changed the title Update log lambda to query alarm tags BM-1950: Update log lambda to query alarm tags Nov 18, 2025
Copy link
Contributor Author

@ncocchiaro ncocchiaro left a comment

Choose a reason for hiding this comment

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

Some comments to help reviewers

return 'l-prod-11155111-bonsai-prover-11155111';
case 'monitor':
return 'l-prod-11155111-monitor-11155111-monitor';
return 'l-prod-11155111-monitor-11155111-mon-monitor';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was renamed in the wild, so needs to be renamed here

// Note we have to escape two backslashes in the query string. In
// CW it should look like: regexp_replace(log, '\\x1b\\[[0-9;]*[mK]', '') AS msg
return `
function proverQuery(logGroup: string): string {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same query as before, just refactored into a function

export class ManagerMetricAlarmComponent extends MetricAlarmComponent {

constructor(config: ManagerMetricAlarmConfig) {
constructor(config: MetricAlarmConfig) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This no longer needs a specific subclass since chainId is moving to the base MetricAlarmConfig interface

Comment on lines +115 to +118
ServiceName: config.serviceName,
LogGroupName: config.logGroupName,
StackName: config.stackName,
ChainId: config.chainId,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These new tags on the alarms allow the new lambda logic to work

@ncocchiaro ncocchiaro marked this pull request as ready for review November 20, 2025 01:54
@ncocchiaro ncocchiaro changed the title BM-1950: Update log lambda to query alarm tags BM-1950: Update log lambda to query alarm tags for debugging via chatbot Nov 20, 2025
Comment on lines 396 to 397
'arn:aws:iam::245178712747:role/alarmListTagsRole',
'arn:aws:iam::632745187633:role/alarmListTagsRole'
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: import the account numbers from accountConstants.ts

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, I missed that. Fixed in 3eb768f

Comment on lines +58 to +60
// Create a role that the log fetcher Lambda can assume to list tags on Cloudwatch alarms in the current account
const alarmTagsRole = new aws.iam.Role(`${prefix}alarmListTagsRole`, {
name: `${prefix}alarmListTagsRole`,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why don't we just grant the lambda execution role the permissions to read tags, rather than creating a new role and assuming it in the lambda?

Copy link
Contributor Author

@ncocchiaro ncocchiaro Nov 21, 2025

Choose a reason for hiding this comment

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

Does that work cross-account though? I had the same thought initially but from experience didn't think it would, I double checked in testing anyway but that confirmed that I couldn't get it to access the resources without assuming a role in the other accounts. Maybe you have a detailed suggestion?

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.

3 participants