Skip to content

[Flex] Bill HTTP-prescaled instances as AlwaysReady baseline until first execution - #11900

Open
Mani (manikantanallagatla) wants to merge 2 commits into
devfrom
user/mnallagatla/prescaling_billing
Open

[Flex] Bill HTTP-prescaled instances as AlwaysReady baseline until first execution#11900
Mani (manikantanallagatla) wants to merge 2 commits into
devfrom
user/mnallagatla/prescaling_billing

Conversation

@manikantanallagatla

Copy link
Copy Markdown
Contributor

Why

HTTP prescaling pre-warms Flex Consumption instances before load, but today their reserved warm time is not billed. This implements the approved v1 deferred-on-demand design: reuse the existing AlwaysReady baseline meter while a prescaled instance is unused, then switch to normal OnDemand billing when it serves its first execution.

This avoids introducing a new Commerce meter, following Thiago's guidance that meter sprawl carries a 6+ month delivery risk.

What changed

  • Added the FUNCTIONS_PRESCALED_INSTANCE host environment setting.
  • A prescaled, unused instance publishes zero-activity metrics stamped IsAlwaysReady=true, which routes them to the existing AlwaysReady baseline meter.
  • The first OnFunctionStarted permanently flips that instance to OnDemand before the serving interval is metered.
  • Added focused coverage for unused baseline publishing, first-execution transition, and post-execution idle behavior.

Compatibility

The change is inert until the appserver injects FUNCTIONS_PRESCALED_INSTANCE=1.

  • Real AlwaysReady instances remain AlwaysReady for their lifetime.
  • Normal OnDemand instances are unchanged.
  • Prescaled instances that are never used continue publishing baseline until the appserver removes them under its unused-pod expiry policy.

Cross-component contract

The cv2 appserver implementation in AAPT-Antares-Functions-Docker PR 16449382 (developer/balag/prescale) must:

  • set FUNCTIONS_PRESCALED_INSTANCE=1 on prescaled pods; and
  • not set it on normal pods.

Balaji Balakrishnan (@bala): please confirm FUNCTIONS_PRESCALED_INSTANCE is the agreed environment-variable name.

Billing routing

No Legion code change is required. NestedRoleFunctionsMetricsCollector already groups and routes billing using Metrics.IsAlwaysReady, so the host's effective stamp selects the existing AlwaysReady meter.

Design: Legion PR 16487726 (docs/functions/prescaling-billing-design.md).

Tests

dotnet test test/WebJobs.Script.Tests/WebJobs.Script.Tests.csproj --filter "FullyQualifiedName~FlexConsumptionMetricsPublisherTests"

Passed: 13, Failed: 0, Skipped: 0. The existing real-AlwaysReady theory also passed both cases unchanged.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@manikantanallagatla
Mani (manikantanallagatla) marked this pull request as ready for review September 7, 2026 05:36
@manikantanallagatla
Mani (manikantanallagatla) requested a review from a team as a code owner September 7, 2026 05:36
Copilot AI lite review requested due to automatic review settings September 7, 2026 05:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

This change affects billing-routing semantics for Flex prescaling, so it warrants final human review despite the added targeted test coverage.

Pull request overview

Implements Flex Consumption “deferred-on-demand” prescaling billing by treating prescaled-but-unused instances as AlwaysReady baseline (via metrics stamping) until the first function execution, after which the instance permanently transitions to normal OnDemand billing behavior.

Changes:

  • Introduces FUNCTIONS_PRESCALED_INSTANCE and uses it to publish zero-activity baseline metrics stamped IsAlwaysReady=true until first execution.
  • Permanently flips prescaled instances to IsAlwaysReady=false on first OnFunctionStarted, ensuring subsequent intervals route to OnDemand.
  • Adds targeted unit tests covering unused baseline publishing, first-execution transition (including during an in-flight publish), and post-execution idle behavior.
File summaries
File Description
test/WebJobs.Script.Tests/Metrics/FlexConsumptionMetricsPublisherTests.cs Adds prescaled-instance billing behavior coverage and adjusts publisher creation to inject configuration / mock metrics provider.
src/WebJobs.Script/Environment/EnvironmentSettingNames.cs Adds FUNCTIONS_PRESCALED_INSTANCE constant.
src/WebJobs.Script.WebHost/WebHostServiceCollectionExtensions.cs Injects IConfiguration into FlexConsumptionMetricsPublisher construction for Flex SKU.
src/WebJobs.Script.WebHost/Metrics/FlexConsumptionMetricsPublisher.cs Implements prescaled detection and AlwaysReady-baseline stamping until first execution is observed.
Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +345 to +350
var configuration = s.GetService<IConfiguration>();
var options = s.GetService<IOptions<FlexConsumptionMetricsPublisherOptions>>();
var standbyOptions = s.GetService<IOptionsMonitor<StandbyOptions>>();
var logger = s.GetService<ILogger<FlexConsumptionMetricsPublisher>>();
var metricsProvider = s.GetService<IHostMetricsProvider>();
return new FlexConsumptionMetricsPublisher(environment, standbyOptions, options, logger, new FileSystem(), metricsProvider);
return new FlexConsumptionMetricsPublisher(environment, configuration, standbyOptions, options, logger, new FileSystem(), metricsProvider);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants