refactor(vpa): make prometheus history provider config testable#9750
refactor(vpa): make prometheus history provider config testable#9750ulascansenturk wants to merge 1 commit into
Conversation
|
Hi @ulascansenturk. Thanks for your PR. I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with Regular contributors should join the org to skip this step. Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions 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. |
| // Prometheus history provider config. They were previously dropped, leaving the | ||
| // queries without a metric name (kubernetes/autoscaler#9747). |
There was a problem hiding this comment.
| // Prometheus history provider config. They were previously dropped, leaving the | |
| // queries without a metric name (kubernetes/autoscaler#9747). | |
| // Prometheus history provider config. |
No need to mention why we have tests
There was a problem hiding this comment.
Can this test be expanded to test more options too?
There was a problem hiding this comment.
Trimmed the comment to just describe what the test checks, no rationale.
There was a problem hiding this comment.
Expanded it to set every recommender flag and assert the full resulting config, so the whole flag-to-config mapping is covered, not just the metric names. Also added a case for an invalid query timeout.
|
/ok-to-test |
8b8a402 to
07e366f
Compare
|
|
||
| // TestNewPrometheusHistoryProviderConfig verifies that every recommender flag is | ||
| // propagated to the Prometheus history provider config. | ||
| func TestNewPrometheusHistoryProviderConfig(t *testing.T) { |
There was a problem hiding this comment.
🤔
If someone adds a flag, and forgets to update newPrometheusHistoryProviderConfig, I think this test won't catch that.
Any idea if it's possible to somehow test if they forgot to update it?
There was a problem hiding this comment.
I don't know if it helps, but we could also move the prometheus specific settings within RecommenderConfig into it's own stuct inside of RecommenderConfig
There was a problem hiding this comment.
Added TestNewPrometheusHistoryProviderConfigMapsEveryField: it sets every flag non-zero and reflects over the result, failing on any zero-valued field. Verified it flags an unmapped field by name.
There was a problem hiding this comment.
Used the reflection test as the guard here. Happy to do the config restructure as a separate cleanup if you'd prefer.
07e366f to
8cf6842
Compare
omerap12
left a comment
There was a problem hiding this comment.
Can we merge all Test* function to one table driven unit test with different test cases?
|
/triage accepted |
…ilder Extract the construction of the Prometheus history provider config out of initHistoryProvider into newPrometheusHistoryProviderConfig so the flag-to-config mapping can be unit tested, and add a regression test that the history metric name flags are propagated. Refs kubernetes#9747 Signed-off-by: ulascansenturk <ulascansenturk@protonmail.com>
8cf6842 to
16bb7d0
Compare
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: ulascansenturk The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
/area vertical-pod-autoscaler
/kind cleanup
What this PR does / why we need it:
Follow-up to #9748, as discussed there. That PR was the minimal fix (cherry-picked to release-1.7). This PR does the refactor: it extracts the construction of the Prometheus history provider config out of
initHistoryProviderinto anewPrometheusHistoryProviderConfighelper, so the flag-to-config mapping can be unit tested, and adds a regression test asserting that--history-cpu-metric/--history-memory-metricare propagated.No behavior change; pure refactor plus test.
Which issue(s) this PR fixes:
Refs #9747
Special notes for your reviewer:
Builds on the fix from #9748 (already merged).
go test ./pkg/recommender/...passes; the new test fails without the field copies and passes with them.Does this PR introduce a user-facing change?: