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
Dynamically generate available options for -target commandline arg #2752
Dynamically generate available options for -target commandline arg #2752
Conversation
Thank you for your work on this. Unfortunately this goes against the idea why module manager was introduced in the first place: to allow projects that extend Cortex to dynamically add new modules (and set new depedendies). In this light, it’s not easily possible to enumerate all modules before they are actually added to the module manager. Given that, one way to make this work may be to define special target like “modules” that would simply list all modules. (Or only modules that should be public in the first place, which can be defined by a new flag passed to RegisterModule function). It’s not as elegant as having it in the -help output, but should work. |
/cc @annanay25 |
Related: #2596 |
Hi @pstibrany thank you for your comment. Can you elaborate more on why "this goes against the idea why module manager was introduced in the first place: to allow projects that extend Cortex to dynamically add new modules"? I checked the commit that added module manager and it seems like to "allow other projects to dynamically add new modules" was achieved by adding the module manager. My PR doesn't change anything regarding interaction with the module manager. My idea was, instead of using constant strings to describe a module, use a struct so that we can mark a module as public. The logic of registering and adding dependencies still remain the same. so even with this PR, other packages should still be able to dynamically add module through module manager. I guess if there are other packages depending on the constant strings of module names then this PR would be problematic. |
There is at least one (not open source) project extending Cortex by reusing the main Cortex structure, its flags and registering additional modules. I would like help for -target option to reflect such added modules. Since they are added to the module manager only after help string for this option has been constructed, I think the best way to do that is by saying “To get list of available modules, use -target=modules”, and to introduce such “modules” module that would only print list of registered user-visible modules, and then stop. (This would also make sure that list is always up to date, and help string isn’t obsolete)
I don’t think struct you have introduced is necessary, and I would like to avoid changing module type from string.
Correct, it is a breaking change. We could do that if needed, but I don’t think we are there yet. |
@pstibrany I see, thanks for the explanation, I get the point now. Let me ponder a bit, and I will update this PR. Thanks again! |
a246b0c
to
2a8325b
Compare
I have push new changes that display list of possible target values as well as throw error if given non-public target. However, I didn't go with the So, I decided to introduce a ➜ cortex git:(issue-2710-commandline-doc) go run cmd/cortex/main.go -modules
alertmanager
data-purger
flusher
query-frontend
all
distributor
store-gateway
configs
ingester
compactor
table-manager
ruler
querier
exit status 2 Below is an example when user pass in non-public target (I list out the possible values in the error message): ➜ cortex git:(issue-2710-commandline-doc) go run cmd/cortex/main.go -target ring
level=info ts=2020-06-20T06:42:36.235822Z caller=main.go:140 msg="Starting Cortex" version="(version=, branch=, revision=)"
level=error ts=2020-06-20T06:42:36.235893Z caller=log.go:140 msg="error running cortex" err="invalid target: ring; valid targets are: store-gateway, data-purger, compactor, flusher, query-frontend, ruler, configs, ingester, table-manager, distributor, alertmanager, all, querier"
exit status 1 |
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.
Thank you, this looks good. I like -module
idea, that is nicer than having extra module for that. I'd prefer to have single RegisterModule
method with options, to reduce number of exported methods and structs. What do you think?
since the module struct is not exported, I can't move the module option to the struct because doing so the |
All options passable to |
7cd120d
to
d0e12b5
Compare
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.
This is looking really good, thank you for addressing my feedback. I have added few more minor comments.
Signed-off-by: Alvin Lin <alvinlin@amazon.com>
Signed-off-by: Alvin Lin <alvinlin@amazon.com>
Signed-off-by: Alvin Lin <alvinlin@amazon.com>
Signed-off-by: Alvin Lin <alvinlin@amazon.com>
Signed-off-by: Alvin Lin <alvinlin@amazon.com>
Signed-off-by: Alvin Lin <alvinlin@amazon.com>
Signed-off-by: Alvin Lin <alvinlin@amazon.com>
Signed-off-by: Alvin Lin <alvinlin@amazon.com>
Signed-off-by: Alvin Lin <alvinlin@amazon.com>
Signed-off-by: Alvin Lin <alvinlin@amazon.com>
Signed-off-by: Alvin Lin <alvinlin@amazon.com>
Signed-off-by: Alvin Lin <alvinlin@amazon.com>
Co-authored-by: Peter Štibraný <pstibrany@gmail.com> Signed-off-by: Alvin Lin <alvinlin@amazon.com>
Co-authored-by: Peter Štibraný <pstibrany@gmail.com> Signed-off-by: Alvin Lin <alvinlin@amazon.com>
Signed-off-by: Alvin Lin <alvinlin@amazon.com>
608dc24
to
7c8f400
Compare
Signed-off-by: Alvin Lin <alvinlin@amazon.com>
Signed-off-by: Alvin Lin <alvinlin@amazon.com>
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 for your work on this PR!
Thanks for your patience and mentorship :) |
Co-authored-by: Peter Štibraný <pstibrany@gmail.com> Signed-off-by: Alvin Lin <alvinlin@amazon.com>
Signed-off-by: Alvin Lin <alvinlin@amazon.com>
1095098
to
83b2f37
Compare
Signed-off-by: Alvin Lin <alvinlin@amazon.com>
Signed-off-by: Alvin Lin <alvinlin@amazon.com>
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.
Please do let me know if you think it's still off; I happen think variable/method/class/whatever names are very important and I am more than welling to spend time to get the terms right to increase readability, so please don't run out of patience with me :)
At some point we need to stop bike-shedding this 😉 I'm fine with the current state. (I would perhaps use UserHiddenModule
, but UserInvisibleModule
is fine too).
Co-authored-by: Peter Štibraný <pstibrany@gmail.com> Signed-off-by: Alvin Lin <alvinlin@amazon.com>
fde00f5
to
3cf8f2a
Compare
Signed-off-by: Alvin Lin <alvinlin@amazon.com>
Signed-off-by: Alvin Lin <alvinlin@amazon.com>
f38b78c
to
0466ce8
Compare
Signed-off-by: Alvin Lin <alvinlin@amazon.com>
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, thanks!
What this PR does:
Add missing options to the command line help text for
-target
. The options are dynamically generated so we don't have to manually modify the text when we add new module in the future.Testing:
Which issue(s) this PR fixes:
Fixes #2710, #2596
Checklist
CHANGELOG.md
updated - the order of entries should be[CHANGE]
,[FEATURE]
,[ENHANCEMENT]
,[BUGFIX]