Skip to content

fix: format autoscaling annotation values without trailing zeros - #3904

Open
Elvand-Lie wants to merge 2 commits into
knative:mainfrom
Elvand-Lie:fix/autoscaling-annotation-format
Open

Elvand-Lie wants to merge 2 commits into
knative:mainfrom
Elvand-Lie:fix/autoscaling-annotation-format

Conversation

@Elvand-Lie

@Elvand-Lie Elvand-Lie commented Jun 17, 2026 •

Copy link
Copy Markdown
Contributor

Description

setServiceOptions in pkg/knative/deployer.go formatted the autoscaling Target and Utilization annotations with fmt.Sprintf("%f", ...), which writes six decimal places ("100.000000").

Both values are now formatted with strconv.FormatFloat(v, 'f', -1, 64): plain decimal, no trailing zeros, and no exponent form (100, 70.5, 1000000). %g would have switched to 1e+06 at one million.

Existing services get one new revision on their next deploy, since the annotation text changes.

Changes

  • pkg/knative/deployer.go: format Target and Utilization with strconv.FormatFloat
  • pkg/knative/deployer_test.go: TestSetServiceOptions_ScaleAnnotationFormat covers integer, fractional and 1e6 values
  • pkg/knative/deployer_scale_test.go: expected values updated

Fixes #3901

Release Note

Knative autoscaling target and utilization annotations are written as plain numbers (for example "100" instead of "100.000000").

@knative-prow
knative-prow Bot requested review from dsimansk and jrangelramos June 17, 2026 20:50
@knative-prow knative-prow Bot added size/M 🤖 PR changes 30-99 lines, ignoring generated files. needs-ok-to-test 🤖 Needs an org member to approve testing labels Jun 17, 2026
@knative-prow

knative-prow Bot commented Jun 17, 2026

Copy link
Copy Markdown

Hi @Elvand-Lie. Thanks for your PR.

I'm waiting for a knative member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Tip

We noticed you've done this a few times! Consider joining the org to skip this step and gain /lgtm and other bot rights. We recommend asking approvers on your previous PRs to sponsor you.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@Elvand-Lie

Copy link
Copy Markdown
Contributor Author

Verification Evidence

1. go vet: clean

$ go vet ./pkg/knative
# (no output, clean)

2. Before vs After

// BEFORE fix (%f):
fmt.Sprintf("%f", 100.0)  // produces "100.000000"
fmt.Sprintf("%f", 70.0)   // produces "70.000000"
fmt.Sprintf("%f", 70.5)   // produces "70.500000"

// AFTER fix (%g):
fmt.Sprintf("%g", 100.0)  // produces "100"
fmt.Sprintf("%g", 70.0)   // produces "70"
fmt.Sprintf("%g", 70.5)   // produces "70.5"

3. Regression test output

$ go test ./pkg/knative/ -run TestSetServiceOptions_ScaleAnnotationFormat -count=1 -v
=== RUN   TestSetServiceOptions_ScaleAnnotationFormat
--- PASS: TestSetServiceOptions_ScaleAnnotationFormat (0.00s)
PASS
ok  	knative.dev/func/pkg/knative	0.280s

4. Full package test suite, all pass

$ go test ./pkg/knative/ -count=1 -v
=== RUN   TestValidateKubeconfigFile
--- PASS: TestValidateKubeconfigFile (1.21s)
=== RUN   TestCheckPullPermissions
--- PASS: TestCheckPullPermissions (4.83s)
=== RUN   TestCheckPullPermissions_FunctionImagePullSecret
--- PASS: TestCheckPullPermissions_FunctionImagePullSecret (0.01s)
=== RUN   TestUpdateService_EnvsPropagated
--- PASS: TestUpdateService_EnvsPropagated (0.00s)
=== RUN   TestGenerateNewService_ResourceSetsPopulated
--- PASS: TestGenerateNewService_ResourceSetsPopulated (0.00s)
=== RUN   TestSetServiceOptions_ScaleAnnotationFormat
--- PASS: TestSetServiceOptions_ScaleAnnotationFormat (0.00s)
PASS
ok  	knative.dev/func/pkg/knative	8.327s

5. What the regression test checks

The new TestSetServiceOptions_ScaleAnnotationFormat test:

  • Creates fn.Options with Scale.Target = 100.0 and Scale.Utilization = 70.0
  • Calls setServiceOptions with a minimal RevisionTemplateSpec
  • Asserts autoscaling.knative.dev/target equals "100" (not "100.000000")
  • Asserts autoscaling.knative.dev/target-utilization-percentage equals "70" (not "70.000000")

@codecov

codecov Bot commented Jun 17, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 54.04%. Comparing base (d7b93f6) to head (2c8df8d).
⚠️ Report is 93 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3904      +/-   ##
==========================================
+ Coverage   54.00%   54.04%   +0.04%     
==========================================
  Files         200      200              
  Lines       23687    23687              
==========================================
+ Hits        12792    12802      +10     
+ Misses       9660     9653       -7     
+ Partials     1235     1232       -3     
Flag Coverage Δ
e2e 34.05% <0.00%> (ø)
e2e go 29.39% <0.00%> (ø)
e2e node 25.72% <0.00%> (ø)
e2e python 29.72% <0.00%> (ø)
e2e quarkus 25.85% <0.00%> (+0.01%) ⬆️
e2e rust 25.32% <0.00%> (ø)
e2e springboot 24.00% <0.00%> (ø)
e2e typescript 25.83% <0.00%> (ø)
e2e-config-ci 26.90% <0.00%> (ø)
integration 15.70% <0.00%> (+0.02%) ⬆️
unit macos-14 43.10% <100.00%> (+0.04%) ⬆️
unit macos-latest 43.10% <100.00%> (+0.04%) ⬆️
unit ubuntu-24.04-arm 43.41% <100.00%> (+0.04%) ⬆️
unit ubuntu-latest 43.95% <100.00%> (+0.04%) ⬆️
unit windows-latest 43.16% <100.00%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Elvand-Lie
Elvand-Lie force-pushed the fix/autoscaling-annotation-format branch from bc022b5 to 740583b Compare June 18, 2026 04:43
@matejvasek
matejvasek requested a review from Copilot June 18, 2026 10:07

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.

Pull request overview

This PR fixes formatting of Knative autoscaling annotation values produced by setServiceOptions so that integer-like floats don’t get emitted with trailing .000000, matching Knative’s expected annotation string format.

Changes:

  • Switch autoscaling Target and Utilization annotation formatting from "%f" to "%g" to remove trailing zeros.
  • Add a regression test ensuring 100.0 and 70.0 render as "100" and "70" in the resulting annotations.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
pkg/knative/deployer.go Updates autoscaling annotation value formatting to avoid unwanted trailing decimals.
pkg/knative/deployer_test.go Adds a regression test to assert the corrected annotation string formatting.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Elvand-Lie
Elvand-Lie force-pushed the fix/autoscaling-annotation-format branch from 740583b to 2c8df8d Compare June 26, 2026 13:36
@knative-prow-robot knative-prow-robot added the needs-rebase Cannot be merged due to conflicts with HEAD. label Aug 20, 2026
Elvand-Lie and others added 2 commits November 24, 2026 14:08
setServiceOptions used fmt.Sprintf(%%f, ...) to format autoscaling
Target and Utilization annotations, producing values like 100.000000
instead of 100. Knative autoscaler expects clean numeric strings.

Changed to %%g which strips trailing zeros (100.0 -> 100, 70.5 -> 70.5).

Also adds regression test TestSetServiceOptions_ScaleAnnotationFormat.

Fixes knative#3901
%f leaves trailing zeros ("100.000000"); %g switches to exponent form
at >= 1e6 ("1e+06"). FormatFloat with 'f' and prec -1 yields the clean
decimal Knative expects ("100", "70.5", "1000000").

Signed-off-by: Luke Kingland <luke@lukekingland.com>
@lkingland
lkingland force-pushed the fix/autoscaling-annotation-format branch from 2c8df8d to 03e24d3 Compare November 24, 2026 05:25
@knative-prow-robot knative-prow-robot removed the needs-rebase Cannot be merged due to conflicts with HEAD. label Nov 24, 2026
@lkingland lkingland changed the title fix: use %g instead of %f for autoscaling annotation values fix: format autoscaling annotation values without trailing zeros Nov 24, 2026
@lkingland

Copy link
Copy Markdown
Member

Thanks @Elvand-Lie. We rebased this and added one commit on top: strconv.FormatFloat instead of %g, so large values stay decimal (1000000, not 1e+06). The title and description now match.

/ok-to-test
/lgtm
/approve

@knative-prow knative-prow Bot added the ok-to-test 🤖 Non-member PR verified by an org member that is safe to test. label Nov 24, 2026
@knative-prow knative-prow Bot added lgtm 🤖 PR is ready to be merged. and removed needs-ok-to-test 🤖 Needs an org member to approve testing labels Nov 24, 2026
@knative-prow

knative-prow Bot commented Nov 24, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Elvand-Lie, lkingland

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow knative-prow Bot added the approved 🤖 PR has been approved by an approver from all required OWNERS files. label Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved 🤖 PR has been approved by an approver from all required OWNERS files. lgtm 🤖 PR is ready to be merged. ok-to-test 🤖 Non-member PR verified by an org member that is safe to test. size/M 🤖 PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

setServiceOptions: %f format produces invalid autoscaling annotation values with trailing zeros

4 participants