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

Add --opamp-config flag #1230

Merged
merged 5 commits into from
Oct 10, 2023
Merged

Add --opamp-config flag #1230

merged 5 commits into from
Oct 10, 2023

Conversation

echlebek
Copy link
Collaborator

The --opamp-config flag is used to specify an OpAmp configuration file. The file will be updated according to the OpAmp server's remote management directives.

Since this method of configuration is so different from the configuration expressed by the --config flag, --opamp-config and --config cannot be combined.

This change marks the second time it was necessary to patch main.go, and so I've created an adhoc patch queue by prefixing patches with numbers that indicate the order the patches should be applied in.

This change is part of an epic to add OpAmp remote management to otelcol-sumo: https://sumologic.atlassian.net/browse/SUMO-206529

Manual testing performed:

  • collector runs with --config (against the example configuration in upstream's repo)
  • collector runs with --op-amp config and reports a not-implemented error
  • collector refuses to run with both --config and --op-amp config and cites a configuration error

@echlebek echlebek requested a review from a team as a code owner August 24, 2023 21:58
@github-actions github-actions bot added documentation Improvements or additions to documentation go labels Aug 24, 2023
@echlebek echlebek marked this pull request as draft August 24, 2023 22:00
@echlebek echlebek force-pushed the echlebek/add-opamp-config-flag branch from 965f9f4 to 0cb76bb Compare August 25, 2023 19:51
@echlebek echlebek marked this pull request as ready for review August 25, 2023 20:27
@echlebek
Copy link
Collaborator Author

This PR is ready for review, despite the complaints of one of the linters (it is wrong).

@echlebek echlebek force-pushed the echlebek/add-opamp-config-flag branch from bbb2c18 to f169398 Compare August 29, 2023 01:35
@sumo-drosiek
Copy link
Contributor

We should have in-code tests for that feature. Is there any plan for opamp e2e tests or unit tests?

Copy link

@swiatekm swiatekm left a comment

Choose a reason for hiding this comment

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

Some structural comments, LGTM otherwise.


func runInteractive(params otelcol.CollectorSettings) error {
cmd := otelcol.NewCommand(params)
+ cmd.Flags().StringVarP(&opAmpConfig, "opamp-config", "", "", "path to opamp config file")
Copy link

Choose a reason for hiding this comment

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

Is this necessary? You're fetching the flag value via flagset.Lookup anyway, so you don't need to explicitly bind it to a variable. And if we delete this line, we can also drop the second patch file completely, simplifying the setup.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You made me do a double take here so I went back and tested. It's necessary! Without this line, the flag is never registered in the flag set, doesn't appear in the --help docs, and will be rejected by the flag parser if you try to use it.

Choose a reason for hiding this comment

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

I was thinking of defining the flag directly on the flagset in UseCustomConfigProvider, before parsing command line arguments. Sorry for not being clear about that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@swiatekm-sumo Sorry, I still don't understand how this suggestion is supposed to work. My understanding is that the flagset defined in UseCustomConfigProvider is a distinct flagset from what the otel collector is actually using. So even if a flag is added in this scope, it won't be usable.

https://github.com/SumoLogic/sumologic-otel-collector/blob/main/otelcolbuilder/cmd/configprovider.go#L51

Discarding the output of the flagset here seems to indicate that this was an intentional design choice and that we expect the original otel flagset to be used still. Am I missing something?

I did try to add a flag in this context, but since the entry point of the program still uses the otel flag parser, it isn't recognized or displayed in the help output of the program.

Copy link

@swiatekm swiatekm Sep 29, 2023

Choose a reason for hiding this comment

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

Yeah, you're right about that. There isn't really a way to simply add a flag to the flagset used by the upstream collector. The current setup was born of a need to add our own configprovider, which unfortunately required parsing flags for config locations. So what happens is we define our own flagset to get these locations, but ignore parse errors and just let the upstream flag parsing logic take care of them. The thought behind this was that we should try to be maximally compatible with the upstream flags.

However, since we're adding a new flag here and want to handle it properly, including help text and error messages, we either need to bite the bullet and bubble-up errors from our own flagset, or do what you've done originally and define the new flag separately.

Thing is, now that I look at it again, your original solution really shouldn't work, or at least the validation shouldn't. You're adding that flag to the upstream flagset, but use our custom flagset for validation. So it should always come up empty when you do a Lookup on it.

The cleanest solution to this problem is probably to just make our own flagset authoritative and add the flag there.

Sorry for the confusion.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Please try running the collector with --opamp-config defined. You will see that it fails with the not implemented error here: https://github.com/SumoLogic/sumologic-otel-collector/pull/1230/files#diff-ebc450ec46371fd0d3aa5c5e35bdbc4d41ccb7c5b2837b4a9b6e8be4bbf2a9d1R121

Copy link

Choose a reason for hiding this comment

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

Okay, I think the current state is the best we can do without redoing the whole command parsing logic. In that case, I'd like to make it clear via comments why the flags are defined this way:

Suggested change
+ cmd.Flags().StringVarP(&opAmpConfig, "opamp-config", "", "", "path to opamp config file")
+ // this flag is only defined here so it shows up in the help text
+ cmd.Flags().StringVarP(&opAmpConfig, "opamp-config", "", "", "path to opamp config file")

Also, is there a reason we can't move this change to the existing patch file? Why do they need to be separate?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Happy to add that comment. I won't commit the suggestion as that would result in a malformed patch but I'm happy to redo that patch.

I think it's best to keep patches as small as possible, even if that results in a greater number of them, as it's generally easier to deal with small patches against an upstream project. I've maintained a project against an upstream with several dozen patches and my experience has been that large patches are generally more difficult to work with overall.

Copy link

Choose a reason for hiding this comment

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

If you feel strongly about keeping it in two patch files, I don't mind. In all honesty, we should propose being able to customize the templates otelcolbuilder uses upstream to avoid the patching. Or just drop the builder altogether and maintain this bootstrap code ourselves.

otelcolbuilder/cmd/configprovider.go Outdated Show resolved Hide resolved
@echlebek
Copy link
Collaborator Author

@sumo-drosiek We had a lot of uncertainty around the implementation details of this feature so I filed this PR with unimplemented functionality. There will be a followup PR that is more "meat and potatoes" with tests. I filed this PR mostly to see if people would be OK with the way I handled the patching.

@swiatekm swiatekm self-requested a review October 9, 2023 09:33
@echlebek
Copy link
Collaborator Author

Thanks for your patience on this one, @swiatekm-sumo

The --opamp-config flag is used to specify an OpAmp configuration file.
The file will be updated according to the OpAmp server's remote
management directives.

Since this method of configuration is so different from the
configuration expressed by the --config flag, --opamp-config and
--config cannot be combined.

This change marks the second time it was necessary to patch main.go, and
so I've created an adhoc patch queue by prefixing patches with numbers
that indicate the order the patches should be applied in.

Signed-off-by: Eric Chlebek <[email protected]>
Signed-off-by: Eric Chlebek <[email protected]>
@echlebek echlebek force-pushed the echlebek/add-opamp-config-flag branch from 748e91e to 9cd0c37 Compare October 10, 2023 19:04
@echlebek echlebek merged commit 2744fef into main Oct 10, 2023
@echlebek echlebek deleted the echlebek/add-opamp-config-flag branch October 10, 2023 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation go
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants