Skip to content

test(tuner): add unit tests for queueingmodel/tuner package (0 → 56 tests)#1465

Open
Goutham-Annem wants to merge 2 commits into
llm-d:mainfrom
Goutham-Annem:test/queueingmodel-tuner-coverage
Open

test(tuner): add unit tests for queueingmodel/tuner package (0 → 56 tests)#1465
Goutham-Annem wants to merge 2 commits into
llm-d:mainfrom
Goutham-Annem:test/queueingmodel-tuner-coverage

Conversation

@Goutham-Annem

Copy link
Copy Markdown
Contributor

What

The internal/engines/analyzers/queueingmodel/tuner package had zero test coverage despite containing ~750 lines of Kalman-filter-based parameter tuning logic. This PR adds 56 table-driven unit tests covering all meaningful exported functions.

Tests added (tuner_test.go)

Function / Method Sub-cases
FloatEqual Exact equality, near-zero, large values, one-zero, negative, asymptotic
IsSymmetric Non-square, 1×1, symmetric 2×2 and 3×3, non-symmetric
GetFactoredSlice Empty, unit, double, zero, negative, fractional; input not mutated
Environment.Valid All 10 invalid-field combinations (zero/negative/NaN/Inf per field)
Environment.GetObservations Vector length and values
CreateTunerConfigFromData nil vs provided FilterData; valid/nil/invalid env; state bounds
NewConfigurator (checkConfigData) 16 sub-cases — every validation branch: zero factors, NaN/Inf state, length mismatches, non-symmetric covariance, min≥max bounds
Configurator.GetStateCov Diagonal correctness, wrong-length state vector
NewTuner Valid path; nil env; invalid env; nil config
Tuner.UpdateEnvironment nil env; invalid env; valid replacement

All 56 tests pass (go test ./internal/engines/analyzers/queueingmodel/tuner/...).

Why

These are stateless pure-logic functions with no Kubernetes dependencies, making them ideal unit test targets. The validation paths in checkConfigData and Environment.Valid were completely untested, leaving silent misbehavior possible if callers pass bad inputs.

When a managed HPA or ScaledObject is deleted or de-annotated, the three
replica scaling gauges (wva_current_replicas, wva_desired_replicas,
wva_desired_ratio) and the accelerator-tracking map entry were never
cleaned up. This caused the /metrics endpoint to keep exporting stale
series for removed variants indefinitely (not via Prometheus staleness,
but via a live GaugeVec that never had .Delete() called).

Changes:
- Add MetricsEmitter.DeleteReplicaMetrics(variantName, namespace) that
  .Delete()s all three gauge series and prunes the replicaSeriesAccel
  map entry under the mutex.
- Wire DeleteReplicaMetrics into HPAReconciler and ScaledObjectReconciler
  on both the IsNotFound path (object gone) and the de-annotation /
  deletion-timestamp path.
- Add MetricsEmitter field to both reconcilers; update cmd/main.go to
  retain and pass the emitter instance.
- Correct the misleading 'expire via Prometheus staleness' comment:
  a GaugeVec series does not expire while the controller process is alive.
- Add five unit specs covering: eviction of all three gauges, map pruning,
  isolation (sibling VA unaffected), no-op on never-emitted variant, and
  unresolved-accelerator series.

Fixes llm-d#1459

Signed-off-by: Goutham Annem <Goutham-Annem@users.noreply.github.com>
The internal/engines/analyzers/queueingmodel/tuner package had zero test
coverage despite containing meaningful Kalman-filter tuning logic. Add 56
table-driven unit tests covering:

- FloatEqual: exact equality, near-zero, large values, NaN/Inf edge cases
- IsSymmetric: square vs non-square, symmetric/non-symmetric matrices
- GetFactoredSlice: normal, zero, negative multipliers; no mutation of input
- Environment.Valid/GetObservations: all invalid-field combinations
- CreateTunerConfigFromData: nil vs provided FilterData, valid/nil/invalid env
- NewConfigurator (exercises checkConfigData): 16 sub-cases covering every
  validation branch (zero factors, NaN/Inf state, mismatched lengths,
  non-symmetric covariance, min>=max bounds)
- Configurator.GetStateCov: diagonal correctness, wrong-length state error
- NewTuner / UpdateEnvironment: nil and invalid-env guard paths

Signed-off-by: Goutham Annem <Goutham-Annem@users.noreply.github.com>
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.

1 participant