Skip to content
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

Merged
merged 26 commits into from Jun 30, 2020

Conversation

alvinlin123
Copy link
Member

@alvinlin123 alvinlin123 commented Jun 19, 2020

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:

➜  cortex git:(issue-2710-commandline-doc) go run cmd/cortex/main.go -modules
alertmanager
all
compactor
configs
data-purger
distributor
flusher
ingester
querier
query-frontend
ruler
store-gateway
table-manager
exit status 2

➜  cortex git:(issue-2710-commandline-doc) go run cmd/cortex/main.go -target api
...
level=warn ts=2020-06-23T08:25:27.092681Z caller=cortex.go:298 msg="'api' is not a public module, is this intended?" public-modules="alertmanager, all, compactor, configs, data-purger, distributor, flusher, ingester, querier, query-frontend, ruler, store-gateway, table-manager"

Which issue(s) this PR fixes:
Fixes #2710, #2596

Checklist

  • Tests updated
  • Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

@pstibrany pstibrany self-requested a review June 19, 2020 11:40
@pstibrany
Copy link
Contributor

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.

@pstibrany
Copy link
Contributor

/cc @annanay25

@pstibrany
Copy link
Contributor

Related: #2596

@alvinlin123
Copy link
Member Author

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.

@pstibrany
Copy link
Contributor

pstibrany commented Jun 19, 2020

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"?

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 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 don’t think struct you have introduced is necessary, and I would like to avoid changing module type from string.
Instead, I suggest that we add flag to module manager register method to mark module as “public” (visible to user). To do that, I suggest that we change RegisterModule method to take variable number of flags of type “ModuleOption”, and implement one such option for this.

I guess if there are other packages depending on the constant strings of module names then this PR would be problematic.

Correct, it is a breaking change. We could do that if needed, but I don’t think we are there yet.

@alvinlin123
Copy link
Member Author

@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!

@alvinlin123 alvinlin123 force-pushed the issue-2710-commandline-doc branch 3 times, most recently from a246b0c to 2a8325b Compare June 20, 2020 06:12
@alvinlin123
Copy link
Member Author

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 -target module approach, it felt akward that you can use "module" in yaml config. Also, all the modules needs to depend on API, which is really unnecessary for just printing list of public modules.

So, I decided to introduce a -modules command line only flag:

➜  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

Copy link
Contributor

@pstibrany pstibrany left a 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?

CHANGELOG.md Outdated Show resolved Hide resolved
cmd/cortex/main.go Show resolved Hide resolved
cmd/cortex/main.go Outdated Show resolved Hide resolved
pkg/util/modules/modules.go Outdated Show resolved Hide resolved
pkg/util/modules/modules.go Outdated Show resolved Hide resolved
pkg/util/modules/modules.go Outdated Show resolved Hide resolved
@alvinlin123
Copy link
Member Author

Let's put all flags into module structure. Individual module options can modify module structure. (See my other comment about functional options).

since the module struct is not exported, I can't move the module option to the struct because doing so the cortex package will not be able to define an option setting function with argument of type *module.

@pstibrany
Copy link
Contributor

Let's put all flags into module structure. Individual module options can modify module structure. (See my other comment about functional options).

since the module struct is not exported, I can't move the module option to the struct because doing so the cortex package will not be able to define an option setting function with argument of type *module.

All options passable to RegisterModule should be defined in the package with module manager. Other packages should not be able to define options.

Copy link
Contributor

@pstibrany pstibrany left a 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.

pkg/util/modules/modules.go Outdated Show resolved Hide resolved
pkg/util/modules/modules_test.go Outdated Show resolved Hide resolved
pkg/util/modules/modules_test.go Outdated Show resolved Hide resolved
pkg/util/modules/modules_test.go Outdated Show resolved Hide resolved
pkg/util/modules/modules_test.go Outdated Show resolved Hide resolved
pkg/util/modules/modules.go Outdated Show resolved Hide resolved
pkg/util/modules/modules.go Outdated Show resolved Hide resolved
alvinlin123 and others added 13 commits June 24, 2020 02:10
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>
alvinlin123 and others added 2 commits June 24, 2020 02:10
Co-authored-by: Peter Štibraný <pstibrany@gmail.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>
Copy link
Contributor

@pstibrany pstibrany left a 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!

@alvinlin123
Copy link
Member Author

Thanks for your work on this PR!

Thanks for your patience and mentorship :)

CHANGELOG.md Outdated Show resolved Hide resolved
pkg/cortex/modules.go Outdated Show resolved Hide resolved
pkg/util/modules/modules.go Outdated Show resolved Hide resolved
alvinlin123 and others added 2 commits June 25, 2020 00:45
Co-authored-by: Peter Štibraný <pstibrany@gmail.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>
pkg/util/modules/modules.go Outdated Show resolved Hide resolved
Signed-off-by: Alvin Lin <alvinlin@amazon.com>
Copy link
Contributor

@pstibrany pstibrany left a 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).

pkg/cortex/cortex.go Outdated Show resolved Hide resolved
Co-authored-by: Peter Štibraný <pstibrany@gmail.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>
Copy link
Contributor

@pracucci pracucci left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@pracucci pracucci merged commit 92622a8 into cortexproject:master Jun 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Document for the -target parameter does not align with the ALL target defined in module manager
3 participants