Skip to content

Commit

Permalink
Add error metric filters for amis, tep, and tpk log groups
Browse files Browse the repository at this point in the history
  • Loading branch information
severij committed Jul 29, 2024
1 parent 06730de commit 56b472a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
3 changes: 2 additions & 1 deletion cdk/lib/amis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ export class HeratepalveluAMISStack extends HeratepalveluStack {
logGroupName: `${envName}-heratepalvelu-amis`,
retention: RetentionDays.TWO_YEARS,
});

this.createErrorMetricFilter('amis', amisLogGroup);

const AMISHerateHandler = new lambda.Function(this, "AMISHerateHandler", {
runtime: this.runtime,
Expand Down Expand Up @@ -743,7 +745,6 @@ export class HeratepalveluAMISStack extends HeratepalveluStack {
resources: [`arn:aws:ssm:eu-west-1:*:parameter/${envName}/services/heratepalvelu/*`],
actions: ['ssm:GetParameter']
}));
this.createMetricFilters(lambdaFunction);
}
);
}
Expand Down
10 changes: 4 additions & 6 deletions cdk/lib/heratepalvelu.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Stack, App, StackProps, Tags } from 'aws-cdk-lib';
import lambda = require("aws-cdk-lib/aws-lambda");
import { FilterPattern, MetricFilter } from 'aws-cdk-lib/aws-logs';
import { FilterPattern, LogGroup, MetricFilter } from 'aws-cdk-lib/aws-logs';
import ssm = require("aws-cdk-lib/aws-ssm");

export type EnvVars = {
Expand Down Expand Up @@ -59,14 +59,12 @@ export class HeratepalveluStack extends Stack {
this.runtime = lambda.Runtime.JAVA_11;
}

createMetricFilters = (lambdaFunction: lambda.Function) => {
createErrorMetricFilter = (stack: string, logGroup: LogGroup) => {
const metricNamespace = 'OpintopolkuLogMetrics';
const logGroup = lambdaFunction.logGroup;
const functionName = lambdaFunction.node.id;
new MetricFilter(this, `${functionName}LogErrors`, {
new MetricFilter(this, `${stack}LogErrors`, {
logGroup,
metricNamespace: metricNamespace,
metricName: `${this.envName}/heratepalvelu/${functionName}/errors`,
metricName: `${this.envName}/heratepalvelu/${stack}/errors`,
filterPattern: FilterPattern.literal('ERROR'),
metricValue: "1"
});
Expand Down
5 changes: 4 additions & 1 deletion cdk/lib/tep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,10 @@ export class HeratepalveluTEPStack extends HeratepalveluStack {
retention: RetentionDays.TWO_YEARS,
});

// MetricFilter

this.createErrorMetricFilter('tep', tepLogGroup);

// VPC

const vpc = ec2.Vpc.fromVpcAttributes(this, "VPC", {
Expand Down Expand Up @@ -673,7 +677,6 @@ export class HeratepalveluTEPStack extends HeratepalveluStack {
resources: [`arn:aws:ssm:eu-west-1:*:parameter/${envName}/services/heratepalvelu/*`],
actions: ['ssm:GetParameter']
}));
this.createMetricFilters(lambdaFunction);
}
);
}
Expand Down
5 changes: 4 additions & 1 deletion cdk/lib/tpk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ export class HeratepalveluTPKStack extends HeratepalveluStack {
retention: RetentionDays.TWO_YEARS,
});

// MetricFilter

this.createErrorMetricFilter('tpk', tpkLogGroup);

// VPC

const vpc = ec2.Vpc.fromVpcAttributes(this, "VPC", {
Expand Down Expand Up @@ -230,7 +234,6 @@ export class HeratepalveluTPKStack extends HeratepalveluStack {
resources: [`arn:aws:ssm:eu-west-1:*:parameter/${envName}/services/heratepalvelu/*`],
actions: ["ssm:GetParameter"],
}));
this.createMetricFilters(lambdaFunction);
}
);
}
Expand Down

0 comments on commit 56b472a

Please sign in to comment.