-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
feat: added thanos check rules command #1097
Conversation
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.
Good stuff 🥇 . Some nits around coding style. Also tests shouldn't be hard to do :)
Also please add this to CHANGELOG
Just one general thought. Should we run this check in the thanos-rule also? |
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.
Looks awesome generally, some comments.
@povilasv Added tests and resolved all your comments PTAL if that's ok with you. |
So I managed to update even the docs and the genflags script. Also the output is now using logger so it looks like this: $ ./thanos check rules cmd/thanos/testdata/rules-files/*.yaml ; echo "$?"
level=info ts=2019-05-02T05:54:37.584375498Z caller=check.go:62 msg=Checking filename=cmd/thanos/testdata/rules-files/invalid-rules-data.yaml
level=error ts=2019-05-02T05:54:37.585238171Z caller=check.go:45 result=FAILED
level=error ts=2019-05-02T05:54:37.585292302Z caller=check.go:47 error="Groupname should not be empty"
level=info ts=2019-05-02T05:54:37.585335002Z caller=check.go:50
level=info ts=2019-05-02T05:54:37.585365002Z caller=check.go:62 msg=Checking filename=cmd/thanos/testdata/rules-files/invalid-yaml-format.yaml
level=error ts=2019-05-02T05:54:37.585543024Z caller=check.go:45 result=FAILED
level=error ts=2019-05-02T05:54:37.585591893Z caller=check.go:47 error="yaml: line 4: could not find expected ':'"
level=info ts=2019-05-02T05:54:37.585625624Z caller=check.go:50
level=info ts=2019-05-02T05:54:37.585653444Z caller=check.go:62 msg=Checking filename=cmd/thanos/testdata/rules-files/valid.yaml
level=info ts=2019-05-02T05:54:37.586356768Z caller=check.go:53 result=SUCCESS rulesfound=2
check rules command failed: 2 errors: Groupname should not be empty; yaml: line 4: could not find expected ':'
1 |
Thanks @povilasv ! all applied. |
@FUSAKLA you just forced pushed which removed the fixes :P could reapply again? |
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.
LGTM
@bwplotka do you want take another look?
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.
LGTM besides those few minor nits. Thank you a lot! 👍
e072530
to
f25f441
Compare
Thanks @GiedriusS, should be fixed and rebased on master now |
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.
LGTM, can you rebase on master again? The CHANGELOG.md
file has changed and we cannot merge this 😛
Thanks! Should be up to date now. |
864a74c
to
9505f39
Compare
Could you rebase it one more time? Then I'll give it one last review and I think we can merge this. Thank you for this work and the persistence, it's not easy |
Sorry for the inactivity, I'm back. @GiedriusS rebased so PTAL if you find a time 🙏, thanks! |
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.
Found another small issue:
./thanos check rules --log.format=json ./cmd/thanos/testdata/rules-files/invalid-unknown-field.yaml
{"caller":"check.go:69","filename":"./cmd/thanos/testdata/rules-files/invalid-unknown-field.yaml","level":"info","msg":"checking","ts":"2019-05-27T12:45:15.957753106Z"}
{"caller":"check.go:42","level":"error","result":"FAILED","ts":"2019-05-27T12:45:15.958307088Z"}
{"caller":"check.go:44","error":"yaml: unmarshal errors:\n line 4: field interrrrrrrrval not found in type main.ThanosRuleGroup","level":"error","ts":"2019-05-27T12:45:15.958366609Z"}
{"caller":"check.go:47","level":"info","ts":"2019-05-27T12:45:15.958406713Z"}
check rules command failed: yaml: unmarshal errors:
line 4: field interrrrrrrrval not found in type main.ThanosRuleGroup
It seems like the JSON format gets broken a bit when errors happen. Perhaps we should remove or rework cmd/thanos/check.go:47
? 🤔
@GiedriusS not sure if this is a bug. It looks like the cmds return error and if the whole process returns any it's printed out by the and this is not using the logger. For example if you run:
Yep, it's here I believe? I can print it out using the logger if you want but that would affect all other thanos components but it works as expected so it up to you.
|
Sorry, I haven't looked into this completely when commenting originally (didn't see that you haven't introduced this yourself) but yes, I think that should be removed and the proper logger should be used. I mean the user asks for a JSON formatted log so it should be printed like that, no? 😄 Could you add that change? |
@GiedriusS sorry for the delay. I changed the log and rebased on the recent master if that is ok with you now? I agree this way it's more consistent :) |
I rebased it once again, fixed issues with MultiError from TSDB which moved meantime to different package and updated the docs cmd flags which changed also. CI is green 🎉 |
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.
Thanks! 😄Will let someone else look through this again before merging.
Signed-off-by: Martin Chodur <[email protected]>
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.
Looking good! Awesome. Thanks 👍
Resolves #1096
This adds
thanos check rules
command to check Prometheus rules.We cannot use the
promtool check rules
since Thanos-rule allows the additional fieldpartial_response_strategy
Changes
Verification
Tested it on different types of invalid rule files even valid. Works fine.