Skip to content

fix: cost_optimization keeps one key, and it reaches the object (#203) - #260

Merged
scttfrdmn merged 1 commit into
mainfrom
v0.11.0-cost-config
Aug 3, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
v0.11.0-cost-config

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Closes #203.

storage.s3.cost_optimization had six keys and no effect on anything. internal/config.S3CostOptimization and internal/storage/s3.CostOptimization shared not one field name, so buildS3Config carried a comment saying the block was not mappable — true, and not a fix. There was no mapping to write: transition_to_ia: 30 had to become an element of a []TransitionRule carrying a source tier, a destination tier, an access pattern and a size filter, none of which the YAML supplied, and nothing read TransitionRules either.

Breaking: five keys removed

Removed, not deprecated. Configuration decodes strictly, so a file still carrying one fails at startup naming the key — which is the only way an operator learns the setting never did anything. A block with no effect for its entire existence has no behavior to preserve.

Removed Why
enabled Gated nothing; the backend has no such field
tiering_enabled Transitions exist in the backend; no mount path invokes them
lifecycle_enabled Lifecycle rules are a bucket-level call this backend never makes
transition_to_ia Same
transition_to_glacier Same

Same treatment #176 gave the fifteen inert read-ahead keys, and the fourth instance of the shape #156, #176 and the cluster.redis fix were — in its worst form, since the two types could not be reconciled without deleting first.

The surviving key, corrected before being exposed

small_objects_on_standard (default false) stores an object on STANDARD when the configured tier would bill it as larger than it is and STANDARD is genuinely cheaper.

The old rule was objectSize < 128 KiB with no reference to the configured tier. It moved objects to STANDARD from tiers with no billing minimum at all — DEEP_ARCHIVE at ~23× the storage rate — and from the three that have one at sizes where they remain far cheaper. Being under a floor does not make STANDARD cheaper. The crossover is minBillable × rateTier / rateStandard:

Tier Crossover at list prices
STANDARD_IA 69.6 KiB
ONEZONE_IA 55.7 KiB
GLACIER_IR 22.3 KiB

A 32 KiB object billed as 128 KiB of GLACIER_IR costs about a third of 32 KiB on STANDARD. Three conditions are now required, the third computed against the prices this deployment pays (volume/enterprise discounts and CustomPricing included).

GLACIER and DEEP_ARCHIVE are excluded on a second, non-monetary ground: their objects cannot be read without a restore, so a diversion would change what a read does, not only what it costs. A cost heuristic must not decide retrieval semantics.

Two seams, both found at the endpoint

Both were found by asserting the storage class S3 recorded, not the value passed in — the technique that found the INTELLIGENT_TIERING default in v0.10.1.

CargoShip drops a per-object class. Transporter.optimizeStorageClass returns its own config's StorageClass — fixed at construction from storage_tier — for any archive with no AccessPattern/RetentionDays, which is every archive ObjectFS builds. It never reads Archive.StorageClass, the field whose comment says "Target storage class". The class was computed correctly and lost at the boundary: object stored fine, read fine, only the invoice differed. Diverging objects now take the direct PutObject path, joining the existing bypasses for compression and for encryption modes the transporter cannot express; the common path keeps CargoShip's throughput optimization. Filed upstream as scttfrdmn/cargoship#352 — OptimizedTransporter, a different type ObjectFS does not construct, already honors the field.

The billing warning described the wrong tier. ValidateWrite ran before the diversion, so an operator who enabled the setting because of that warning still saw billed_size=131072 on a 16 KiB object about to be stored on STANDARD and billed as 16 KiB. The diversion logs at Debug, so at the default level the misleading half was the only half visible. The tier decision now precedes validation, via ValidateWriteToTier. tier_constraints.min_object_size deliberately does not follow the effective tier: that is a floor the operator configured for this mount, and an internal cost optimization is not a reason to stop enforcing it.

TierValidator.GetRecommendations had the identical size-only rule and is fixed the same way. No mount-path caller — it is exported API — but advice nobody can act on wrongly is still advice someone will act on.

Tests, each verified by mutation

  • Eight-tier table with per-tier sizes on both sides of each crossover, so a size-only implementation cannot pass. Restoring the old rule fails 7 of 8 tiers, DEEP_ARCHIVE reporting "every object under 128 KiB went to STANDARD at ~23× the storage rate".
  • A negotiated 90% discount on STANDARD_IA must keep a 64 KiB object there.
  • The endpoint-level seam test — this is what caught the CargoShip drop, and it failed for real before the bypass landed.
  • The billing warning follows the effective tier, stays for the undiverted case, falls back on an unknown tier name (zero-valued StorageTierInfo means "no minimum", so an unrecognized name must not reach the checks as one), and does not relax the operator's floor.
  • TestBuildS3ConfigMapsEveryConfiguredValue asserted CostOptimization was the zero value — and kept passing once the mapping existed, for the wrong reason, because the fixture never set the key. It now sets it and compares the whole struct, so a new field arriving without a decision fails.
  • The rewritten recommendation test asserts behavior on both sides of the crossover rather than matching the old literal advice string, which passed for any object under 128 KiB on any tier including the ones where the advice was wrong.

Two s3.CostOptimization fields survive as Go fields with no YAML key, deliberately: EnableAutoTiering and CostThreshold are reachable to an embedder using the package as a library, while a mount has no path to AnalyzeAndOptimize. MonitorAccessPatterns is likewise unmapped, and for a second reason — the map it populates holds one entry per distinct key read and nothing evicts.

docs/index.md claimed "Lifecycle management: Automatic tiering to IA, Glacier, Deep Archive" as a key feature; it is now in the Not yet wired up table with the reason.

Verification

  • go build ./..., go vet ./..., go test -race ./... — all clean
  • golangci-lint run --new-from-merge-base=origin/main — 0 issues
  • ./scripts/coverage-gate.sh — 30 packages at or above their floors
  • markdownlint clean on every changed markdown file

Also updated: examples/config.yaml, docs-platform/guide/getting-started.md, sdks/python/README.md and sdks/python/objectfs/config.py — the Python SDK's default config wrote three of the removed keys as True, so to_yaml() produced a document asking for tiering and lifecycle management that would now fail the Go loader.

`storage.s3.cost_optimization` had six keys and no effect. internal/config's
S3CostOptimization and internal/storage/s3's CostOptimization shared not one
field name, so buildS3Config carried a comment saying the block was not
mappable — which was true, and is not a fix. `transition_to_ia: 30` had to
become an element of a []TransitionRule carrying a source tier, a destination
tier, an access pattern and a size filter, none of which the YAML supplied, and
nothing read TransitionRules either.

Five keys are deleted rather than plumbed, the same treatment #176 gave the
fifteen inert read-ahead keys: `enabled` gated nothing, `tiering_enabled` names
transitions no mount path invokes, and `lifecycle_enabled` / `transition_to_ia`
/ `transition_to_glacier` name bucket-level lifecycle rules this backend never
writes. Removed, not deprecated — config decodes strictly, so a file still
carrying one fails at startup naming it, which is the only way an operator
learns the setting never did anything.

`small_objects_on_standard` is what remains, and its behavior was corrected
before being exposed. The rule was `objectSize < 128 KiB` with no reference to
the configured tier, so it moved objects to STANDARD from tiers with no billing
minimum at all — DEEP_ARCHIVE at ~23× the storage rate — and from the three
that have one at sizes where they are still far cheaper. Being under a floor
does not make STANDARD cheaper: the crossover is minBillable × rateTier /
rateStandard, so 69.6 KiB on STANDARD_IA, 55.7 KiB on ONEZONE_IA, 22.3 KiB on
GLACIER_IR. Three conditions now, the third computed against the prices this
deployment pays. GLACIER and DEEP_ARCHIVE are excluded on a second ground:
their objects need a restore to read, so a diversion would change what a read
does, not only what it costs.

Two further seams, each found by asserting the class recorded at the endpoint
rather than the value passed in:

- CargoShip drops a per-object class. Transporter.optimizeStorageClass returns
  its own config's StorageClass for any archive with no AccessPattern and no
  RetentionDays — every archive ObjectFS builds — and never reads
  Archive.StorageClass, the field whose comment says "Target storage class". The
  diverted class was computed correctly and lost at the boundary; the object
  stored fine, read fine, and only the invoice differed. Diverging objects now
  take the direct path, joining the existing compression and encryption
  bypasses. Filed as scttfrdmn/cargoship#352.
- The billing warning described the wrong tier. ValidateWrite ran before the
  diversion, so an operator who enabled the setting because of that warning
  still saw billed_size=131072 on a 16 KiB object about to be billed as 16 KiB
  — and the diversion logs at Debug, so at the default level the misleading
  half was the only half visible. The decision now precedes validation.
  tier_constraints.min_object_size deliberately does not follow the effective
  tier: that is a floor the operator configured, and an internal cost
  optimization is not a reason to stop enforcing it.

GetRecommendations had the identical size-only rule and is fixed the same way.
It has no mount-path caller, but advice nobody can act on wrongly is still
advice someone will act on.

Tests, each verified by mutation:

- the eight-tier table with per-tier sizes on both sides of each crossover, so
  a size-only implementation cannot pass it; restoring the old rule fails 7 of
  8 tiers
- a negotiated 90% discount on STANDARD_IA must keep a 64 KiB object there
- the endpoint-level seam test, which is what caught the CargoShip drop
- the billing warning follows the effective tier, stays for the undiverted
  case, falls back on an unknown tier name, and does not relax the operator's
  floor
- the adapter mapping test asserted CostOptimization was the zero value and
  passed for the wrong reason once the mapping existed, because the fixture
  never set the key; it now sets it and compares the whole struct, so a new
  field arriving without a decision fails

docs/index.md claimed "Lifecycle management: Automatic tiering to IA, Glacier,
Deep Archive" as a key feature. It is now in the Not yet wired up table with
the reason.

Closes #203
@scttfrdmn
scttfrdmn merged commit 8981d93 into main Aug 3, 2026
23 checks passed
@scttfrdmn
scttfrdmn deleted the v0.11.0-cost-config branch August 3, 2026 10:32
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.

config: the two CostOptimization types are disjoint, so the YAML block cannot reach the backend at all

1 participant