Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
constructor(scope: Construct, id: string, props: WatchApiGatewayProps) {
super(scope, id);
this.api = props.restApi.node.findChild('Resource') as apigw.CfnRestApi;
this.stage = props.restApi.deploymentStage.stageName;
this.watchful = props.watchful;
const alarmThreshold = props.serverErrorThreshold == null ? 1 : props.serverErrorThreshold;
if (alarmThreshold) {
this.watchful.addAlarm(
this.createApiGatewayMetric(ApiGatewayMetric.FiveHundredError)
.createAlarm(this, '5XXErrorAlarm', {
alarmDescription: `at ${alarmThreshold}`,
threshold: alarmThreshold,
period: Duration.minutes(5),
comparisonOperator: ComparisonOperator.GREATER_THAN_OR_EQUAL_TO_THRESHOLD,
evaluationPeriods: 1,
statistic: 'sum',
})
);
}
this.watchful.addSection(props.title, {
links: [{ title: 'Amazon API Gateway Console', url: linkForApiGateway(props.restApi) }]
});
[undefined, ...props.watchedOperations || []].forEach(operation =>
this.watchful.addWidgets(
this.createCallGraphWidget(operation, alarmThreshold),
...props.cacheGraph ? [this.createCacheGraphWidget(operation)] : [],
this.createLatencyGraphWidget(ApiGatewayMetric.Latency, operation),
this.createLatencyGraphWidget(ApiGatewayMetric.IntegrationLatency, operation),
)