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
[Kafka output] Add config validation for topic and topics fields #38058
Conversation
f31c72b
to
de3d736
Compare
This pull request does not have a backport label.
To fixup this pull request, you need to add the backport labels for the needed
|
Pinging @elastic/elastic-agent (Team:Elastic-Agent) |
@@ -169,6 +175,20 @@ func (c *kafkaConfig) Validate() error { | |||
return fmt.Errorf("compression_level must be between 0 and 9") | |||
} | |||
} | |||
|
|||
if c.Topic == "" && len(c.Topics) == 0 { |
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.
Would it be possible to attempt to evaluate c.Topic
as a format string and log a warning if we think it is one?
That would help people figure out why their topic routing is failing. I don't think the %{
syntax is a valid topic name so the only way we'd get that is if someone is trying to use the Beat topic syntax with agent.
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.
The legal characters for a kafka topic is pretty small.
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.
The bits of code that used to convert the %{foo}
notation is deep within some helper from the outputs (outil.BuildSelectorFromConfig
) and it will return some errors that might not be what we want.
I could either search for %{
in the topic name and return an error or use a regexp validation with the characters Lee pointed. I prefer the latter and returning an error message stating the valid characters.
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.
Agreed just use the character set Lee linked and link back to that file in our code.
This pull request is now in conflicts. Could you fix it? 🙏
|
05f96f7
to
50738a1
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.
LGTM
This pull request is now in conflicts. Could you fix it? 🙏
|
This commit adds configuration validation for `topic` and `topics` fields from the Kafka output. Validation is performed for both cases: standalone Beat and running under Elastic-Agent. The latter does not support dynamic topics, hence setting `topics` is rejected by the validation.
This commit adds validation for the topic when running under Elastic-Agent. The topic is validates using a regexpt taken from the Kafka source code: https://github.com/apache/kafka/blob/a126e3a622f2b7142f3543b9dbee54b6412ba9d8/clients/src/main/java/org/apache/kafka/common/internals/Topic.java#L33
This commit adds a test case making explicity that topics containing the syntax `%{}` is not supported under Elastic-Agent
c24b4c3
to
e6280db
Compare
💚 Build Succeeded
cc @belimawr |
💔 Build Failed
Failed CI StepsHistory
cc @belimawr |
💔 Build Failed
Failed CI StepsHistory
cc @belimawr |
💚 Build Succeeded
History
cc @belimawr |
💚 Build Succeeded
History
cc @belimawr |
💔 Build Failed
Failed CI StepsHistory
cc @belimawr |
💔 Build Failed
Failed CI StepsHistory
cc @belimawr |
💚 Build Succeeded
History
cc @belimawr |
💚 Build Succeeded
History
cc @belimawr |
💚 Build Succeeded
cc @belimawr |
) This commit adds configuration validation for `topic` and `topics` fields from the Kafka output. Validation is performed for both cases: standalone Beat and running under Elastic-Agent. The latter does not support dynamic topics, hence setting `topics` is rejected by the validation. When running under Elastic-Agent the topic is validated using a regexpt taken from the Kafka source code: https://github.com/apache/kafka/blob/a126e3a622f2b7142f3543b9dbee54b6412ba9d8/clients/src/main/java/org/apache/kafka/common/internals/Topic.java#L33 (cherry picked from commit 8289144)
) (#38381) This commit adds configuration validation for `topic` and `topics` fields from the Kafka output. Validation is performed for both cases: standalone Beat and running under Elastic-Agent. The latter does not support dynamic topics, hence setting `topics` is rejected by the validation. When running under Elastic-Agent the topic is validated using a regexpt taken from the Kafka source code: https://github.com/apache/kafka/blob/a126e3a622f2b7142f3543b9dbee54b6412ba9d8/clients/src/main/java/org/apache/kafka/common/internals/Topic.java#L33 (cherry picked from commit 8289144) Co-authored-by: Tiago Queiroz <tiago.queiroz@elastic.co>
Proposed commit message
This commit adds configuration validation for
topic
andtopics
fields from the Kafka output. Validation is performed for both cases: standalone Beat and running under Elastic-Agent. The latter does not support dynamic topics, hence settingtopics
is rejected by the validation.Checklist
[ ] I have made corresponding changes to the documentation[ ] I have made corresponding change to the default configuration filesCHANGELOG.next.asciidoc
orCHANGELOG-developer.next.asciidoc
.## Author's ChecklistHow to test this PR locally
For both test cases first start a Kafka cluster (instructions below)
Standalone Beats (Filebeat):
Start Filebeat using the following configuration file
filebeat.yml
Validate that
is logged
Under Elastic-Agent
/tmp/flog.log
elastic-agent.yml
Validate you see an error log like:
Running a Kafka cluster
docker-compose.yml
provided below<YOUR LOCAL IP>
by your IP address (e.g:10.0.0.42
). Do not use a loopback addressdocker-compose up
http://localhost:9000/
) on your browser. You can use it to manage topics and look at the messages.docker-compose.yml
Tutorial on running a Kafka cluster with Docker: https://betterprogramming.pub/a-simple-apache-kafka-cluster-with-docker-kafdrop-and-python-cf45ab99e2b9
Related issues
## Use cases## Screenshots## Logs