in src/backend/inventory/index.ts [48:109]
public constructor(scope: Construct, id: string, props: InventoryProps) {
super(scope, id);
this.rate = props.scheduleRate ?? Duration.minutes(15);
this.canary = new Canary(this, 'Resource', {
description: '[ConstructHub/Inventory] A canary that periodically inspects the list of indexed packages',
environment: {
AWS_EMF_ENVIRONMENT: 'Local',
BUCKET_NAME: props.bucket.bucketName,
},
logRetention: props.logRetention,
memorySize: 10_240,
timeout: this.rate,
});
const grantRead = props.bucket.grantRead(this.canary);
const grantWriteMissing = props.bucket.grantWrite(this.canary, MISSING_DOCUMENTATION_REPORT_PATTERN);
const grantWriteCorruptAssembly = props.bucket.grantWrite(this.canary, CORRUPT_ASSEMBLY_REPORT_PATTERN);
const grantWriteUnInstallable = props.bucket.grantWrite(this.canary, UNINSTALLABLE_PACKAGES_REPORT);
const rule = new Rule(this, 'ScheduleRule', {
schedule: Schedule.rate(this.rate),
targets: [new LambdaFunction(this.canary)],
});
rule.node.addDependency(grantRead, grantWriteMissing);
rule.node.addDependency(grantRead, grantWriteCorruptAssembly);
rule.node.addDependency(grantRead, grantWriteUnInstallable);
props.monitoring.addLowSeverityAlarm(
'Inventory Canary is not Running',
this.canary.metricInvocations({ period: this.rate }).createAlarm(this, 'Not Running', {
alarmName: `${this.node.path}/NotRunning`,
alarmDescription: [
'The inventory canary is not running!',
'',
`RunBook: ${RUNBOOK_URL}`,
'',
`Direct link to function: ${lambdaFunctionUrl(this.canary)}`,
].join('\n'),
comparisonOperator: ComparisonOperator.LESS_THAN_THRESHOLD,
evaluationPeriods: 1,
threshold: 1,
}),
);
props.monitoring.addLowSeverityAlarm(
'Inventory Canary is failing',
this.canary.metricErrors({ period: this.rate }).createAlarm(this, 'Failures', {
alarmName: `${this.node.path}/Failures`,
alarmDescription: [
'The inventory canary is failing!',
'',
`RunBook: ${RUNBOOK_URL}`,
'',
`Direct link to function: ${lambdaFunctionUrl(this.canary)}`,
].join('\n'),
comparisonOperator: ComparisonOperator.GREATER_THAN_OR_EQUAL_TO_THRESHOLD,
evaluationPeriods: 2,
threshold: 1,
}),
);
}