-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use RUNBOOK_URL_TEMPLATE
env for the runbooks URL template
#524
Conversation
Hi @assafad. Thanks for your PR. I'm waiting for a kubevirt member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. 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/test-infra repository. |
/hold |
Thanks! Can you add tests for the new feature please? |
Does the env variable have to be a format string, or will it always be a prefix? In my opinion, accepting a format string as an env variable doesn't seem safe. It could probably cause a panic, if the formatting parameters are incorrect. |
Blocked by kubevirt/monitoring#165 |
@0xFelix Hi, I've added some tests on internal/operands/metrics/reconcile_test.go. Beware that we also have this test, that checks if the runbooks are accessible. Please let me know if the new tests make sense. |
@akrejcir Not sure I fully understand your concern. We don't assume that |
@akrejcir wanted to point out that you can inject arbitrary format specifiers when reading |
@0xFelix, @akrejcir For now, U/S URLs template is indeed a prefix, but different installations/versions have different documentation requirements. Thus, assuming the alerts names are suffix is not generic enough and might require future updates. I validated here that |
Ok, we can keep this for now. If the pattern is incorrect, the resulting string will contain an error message https://pkg.go.dev/fmt#hdr-Format_errors . So it will not panic. |
/lgtm |
Right, it's not a good solution. @assafad, can you change the code, so that the env variable
Where |
/lgtm cancel |
/retest |
} | ||
|
||
if strings.Count(runbookURLTemplate, "%s") != 1 || strings.Count(runbookURLTemplate, "%") != 1 { | ||
panic(errors.New("runbook URL template must have exactly 1 %s substring")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you return an error instead of panicking? The error is caused by user input and that could be handled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated, please let me know if the change makes sense
/ok-to-test |
/retest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one more nit, otherwise looks good to me!
}, | ||
Entry("should use the default template when no ENV variable is set", defaultRunbookURLTemplate), | ||
Entry("should use the ENV variable when a valid value is set", "valid/runbookURL/template/%s"), | ||
Entry("should throw an error when an invalid ENV variable value is set", "invalid/runbookURL/template/"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add negative test case for another format specifier, e.g. %d
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added
Signed-off-by: assafad <aadmi@redhat.com>
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
/retest |
Thank you! It looks good to me! @akrejcir WDYT? /approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: 0xFelix The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Looks good, thanks. /lgtm |
What this PR does / why we need it:
When
RUNBOOK_URL_TEMPLATE
env variable is set, its value will be used as the runbooks URL template. Otherwise, keep using the default runbook URL templatehttps://kubevirt.io/monitoring/runbooks/%s
.This allows using different runbooks versions, in accordance with the installation.
Which issue(s) this PR fixes:
Jira-ticket - https://issues.redhat.com/browse/CNV-14382
Special notes for your reviewer:
Release note: