feat(servicequotas): configure applied EC2 vCPU quota (#5926)

* feat(servicequotas): configure applied EC2 vCPU quota

Report configured EC2 vCPU quotas separately from AWS defaults.

* fix(servicequotas): reject negative applied quota settings

Reject invalid quota settings before serving local requests.

* docs(servicequotas): clarify negative quota settings

* fix(servicequotas): reject invalid settings at startup
This commit is contained in:
David Phillips authored and GitHub committed 2026-10-18 11:03:06 -04:00
1 parent 8298779ead
commit 1a80884f40
11 files changed
+288 -32

No files matched your search

@@ -1094,6 +1094,9 @@ public interface EmulatorConfig {
interface ServiceQuotasServiceConfig {
@WithDefault("true")
boolean enabled();
@WithDefault("5")
int standardOnDemandVcpus();
}
interface VerifiedPermissionsServiceConfig {
@@ -0,0 +1,28 @@
package io.github.hectorvent.floci.config;
import io.quarkus.runtime.StartupEvent;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.event.Observes;
import jakarta.inject.Inject;
@ApplicationScoped
public class ServiceQuotasStartupValidator {
private final EmulatorConfig config;
@Inject
public ServiceQuotasStartupValidator(EmulatorConfig config) {
this.config = config;
}
void onStart(@Observes StartupEvent ignored) {
validateStandardOnDemandVcpus(config.services().servicequotas().standardOnDemandVcpus());
}
public static void validateStandardOnDemandVcpus(int value) {
if (value < 0) {
throw new IllegalArgumentException(
"floci.services.servicequotas.standard-on-demand-vcpus must be nonnegative");
}
}
}
@@ -28,10 +28,10 @@ public class ServiceQuotasJsonHandler {
public Response handle(String action, JsonNode request, String region, String accountId) {
LOG.debugv("ServiceQuotas action: {0}", action);
return switch (action) {
case "ListServiceQuotas" -> handleListServiceQuotas(request, region, accountId);
case "GetServiceQuota" -> handleGetServiceQuota(request, region, accountId);
case "GetAWSDefaultServiceQuota" -> handleGetServiceQuota(request, region, accountId);
case "ListAWSDefaultServiceQuotas" -> handleListServiceQuotas(request, region, accountId);
case "ListServiceQuotas" -> handleListServiceQuotas(request, region, accountId, false);
case "GetServiceQuota" -> handleGetServiceQuota(request, region, accountId, false);
case "GetAWSDefaultServiceQuota" -> handleGetServiceQuota(request, region, accountId, true);
case "ListAWSDefaultServiceQuotas" -> handleListServiceQuotas(request, region, accountId, true);
case "RequestServiceQuotaIncrease" -> handleRequestServiceQuotaIncrease(request, region, accountId);
case "GetRequestedServiceQuotaChange" ->
Response.ok(service.getRequestedServiceQuotaChange(
@@ -48,20 +48,22 @@ public class ServiceQuotasJsonHandler {
};
}
private Response handleListServiceQuotas(JsonNode request, String region, String accountId) {
return Response.ok(service.listServiceQuotas(
stringOrNull(request, "ServiceCode"),
stringOrNull(request, "QuotaCode"),
stringOrNull(request, "NextToken"),
integerOrNull(request, "MaxResults"),
region, accountId)).build();
private Response handleListServiceQuotas(JsonNode request, String region, String accountId, boolean awsDefault) {
String serviceCode = stringOrNull(request, "ServiceCode");
String quotaCode = stringOrNull(request, "QuotaCode");
String nextToken = stringOrNull(request, "NextToken");
Integer maxResults = integerOrNull(request, "MaxResults");
return Response.ok(awsDefault
? service.listAwsDefaultServiceQuotas(serviceCode, quotaCode, nextToken, maxResults, region, accountId)
: service.listServiceQuotas(serviceCode, quotaCode, nextToken, maxResults, region, accountId)).build();
}
private Response handleGetServiceQuota(JsonNode request, String region, String accountId) {
return Response.ok(service.getServiceQuota(
stringOrNull(request, "ServiceCode"),
stringOrNull(request, "QuotaCode"),
region, accountId)).build();
private Response handleGetServiceQuota(JsonNode request, String region, String accountId, boolean awsDefault) {
String serviceCode = stringOrNull(request, "ServiceCode");
String quotaCode = stringOrNull(request, "QuotaCode");
return Response.ok(awsDefault
? service.getAwsDefaultServiceQuota(serviceCode, quotaCode, region, accountId)
: service.getServiceQuota(serviceCode, quotaCode, region, accountId)).build();
}
private static String stringOrNull(JsonNode node, String field) {
@@ -4,6 +4,8 @@ import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.config.ServiceQuotasStartupValidator;
import io.github.hectorvent.floci.core.common.AwsArnUtils;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.Base64Url;
@@ -31,7 +33,8 @@ import java.util.zip.CRC32;
* executions"), plus a deterministic generic set for any other service code.
* Unmodeled values are deliberately generous so local pipelines that gate on
* quota headroom never stall on a limit the emulator does not enforce.
* Applied and default quotas return the same data.
* Applied EC2 Standard On-Demand vCPU values use local configuration; AWS defaults
* retain the catalog value.
*
* @see <a href="https://docs.aws.amazon.com/servicequotas/2019-06-24/apireference/Welcome.html">Service Quotas API</a>
*/
@@ -81,12 +84,15 @@ public class ServiceQuotasService {
"Concurrent operations");
private final ObjectMapper objectMapper;
private final int standardOnDemandVcpus;
private final StorageBackend<String, ObjectNode> requestedQuotaStore;
private final Object openRequestLock = new Object();
@Inject
public ServiceQuotasService(StorageFactory storageFactory, ObjectMapper objectMapper) {
public ServiceQuotasService(StorageFactory storageFactory, ObjectMapper objectMapper, EmulatorConfig config) {
this.objectMapper = objectMapper;
this.standardOnDemandVcpus = config.services().servicequotas().standardOnDemandVcpus();
ServiceQuotasStartupValidator.validateStandardOnDemandVcpus(standardOnDemandVcpus);
this.requestedQuotaStore = storageFactory.create("servicequotas",
"servicequotas-requested-changes.json",
new TypeReference<Map<String, ObjectNode>>() {});
@@ -94,6 +100,16 @@ public class ServiceQuotasService {
public ObjectNode listServiceQuotas(String serviceCode, String quotaCodeFilter, String nextToken,
Integer maxResults, String region, String accountId) {
return listQuotas(serviceCode, quotaCodeFilter, nextToken, maxResults, region, accountId, true);
}
public ObjectNode listAwsDefaultServiceQuotas(String serviceCode, String quotaCodeFilter, String nextToken,
Integer maxResults, String region, String accountId) {
return listQuotas(serviceCode, quotaCodeFilter, nextToken, maxResults, region, accountId, false);
}
private ObjectNode listQuotas(String serviceCode, String quotaCodeFilter, String nextToken,
Integer maxResults, String region, String accountId, boolean applied) {
requireServiceCode(serviceCode);
List<QuotaDefinition> quotas = quotasFor(serviceCode);
if (quotaCodeFilter != null && !quotaCodeFilter.isEmpty()) {
@@ -104,7 +120,7 @@ public class ServiceQuotasService {
ObjectNode response = objectMapper.createObjectNode();
ArrayNode array = response.putArray("Quotas");
for (QuotaDefinition quota : page.items()) {
array.add(quotaNode(serviceCode, quota, region, accountId));
array.add(quotaNode(serviceCode, quota, region, accountId, applied));
}
if (page.nextToken() != null) {
response.put("NextToken", page.nextToken());
@@ -113,6 +129,14 @@ public class ServiceQuotasService {
}
public ObjectNode getServiceQuota(String serviceCode, String quotaCode, String region, String accountId) {
return getQuota(serviceCode, quotaCode, region, accountId, true);
}
public ObjectNode getAwsDefaultServiceQuota(String serviceCode, String quotaCode, String region, String accountId) {
return getQuota(serviceCode, quotaCode, region, accountId, false);
}
private ObjectNode getQuota(String serviceCode, String quotaCode, String region, String accountId, boolean applied) {
requireServiceCode(serviceCode);
if (quotaCode == null || quotaCode.isEmpty()) {
throw new AwsException("IllegalArgumentException",
@@ -124,7 +148,7 @@ public class ServiceQuotasService {
.orElseThrow(() -> new AwsException("NoSuchResourceException",
"The request failed because the specified service quota does not exist.", 400));
ObjectNode response = objectMapper.createObjectNode();
response.set("Quota", quotaNode(serviceCode, quota, region, accountId));
response.set("Quota", quotaNode(serviceCode, quota, region, accountId, applied));
return response;
}
@@ -148,7 +172,8 @@ public class ServiceQuotasService {
return "L-%08X".formatted(crc.getValue());
}
private ObjectNode quotaNode(String serviceCode, QuotaDefinition quota, String region, String accountId) {
private ObjectNode quotaNode(String serviceCode, QuotaDefinition quota, String region, String accountId,
boolean applied) {
ObjectNode node = objectMapper.createObjectNode();
node.put("ServiceCode", serviceCode);
node.put("ServiceName", SERVICE_NAMES.getOrDefault(serviceCode, serviceCode));
@@ -156,7 +181,9 @@ public class ServiceQuotasService {
serviceCode + "/" + quota.quotaCode()).toString());
node.put("QuotaCode", quota.quotaCode());
node.put("QuotaName", quota.quotaName());
node.put("Value", quota.value());
double value = applied && "ec2".equals(serviceCode) && "L-1216C47A".equals(quota.quotaCode())
? standardOnDemandVcpus : quota.value();
node.put("Value", value);
node.put("Unit", "None");
node.put("Adjustable", true);
node.put("GlobalQuota", quota.globalQuota());