mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(cloudformation): provision CloudWatch metric alarms (#1371)
Inject CloudWatchMetricsService and add provision + delete handling for AWS::CloudWatch::Alarm, mapping AlarmName, Namespace, MetricName, Statistic, Period, EvaluationPeriods, Threshold, ComparisonOperator, Dimensions, the action lists and TreatMissingData. Ref returns the alarm name; Fn::GetAtt Arn returns the alarm ARN. Docker-free integration test: CreateStack -> DescribeAlarms shows the alarm.
This commit is contained in:
1 parent
571d81afe3
commit
6004e57c29
4 files changed
+165
-3
No files matched your search
+88
@@ -0,0 +1,88 @@
|
||||
package io.github.hectorvent.floci.services.cloudformation;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
|
||||
/**
|
||||
* End-to-end check that CloudFormation provisions an AWS::CloudWatch::Alarm for real (into
|
||||
* CloudWatchMetricsService) rather than stubbing it. Alarms are metadata (no container), so the
|
||||
* test is Docker-free. CloudWatch is the Query API (form-encoded request, XML response).
|
||||
*/
|
||||
@QuarkusTest
|
||||
class CloudFormationCloudWatchAlarmIntegrationTest {
|
||||
|
||||
private static final String CFN_AUTH =
|
||||
"AWS4-HMAC-SHA256 Credential=test/20260205/us-east-1/cloudformation/aws4_request";
|
||||
private static final String CW_AUTH =
|
||||
"AWS4-HMAC-SHA256 Credential=test/20260205/us-east-1/monitoring/aws4_request";
|
||||
|
||||
@Test
|
||||
void createStackProvisionsAlarmVisibleToCloudWatch() {
|
||||
String suffix = Long.toString(System.nanoTime(), 36);
|
||||
String alarmName = "cfn-alarm-" + suffix;
|
||||
String stackName = "cfn-cw-alarm-stack-" + suffix;
|
||||
|
||||
String template = """
|
||||
{
|
||||
"Resources": {
|
||||
"Alarm": {
|
||||
"Type": "AWS::CloudWatch::Alarm",
|
||||
"Properties": {
|
||||
"AlarmName": "%s",
|
||||
"Namespace": "AWS/EC2",
|
||||
"MetricName": "CPUUtilization",
|
||||
"Statistic": "Average",
|
||||
"Period": 300,
|
||||
"EvaluationPeriods": 2,
|
||||
"Threshold": 80,
|
||||
"ComparisonOperator": "GreaterThanThreshold"
|
||||
}
|
||||
}
|
||||
},
|
||||
"Outputs": {
|
||||
"AlarmArn": {"Value": {"Fn::GetAtt": ["Alarm", "Arn"]}}
|
||||
}
|
||||
}
|
||||
""".formatted(alarmName);
|
||||
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.header("Authorization", CFN_AUTH)
|
||||
.formParam("Action", "CreateStack")
|
||||
.formParam("StackName", stackName)
|
||||
.formParam("TemplateBody", template)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
// Stack completes and Fn::GetAtt(Alarm, Arn) resolves to the real alarm ARN.
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.header("Authorization", CFN_AUTH)
|
||||
.formParam("Action", "DescribeStacks")
|
||||
.formParam("StackName", stackName)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<StackStatus>CREATE_COMPLETE</StackStatus>"))
|
||||
.body(containsString(":alarm:" + alarmName));
|
||||
|
||||
// The alarm really exists in CloudWatch.
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.header("Authorization", CW_AUTH)
|
||||
.formParam("Action", "DescribeAlarms")
|
||||
.formParam("AlarmNames.member.1", alarmName)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString(alarmName))
|
||||
.body(containsString("CPUUtilization"));
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -48,7 +48,7 @@ class CustomResourceProvisionerTest {
|
||||
|
||||
provisioner = new CloudFormationResourceProvisioner(
|
||||
null, null, null, null, lambdaService, null, null, null, null, null,
|
||||
null, null, null, null, null, null, mapper, store, endpoint, null, null, null, null, null, null, null, null, null);
|
||||
null, null, null, null, null, null, mapper, store, endpoint, null, null, null, null, null, null, null, null, null, null);
|
||||
}
|
||||
|
||||
private CloudFormationTemplateEngine engine() {
|
||||
|
||||
+1
-1
@@ -44,7 +44,7 @@ class RdsCfnProvisionerTest {
|
||||
null, null, null, null, null, null,
|
||||
mapper,
|
||||
null, null, null, null, null, null, null,
|
||||
rdsService, null, null, null);
|
||||
rdsService, null, null, null, null);
|
||||
}
|
||||
|
||||
private CloudFormationTemplateEngine engine() {
|
||||
|
||||
Reference in new issue
Block a user