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

Add lambda invocation failure alarm #244

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

krissrex
Copy link
Contributor

@krissrex krissrex commented May 10, 2024

Ports lambda-alarms from Team DTP.

@krissrex krissrex requested a review from a team as a code owner May 10, 2024 15:13
Comment on lines +48 to +49
}).createAlarm(this, "FailedInvocationAlarm", {
alarmDescription: `Invocation for '${this.lambdaFunctionName}' failed. ${props?.appendToAlarmDescription ?? ""}`,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fjernet eksplisitt alarmName her. For å unngå collisions hvis man lager flere av samme construct or alarm.

Copy link
Contributor

Choose a reason for hiding this comment

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

Bra!


export interface LambdaAlarmsProps {
actions: cloudwatch.IAlarmAction[]
lambdaFunctionName: 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.

Endret til å ta inn bare en lambda name som string i stedet for lambda.Function. Unngår imports her og lettere å skrive test-kode.

Copy link
Contributor

Choose a reason for hiding this comment

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

Har lurt litt på denne, og tror vi bør holde det til å sende inn selve funksjonen.

  • Dersom vi senere introduserer andre alarmer/metrikker som ser på andre attributter i en lambda vil vi være nødt til å dytte ut en breaking change til alle konsumenter hvor vi endrer signaturen fra string (funksjonsnavn) til objekt (funksjon)
  • Vi mister den eksplisitte CloudFormation-avhengigheten mellom metrikken og lambdaen. Det er ikke et problem i akkurat dette tilfellet, siden metrikken kan opprettes uavhengig, men det hadde vært kjekt å ha avhengigheten definert uansett

Så er ikke krise, men tror vi bør gjøre det for å ruste oss mot endringer

import * as cloudwatch from "aws-cdk-lib/aws-cloudwatch"

export interface LambdaAlarmsProps {
actions: cloudwatch.IAlarmAction[]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Den er en array, for i DTP har vi sendt samme alarm til fler actions, både Slack og OpsGenie.
Kan alternativt vært en enkelt IAlarmAction og så instansiert LambdaAlarms to ganger og lagd 2 Alarms i DTP, spesielt nå som jeg fjernet eksplisitt alarmName.

Copy link
Contributor

Choose a reason for hiding this comment

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

Tror det er enklest å holde det til en IAlarmAction for enkelhetens skyld, spesielt nå som det å opprette flere ikke er et problem etter fjerning av alarmName

Copy link
Contributor

@joakimen joakimen left a comment

Choose a reason for hiding this comment

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

Bra tilskudd! Noen tilpasninger og forenklinger, så er det good :)

import * as cloudwatch from "aws-cdk-lib/aws-cloudwatch"

export interface LambdaAlarmsProps {
actions: cloudwatch.IAlarmAction[]
Copy link
Contributor

Choose a reason for hiding this comment

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

Tror det er enklest å holde det til en IAlarmAction for enkelhetens skyld, spesielt nå som det å opprette flere ikke er et problem etter fjerning av alarmName


export interface LambdaAlarmsProps {
actions: cloudwatch.IAlarmAction[]
lambdaFunctionName: string
Copy link
Contributor

Choose a reason for hiding this comment

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

Har lurt litt på denne, og tror vi bør holde det til å sende inn selve funksjonen.

  • Dersom vi senere introduserer andre alarmer/metrikker som ser på andre attributter i en lambda vil vi være nødt til å dytte ut en breaking change til alle konsumenter hvor vi endrer signaturen fra string (funksjonsnavn) til objekt (funksjon)
  • Vi mister den eksplisitte CloudFormation-avhengigheten mellom metrikken og lambdaen. Det er ikke et problem i akkurat dette tilfellet, siden metrikken kan opprettes uavhengig, men det hadde vært kjekt å ha avhengigheten definert uansett

Så er ikke krise, men tror vi bør gjøre det for å ruste oss mot endringer

Comment on lines +48 to +49
}).createAlarm(this, "FailedInvocationAlarm", {
alarmDescription: `Invocation for '${this.lambdaFunctionName}' failed. ${props?.appendToAlarmDescription ?? ""}`,
Copy link
Contributor

Choose a reason for hiding this comment

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

Bra!

metricName: "Errors",
namespace: "AWS/Lambda",
statistic: "Sum",
period: cdk.Duration.seconds(60), // Standard resolution metric has a minimum of 60s period
Copy link
Contributor

Choose a reason for hiding this comment

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

Kan fjerne kommentaren

lambdaFunctionName: string
}

export class LambdaAlarms extends constructs.Construct {
Copy link
Contributor

Choose a reason for hiding this comment

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

Kan ha en docstring som oppsummerer klassens ansvar, gjerne med notis tilsvarende service-alarms om at ingen alarmer opprettes før man kaller de forskjellige metodene

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