Loading…
Loading…
Calculates deployment capacity from cloud provider data and configuration, and compares it to discovered demand from traffic logs to estimate system load.
The Capacity Estimation Service provides a dynamic assessment of the platform's data plane capacity versus its observed traffic demand. This service powers the "deployment capacity vs. discovered demand" panel on the administrative dashboard, offering an at-a-glance verdict on whether the current deployment is sufficiently provisioned.
The service synthesizes two key perspectives:
CapacityProvider, which can either discover resources and quotas live from the cloud environment or fall back to statically configured values.The service's final output is a CapacityEstimateResponse object, which includes detailed breakdowns of both capacity and demand, along with a simple verdict: OK, OVER_CAPACITY, or UNKNOWN. This allows operators to quickly identify potential capacity shortfalls.
IMPORTANT
This service is designed to be fail-soft. If an error occurs while querying a specific demand metric from the database, that metric will be reported as null with an accompanying warning, but the overall estimation process will complete rather than failing the entire request.
The capacity estimation process runs when the estimate() method is called. It calculates the capacity and demand sides concurrently before comparing them to produce a verdict.
flowchart TD
subgraph "Capacity Calculation"
A[CapacityProvider] -->|Live data| B(Merge with Fallbacks)
C[S2R_CAPACITY_* config] -->|Fallback values| B
B --> D(CapacityMath.compute)
D --> E[CapacitySide Response]
end
subgraph "Demand Calculation"
F[DB: s2r_traffic_concurrency_hourly] -->|Measured peak| G{Read Demand Metrics}
H[DB: s2r_agg_service_hourly] -->|Estimated peak, calls/day| G
I[DB: s2r_master_discovery] -->|Service count| G
G --> J[DemandSide Response]
end
K(estimate() call) --> A
K --> G
E --> L{Combine and Determine Verdict}
J --> L
L --> M[CapacityEstimateResponse]The capacity side of the estimate is determined through the following steps:
CapacityProvider. If a cloud-specific implementation (e.g., for GCP) is available in the system, it is used. Otherwise, it defaults to a StaticCapacityProvider which relies solely on operator-configured environment variables.describeDataPlaneCapacity() method is called to get a DeploymentCapacity object containing details like instance counts, quotas, and network IP availability.S2R_CAPACITY_*). This makes the estimate more robust. If the live provider fails to determine a specific value (e.g., due to missing IAM permissions), the corresponding static configuration value is used as a fallback. A warning is added to the response indicating which values were supplied from configuration. A successful live read always takes precedence over a configured fallback.DeploymentCapacity is passed to the CapacityMath.compute() function. This function analyzes the various inputs to calculate the maxSimultaneousCalls the deployment can support and identifies the specific limitingFactor (e.g., CPU, IP addresses, regional quota).The demand side is derived from historical traffic data stored in aggregated database tables.
callsPerDay: Calculated by summing the success_hits and failure_hits from the s2r_agg_service_hourly table over the last 24 hours.discoveredServiceCount: Calculated by counting rows in s2r_master_discovery that have had traffic in the last 24 hours (hits_24h > 0). This aligns with the service count shown on the Master Discovery screen.peakParallelCalls: This metric is determined using a two-tiered approach to find the highest number of concurrent calls within the configured demand-window-days:
s2r_traffic_concurrency_hourly table. This table contains pre-calculated, sub-hour peak concurrency values. If a valid peak is found, it is used, and the resolution field in the response is set to "measured".s2r_agg_service_hourly table and calculates concurrency as (callsThisHour / 3600.0) * avgBackendLatencySeconds. The highest calculated value across all hours becomes the peakParallelCalls, and the resolution is set to "hourly-estimate". If latency data is not available for an hour, a default assumed-call-ms value is used.The final verdict is determined by comparing the capacity and demand estimates:
UNKNOWN: If maxSimultaneousCalls could not be calculated due to missing capacity inputs.OVER_CAPACITY: If peakParallelCalls is known and exceeds maxSimultaneousCalls.OK: In all other cases.The CapacityEstimateService exposes an estimate() method that returns a CapacityEstimateResponse object. The source does not specify the exact HTTP endpoint that exposes this service method.
The following is an example of the JSON response payload. This example shows an OVER_CAPACITY verdict where the discovered peak demand of 1250 concurrent calls exceeds the system's calculated capacity of 1000. It also includes a warning that the max-instances value was sourced from a configuration fallback.
{
"capacity": {
"provider": "GcpCapacityProvider",
"region": "us-east1",
"service": "s2r-runtime",
"effectiveMaxInstances": 50,
"concurrencyPerInstance": 20,
"maxSimultaneousCalls": 1000,
"limitingFactor": "Per-instance concurrency",
"factorCeilings": {
"CONFIGURED_MAX_INSTANCES": 50,
"REGIONAL_INSTANCE_QUOTA": 200,
"SUBNET_IP_CAPACITY": 409,
"CONCURRENCY": 1000
},
"live": true,
"warnings": [
"Max-instances from configured fallback (S2R_CAPACITY_MAX_INSTANCES=50)."
]
},
"demand": {
"peakParallelCalls": 1250,
"peakObservedAt": "2023-10-27 14:00:00.0",
"callsPerDay": 2150498,
"discoveredServiceCount": 88,
"windowDays": 30,
"resolution": "measured",
"warnings": []
},
"verdict": "OVER_CAPACITY"
}
The response object contains three top-level fields: capacity, demand, and verdict.
capacity Object| Field | Type | Description |
|---|---|---|
provider | String | The simple class name of the CapacityProvider used (e.g., GcpCapacityProvider, StaticCapacityProvider). |
region | String | The region of the deployment. |
service | String | The name of the service being analyzed. |
effectiveMaxInstances | Integer | The maximum number of instances the service can scale to, considering all constraints. |
concurrencyPerInstance | Integer | The number of concurrent calls a single instance can handle. |
maxSimultaneousCalls | Long | The total maximum number of simultaneous calls the deployment can handle across all instances. null if capacity could not be determined. |
limitingFactor | String | The name of the resource that is the primary constraint on maxSimultaneousCalls. |
factorCeilings | Map<String, Integer> | A map showing the calculated ceiling for each capacity factor (e.g., max instances, regional quota, IP addresses). |
live | Boolean | true if the capacity data was sourced from a live provider; false if it came entirely from static configuration. |
warnings | Array of Strings | A list of warnings related to capacity calculation, such as the use of fallback values. |
demand Object| Field | Type | Description |
|---|---|---|
peakParallelCalls | Long | The highest number of parallel calls observed during the windowDays. null if demand could not be calculated. |
peakObservedAt | String | The timestamp (UTC) of the hourly bucket when peakParallelCalls was observed. |
callsPerDay | Long | The total number of calls (success and failure) processed in the last 24 hours. |
discoveredServiceCount | Integer | The number of distinct services that received traffic in the last 24 hours. |
windowDays | Integer | The number of past days analyzed to find the peakParallelCalls. |
resolution | String | The method used to determine peakParallelCalls. Either "measured" (from pre-computed data) or "hourly-estimate" (calculated using Little's Law). |
warnings | Array of Strings | A list of warnings related to demand calculation, such as database query failures. |
The service is configured through application properties, which can be supplied as environment variables.
| Property / Environment Variable | Type | Default | Required | Description |
|---|---|---|---|---|
s2r.capacity.region / S2R_REGION | String | — | No | The cloud region of the deployment. Used by the StaticCapacityProvider. |
s2r.capacity.service / S2R_CAPACITY_SERVICE | String | s2r-runtime | No | The name of the service being analyzed. Used by the StaticCapacityProvider. |
s2r.capacity.max-instances / S2R_CAPACITY_MAX_INSTANCES | Integer | — (null) | No | Fallback for the maximum number of instances the service can scale to. |
s2r.capacity.concurrency / S2R_CAPACITY_CONCURRENCY | Integer | — (null) | No | Fallback for the number of concurrent requests a single service instance can handle. |
s2r.capacity.regional-quota / S2R_CAPACITY_REGIONAL_QUOTA | Integer | — (null) | No | Fallback for the total instance quota for the service in the configured region. |
s2r.capacity.usable-ips / S2R_CAPACITY_USABLE_IPS | Long | — (null) | No | Fallback for the number of available IP addresses in the deployment's subnet. |
s2r.capacity.ips-per-instance / S2R_CAPACITY_IPS_PER_INSTANCE | Integer | — (null) | No | Fallback for the number of IP addresses consumed by each service instance. |
s2r.capacity.assumed-call-ms / S2R_CAPACITY_ASSUMED_CALL_MS | Long | 200 | No | The assumed average call duration in milliseconds, used in the fallback demand estimate when actual backend latency is not available. |
s2r.capacity.demand-window-days / S2R_CAPACITY_DEMAND_WINDOW_DAYS | Integer | 30 | No | The number of days of historical data to scan when calculating peakParallelCalls. |
NOTE
The S2R_CAPACITY_* variables are primarily used in two scenarios:
CapacityProvider is active.nullIf a database query to fetch a demand metric (e.g., callsPerDay or peakParallelCalls) fails, the service will not fail. Instead, the corresponding field in the demand object of the response will be null, and a descriptive error message will be added to the demand.warnings array.
If the capacity.warnings array contains messages like "Max-instances from configured fallback...", it means the live CapacityProvider was unable to determine that value from the cloud environment. The service successfully used the corresponding S2R_CAPACITY_* environment variable as a substitute. While the estimate is still valid, this may indicate a problem with the service account permissions used for live discovery.
A verdict of UNKNOWN indicates that the service was unable to calculate maxSimultaneousCalls. This occurs when essential capacity inputs (like max instances, concurrency, or IP availability) are missing from both the live provider and the static configuration fallbacks. Check that the S2R_CAPACITY_* variables are set correctly if you are not using a live provider, or investigate the capacity.warnings for clues if you are.
discoveredServiceCount metric.