Skip to content

Conversation

@Vlasis-Perdikidis
Copy link
Contributor

Description

Context

Type of changes

  • Refactoring (non-breaking change)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would change existing functionality)
  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • I am familiar with the contributing guidelines
  • I have followed the code style of the project
  • I have added tests to cover my changes
  • I have updated the documentation accordingly
  • This PR is a result of pair or mob programming
  • If I have used the 'skip-trivy-package' label I have done so responsibly and in the knowledge that this is being fixed as part of a separate ticket/PR.

Sensitive Information Declaration

To ensure the utmost confidentiality and protect your and others privacy, we kindly ask you to NOT including PII (Personal Identifiable Information) / PID (Personal Identifiable Data) or any other sensitive data in this PR (Pull Request) and the codebase changes. We will remove any PR that do contain any sensitive information. We really appreciate your cooperation in this matter.

  • I confirm that neither PII/PID nor sensitive data are included in this PR and the codebase changes.

@Vlasis-Perdikidis Vlasis-Perdikidis requested a review from a team as a code owner January 20, 2026 12:59
@Vlasis-Perdikidis Vlasis-Perdikidis changed the title change to create a PR Expose key metrics to cloudwatch Jan 20, 2026
@Vlasis-Perdikidis Vlasis-Perdikidis requested review from a team as code owners January 21, 2026 15:27
Copy link
Contributor

@stevebux stevebux left a comment

Choose a reason for hiding this comment

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

Looks good, just a few queries

/**
* emits metrics of successful letter updates, including the supplier and grouped by status
*/
async function emitMetics(
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this function need to be async?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think so. Because I call it at the end, just before the lambda handler return.
So I'm not sure if the lambda completes, it emitMetrics() will also exit, or complete.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, I think if you declare it to be async, then yes, you need to await it to avoid the scenario you mention, where the lambda exits before the metrics have been emitted. But if it's just a straight synchronous function, I believe that would be the same as just writing the same code in-line in the main lambda function - it won't exit until the metrics have been written

(statusesMapping.get(letterCommand.status) || 0) + 1,
);
}
return letterCommand;
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be better for post-letters to build the statusMapping as a separate step, rather than complicating the mapToUpdateCommands function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I also don't feel good about adding extra logic to this function.
I was between populating the map in this function or letter-operations.enqueueLetterUpdateRequests(), because these functions already loop through the letter requests and I could populate the map at the same time.

I could iterate the requests and populate my map in post-letters directly, but that would slow down processing, and I was told by Mark that we already have performance issues.

I have kept the map as an optional parameter, but if we decide as a team I could always remove the logic from here and add it to post-letters

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd be surprised if populating the map separately turned out to have a significant impact on performance - ultimately it's just manipulating a small in-memory array

PublishBatchRequestEntries: batch.map((element, index) => {
eventTypeCount.set(
element.type,
(eventTypeCount.get(element.type) || 0) + 1,
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering if it would be clearer to move the calculation of eventTypeCount outside of the batch loop - it might be simpler to calculate it in one go rather than a batch at a time

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could add it a bit further up in the mapLetterToCloudEvent() function, but again I'm complicating the single-responsibility of the function.

I could also separately loop over the events one by one, but that would slow down the lambda.

Copy link
Contributor

Choose a reason for hiding this comment

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

I wouldn't assume that doing it in a separate loop would slow down the lambda - if you're concerned, you could try both options and see if it makes a difference to the lambda timings

import mapLetterToCloudEvent from "./mappers/letter-mapper";
import { Deps } from "./deps";
import { LetterForEventPub, LetterSchemaForEventPub } from "./types";
import { string } from "zod";
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this need to be the zod string, or could it be the built-in type?

const eventTypeCount = new Map<string, number>();
const eventTypeCount: Map<string, number> =
populateEventTypeMap(cloudEvents);
// const eventTypeCount = new Map<string, number>();
Copy link
Contributor

Choose a reason for hiding this comment

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

This commented out line can probably be removed

stevebux
stevebux previously approved these changes Feb 3, 2026
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