-
Notifications
You must be signed in to change notification settings - Fork 154
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
Support for validate subcommand for otel configuration #4023
Conversation
Pinging @elastic/elastic-agent (Team:Elastic-Agent) |
Pinging @elastic/elastic-agent-control-plane (Team:Elastic-Agent-Control-Plane) |
UT for logic not for boilerplate results in low soundqube rating |
With this PR, we are adding a top-level sub-command to the Agent, so users will execute I really think we need to implement #3903 first and move this |
@@ -0,0 +1,301 @@ | |||
###################### Agent Configuration Example ######################### |
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.
WDYT about removing all the comments from this file, so this file also becomes more like the otel.yml
file? Just thinking that the comments are not adding much value to test fixture files.
With this PR, the syntax for running OTel configuration validation becomes To ease migration, I think we'd want Agent (with embedded OTel Collector) to be as much of a drop-in replacement for the vanilla OTel collector. So I think we need to support the same syntax, that is, something like |
once i introduce otel subcommand i will move this under otel subcommand and add multiple files and other flags. for now i prefer to stay with flags we have and not support multiple files using --config as normal agent does not understand that. the order in my mind is |
Co-authored-by: Shaunak Kashyap <ycombinator@gmail.com>
I built Agent with this PR, extracted it into a folder, and ran
There is no
And there is actually an
|
elastic-agent.yml is a default config value if not provided by |
…t into otel/validate
fixed |
internal/pkg/agent/cmd/validate.go
Outdated
if runAsOtel := otel.IsOtelConfig(ctx, cfgFile); !runAsOtel { | ||
return fmt.Errorf("%q is not an otel config. file should be named 'otel.yml', 'otlp.yml' or 'otelcol.yml'", cfgFile) | ||
} |
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.
After this PR is merged but before we change elastic-agent validate
to elastic-agent otel validate
, the user experience would be that elastic-agent validate
only works for OTel configurations. To me, this is a bit awkward as validate
is a top-level sub-command and, therefore, suggests that it can validate both OTel and Agent configurations.
So my suggestion for this PR would be to return early from this function with nil
if otel.IsOtelConfig(ctx, cfgFile)
returns false
and also make DefaultConfigName
the default value for the -c/--config
global CLI options.
Once we have the follow up PR to move elastic-agent validate
to elastic-agent otel validate
, it would make sense to error out if otel.IsOtelConfig(ctx, cfgFile)
returns false.
Co-authored-by: Shaunak Kashyap <ycombinator@gmail.com>
It would be really nice to see this do a simple validation of the |
@michalpristas should we put this back on draft for now? |
@pierrehilbert after |
If I run As comparison, if I run the OTel Collector binary's $ ./bin/otelcorecol_darwin_arm64 validate
Error: at least one config flag must be provided
2024/02/02 04:18:29 collector server run finished with error: at least one config flag must be provided Would it be possible to mimic the OTel Collector binary's behavior in |
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.
Apart from my request/suggestion in #4023 (comment), which I would say is a nice to have, this PR LGTM.
testing/integration/otel_test.go
Outdated
@@ -133,6 +133,11 @@ func TestOtelFileProcessing(t *testing.T) { | |||
`"stringValue":"system.log"`, // system.log is being processed | |||
}) | |||
|
|||
// check `elastic-agent otel validate` command works for otel config | |||
out, err := fixture.Exec(ctx, []string{"otel", "validate", "--config", cfgFilePath}) |
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.
I would like to see a test (here or elsewhere) that the validate command actually detects errors in otel configuration files.
That is the real value of the validate command, lets make sure it works. This test would pass even if we never called the otel validate function and just parsed the command line arguments.
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 now addressed at e432f98
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.
i pulled it outside into separate function for readability but kept within same test to spare some resources
|
LGTM, fine to force merge this. Will wait until Michal is back online before doing so. |
performs validation of config passed to the command using flags supported also in
otel
subcommand (--config
and--set
)