test(tuner): add unit tests for queueingmodel/tuner package (0 → 56 tests)#1465
Open
Goutham-Annem wants to merge 2 commits into
Open
test(tuner): add unit tests for queueingmodel/tuner package (0 → 56 tests)#1465Goutham-Annem wants to merge 2 commits into
Goutham-Annem wants to merge 2 commits into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The
internal/engines/analyzers/queueingmodel/tunerpackage 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)FloatEqualIsSymmetricGetFactoredSliceEnvironment.ValidEnvironment.GetObservationsCreateTunerConfigFromDataFilterData; valid/nil/invalid env; state boundsNewConfigurator(checkConfigData)Configurator.GetStateCovNewTunerTuner.UpdateEnvironmentAll 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
checkConfigDataandEnvironment.Validwere completely untested, leaving silent misbehavior possible if callers pass bad inputs.