Skip to content

feat(new source): Initial MQTT Source, #19931 #22752

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

Merged
merged 24 commits into from
May 14, 2025

Conversation

StormStake
Copy link
Contributor

Summary

The base for this PR is #19931, I have put some work into de-duplicating the code between the MQTT source and sink, I also made a few changes to update some of the older documentation to get it to pass tests. I tried to make as few changes to the overall logic of the source/sink as I could while refactoring but I do need some review and guidance on how the source looks now.

I tried to work on some of the unresolved comments from the original PR but I would like a fresh review so that I can work on anything remaining that the source needs to get merged. Feel free to provide any advice on what I have done, I only really have an okay understanding of Rust and not much in the way of knowledge of Vector's internals but I am prepared to learn if that is needed to get this merged.

Change Type

  • Bug fix
  • New feature
  • Non-functional (chore, refactoring, docs)
  • Performance

Is this a breaking change?

  • Yes
  • No

How did you test this PR?

I used Vector's builtin MQTT sink and the Eclipse Mosquitto MQTT broker along the mosquitto_sub and mosquitto_pub commands provided by Mosquitto to test base functionality. I used the configuration defaults for the mosquitto broker, (No authentication, No TLS, localhost:1883)

Vector MQTT source configuration

[sources.mqtt]
type = "mqtt"
host = "localhost"
topic = "testvectortopic"

[sinks.stdout]
inputs = ["mqtt"]
type = "console"
encoding.codec = "json"

Does this PR include user facing changes?

  • Yes. Please add a changelog fragment based on our guidelines.
  • No. A maintainer will apply the "no-changelog" label to this PR.

Checklist

  • Please read our Vector contributor resources.
    • make check-all is a good command to run locally. This check is
      defined here. Some of these
      checks might not be relevant to your PR. For Rust changes, at the very least you should run:
      • cargo fmt --all
      • cargo clippy --workspace --all-targets -- -D warnings
      • cargo nextest run --workspace (alternatively, you can run cargo test --all)
  • If this PR introduces changes Vector dependencies (modifies Cargo.lock), please
    run dd-rust-license-tool write to regenerate the license inventory and commit the changes (if any). More details here.

References

@StormStake StormStake requested review from a team as code owners March 30, 2025 23:11
@github-actions github-actions bot added domain: sources Anything related to the Vector's sources domain: sinks Anything related to the Vector's sinks domain: ci Anything related to Vector's CI environment domain: external docs Anything related to Vector's external, public documentation labels Mar 30, 2025
@pront pront self-assigned this Mar 31, 2025
@pront
Copy link
Member

pront commented Mar 31, 2025

Thank you @StormStake! I will take a look.

@rtrieu rtrieu self-assigned this Mar 31, 2025
@ahsandar
Copy link

is it due to release in upcoming version ?

Copy link
Member

@pront pront left a comment

Choose a reason for hiding this comment

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

This looks great. We can release it as a beta component and see if any issues come up.

@pront
Copy link
Member

pront commented Apr 18, 2025

is it due to release in upcoming version ?

Looks likely based on the current state of the PR.

@StormStake
Copy link
Contributor Author

I noticed that, from what I can tell you can't get what topic the message was sent to from the log event in this version of the source. In my head I think that is pretty fundamental for this type of application, so I think it would make sense to have it added on first release. But I don't really work with MQTT data, so I could be wrong. Otherwise it could always be added in future releases.

Does this look like it's headed in the right
direction for adding that metadata? Or is there a simpler way to manage this?

https://github.com/StormStake/vector/blob/e09bb91a2637be153d888a08fa37b0c08514ce74/src/sources/mqtt/source.rs#L85-L111

Copy link
Member

@pront pront left a comment

Choose a reason for hiding this comment

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

Thanks @StormStake!

@pront
Copy link
Member

pront commented Apr 25, 2025

I noticed that, from what I can tell you can't get what topic the message was sent to from the log event in this version of the source. In my head I think that is pretty fundamental for this type of application, so I think it would make sense to have it added on first release. But I don't really work with MQTT data, so I could be wrong. Otherwise it could always be added in future releases.

Does this look like it's headed in the right direction for adding that metadata? Or is there a simpler way to manage this?

https://github.com/StormStake/vector/blob/e09bb91a2637be153d888a08fa37b0c08514ce74/src/sources/mqtt/source.rs#L85-L111

Yeah, let's add a topic field. We can draw inspiration from other sources:
https://github.com/vectordotdev/vector/blob/master/src/sources/kafka.rs#L361-L416

@pront pront enabled auto-merge May 14, 2025 16:59
@pront pront added this pull request to the merge queue May 14, 2025
Merged via the queue into vectordotdev:master with commit a39d60a May 14, 2025
42 checks passed
@pront
Copy link
Member

pront commented May 14, 2025

Happy to see this merged, thanks all!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain: ci Anything related to Vector's CI environment domain: external docs Anything related to Vector's external, public documentation domain: sinks Anything related to the Vector's sinks domain: sources Anything related to the Vector's sources
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New mqtt source
5 participants