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

feat: Allow passing unknown flags to plugins #1902

Closed

Conversation

erezrokah
Copy link
Member

@erezrokah erezrokah commented Sep 20, 2024

Summary

Should help with https://github.com/cloudquery/cloudquery-issues/issues/2455#issuecomment-2363343665 (internal issue).

At the moment, each time we add a new flag to a plugin and pass it from the CLI it will break all existing plugins since they fail to parse known flags.

This should allow the CLI send new flags to new plugins without breaking existing ones


Use the following steps to ensure your PR is ready to be reviewed

  • Read the contribution guidelines 🧑‍🎓
  • Run go fmt to format your code 🖊
  • Lint your changes via golangci-lint run 🚨 (install golangci-lint here)
  • Update or add tests 🧪
  • Ensure the status checks below are successful ✅

@erezrokah erezrokah requested a review from a team as a code owner September 20, 2024 10:08
@github-actions github-actions bot added feat and removed feat labels Sep 20, 2024
@erezrokah
Copy link
Member Author

The way I see it, we can add new properties to the spec without breaking existing plugins, so this should be the same

@erezrokah
Copy link
Member Author

Not sure why Post Unit Tests is failing seems unrelated

@github-actions github-actions bot added feat and removed feat labels Sep 20, 2024
Copy link
Member

@disq disq left a comment

Choose a reason for hiding this comment

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

Can we make it log a warning with the unhandled/unknown flag?

@erezrokah
Copy link
Member Author

Can we make it log a warning with the unhandled/unknown flag?

I can see if Cobra exposes the unknown flags

@hermanschaaf
Copy link
Member

hermanschaaf commented Sep 20, 2024

Yeah this seems a bit controversial, as the plugin may silently fail to act as you instructed it to act, which might be worse than failing hard

@disq
Copy link
Member

disq commented Sep 20, 2024

I think we should also add an --abort-on-unknown-flag type thing.

@marianogappa
Copy link
Contributor

Actually @hermanschaaf has a really good point here cc @erezrokah

I encountered this many times across the years. You misspell a flag and don't notice and suddenly your tool misbehaves and you find out the week after 🤔

I think this needs some thinking. Because forwards/backwards compatibility is important too.

@erezrokah
Copy link
Member Author

Yeah this seems a bit controversial, as the plugin may silently fail to act as you instructed it to act, which might be worse than failing hard

Yeah I think this is mostly an internal problem for us, less for our users.

@disq
Copy link
Member

disq commented Sep 20, 2024

Maybe we can turn this around, by adding an --ignore-unknown-flags flag? Then each time the cli specifies a "known-new" flag we include --ignore-unknown-flags temporarily too, for a few versions until a set time has passed. (Implementation would need have two parse operations if the ignore flag wasn't specified on the first parse, to make sure there really was no unknown flags, to be able to fail if there were)

@erezrokah
Copy link
Member Author

I can see if Cobra exposes the unknown flags

We need spf13/pflag#199, spf13/cobra#739 (comment)

@erezrokah
Copy link
Member Author

Maybe we can turn this around, by adding an --ignore-unknown-flags flag? Then each time the cli specifies a "known-new" flag we include --ignore-unknown-flags temporarily too, for a few versions until a set time has passed. (Implementation would need have two parse operations if the ignore flag wasn't specified on the first parse, to make sure there really was no unknown flags, to be able to fail if there were)

I like that idea but it needs to be an environment variable (it needs to be evaluated before parsing happens), so maybe when the CLI starts plugins it can pass IGNORE_UNKNOWN_FLAGS=true

@hermanschaaf
Copy link
Member

Yeah I think this is mostly an internal problem for us, less for our users.

@erezrokah why? Maybe I'm missing something. I know users don't typically run plugins directly, but I still think it's everyone's problem.

Let's say we added a new feature to the CLI to allowlist only connections to certain domains (to use a random example). If this is to be enforced by the plugin, it would need to be passed as a flag. With the change here, if users enabled this feature in the CLI, they would expect it to work, but actually it would not, if they are using an older version of a plugin.

@erezrokah
Copy link
Member Author

@erezrokah why? Maybe I'm missing something. I know users don't typically run plugins directly, but I still think it's everyone's problem.

Let's say we added a new feature to the CLI to allowlist only connections to certain domains (to use a random example). If this is to be enforced by the plugin, it would need to be passed as a flag. With the change here, if users enabled this feature in the CLI, they would expect it to work, but actually it would not, if they are using an older version of a plugin.

Ah, good point. @marianogappa and I discussed this problem via DMs as well. At the moment the CLI does not know which features plugins support. For example not all plugins support deterministic_cq_id (e.g. DB source plugins). Plugins that don't use the scheduler don't support otel_endpoint.

So maybe what we really need is a way for plugins to tell the CLI the features they support

@marianogappa
Copy link
Contributor

With the change here, if users enabled this feature in the CLI, they would expect it to work, but actually it would not, if they are using an older version of a plugin.

Even with a warning I think it's problematic. Older version of a plugin is one case, but misspelling is another, am I the only one who misspells a lot?

@disq
Copy link
Member

disq commented Sep 20, 2024

environment variable (it needs to be evaluated before parsing happens)

My idea was to parse everything twice, once with cobra.Unknown enabled, to detect the unknown flag, and then a second time... but I like this env var idea.

@disq
Copy link
Member

disq commented Sep 20, 2024

way for plugins to tell the CLI the features they support

Move most things to spec, then we can have a message through GRPC? Simplify serve to have only --address (or just a few more). Do you think initializing otel after the spec is parsed is acceptable?

Also this needs to be accomodated in other language SDKs as well, so moving more things into spec is beneficial from SDK maintenance PoV.

@erezrokah
Copy link
Member Author

Move most things to spec, then we can have a message through GRPC? Simplify serve to have only --address (or just a few more). Do you think initializing otel after the spec is parsed is acceptable?

Well if you init OTEL after spec is parsed, you're bound to miss some logs. But regardless plugins don't have access to top level spec, so we'd need to pass everything to the init gRPC call I think

@disq
Copy link
Member

disq commented Sep 20, 2024

Move most things to spec, then we can have a message through GRPC? Simplify serve to have only --address (or just a few more). Do you think initializing otel after the spec is parsed is acceptable?

Well if you init OTEL after spec is parsed, you're bound to miss some logs. But regardless plugins don't have access to top level spec, so we'd need to pass everything to the init gRPC call I think

Yes the options would be in the outer spec which gets passed into Init (or capability detection call first, then selectively to Init)

@erezrokah
Copy link
Member Author

OK going to close this since this warrants an offline discussion

@erezrokah erezrokah closed this Sep 20, 2024
@erezrokah erezrokah deleted the feat/allow_unknown_flags branch September 20, 2024 13:55
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.

4 participants