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(outputs.mqtt): Add support for MQTT protocol version 5 #11284

Merged
merged 1 commit into from
Jul 27, 2022
Merged

feat(outputs.mqtt): Add support for MQTT protocol version 5 #11284

merged 1 commit into from
Jul 27, 2022

Conversation

cmackenzie1
Copy link
Contributor

@cmackenzie1 cmackenzie1 commented Jun 13, 2022

Required for all PRs:

Summary

By refactoring into versioned clients and adding github.com/eclipse/paho.golang, the MQTT output plugin can now support MQTT protocols 3.1.1 and 5, with the default remaining 3.1.1

Other notable changes:

  • The list of servers in the config can now be prefixed with a scheme (ie, mqtt:// or mqtts://), with the default being tcp:// if not present to maintain original behavior.
  • The write timeout is for protocol 5 client is done using context.WithTimeout.
  • MQTT config was reordered to group similar properties together and toml tags were added for all exported fields.

@telegraf-tiger telegraf-tiger bot added the feat Improvement on an existing feature such as adding a new setting/mode to an existing plugin label Jun 13, 2022
@cmackenzie1 cmackenzie1 changed the title feat(output.mqtt): github.com/eclipse/paho.mqtt.golang with githubcom/eclipse/paho.golang feat(output.mqtt): github.com/eclipse/paho.mqtt.golang with github.com/eclipse/paho.golang Jun 13, 2022
@srebhan srebhan changed the title feat(output.mqtt): github.com/eclipse/paho.mqtt.golang with github.com/eclipse/paho.golang feat(output.mqtt): Replace github.com/eclipse/paho.mqtt.golang with github.com/eclipse/paho.golang Jun 13, 2022
Copy link
Member

@srebhan srebhan left a comment

Choose a reason for hiding this comment

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

Looks mostly good. Thanks for your submission @cmackenzie1! I do have some small suggestions. Can you please take a look?

plugins/outputs/mqtt/mqtt.go Outdated Show resolved Hide resolved
plugins/outputs/mqtt/mqtt.go Outdated Show resolved Hide resolved
plugins/outputs/mqtt/mqtt.go Outdated Show resolved Hide resolved
plugins/outputs/mqtt/mqtt.go Outdated Show resolved Hide resolved
@srebhan srebhan self-assigned this Jun 13, 2022
@srebhan srebhan added area/mqtt plugin/output 1. Request for new output plugins 2. Issues/PRs that are related to out plugins labels Jun 13, 2022
@cmackenzie1
Copy link
Contributor Author

@srebhan upon digging into the paho.golang client code, I see they mention v3 protocol but explicitly set it to v5. https://github.com/eclipse/paho.golang/blob/master/paho/client.go#L211-L212

Thoughts on using both the new and old libraries and adding a field Procotol string to the MQTT struct?

@srebhan
Copy link
Member

srebhan commented Jun 14, 2022

@cmackenzie1 do you know if the paho guys are planning to support both in one library? The setting might be an oversight or something...

If this is not an issue they want to fix, we should indeed look into supporting both libraries with a Protocol user-setting as a last resort. ;-)

@cmackenzie1
Copy link
Contributor Author

@srebhan - just created eclipse-paho/paho.golang#89 to see what the status is. There is no clear answer in the docs from what I can tell.

@MattBrittan
Copy link

Note that the v5 package does not yet support persistence (this negates the point of QOS1/2).

As per the response on the issue raised on paho.golang there is no current plan to support MQTT 3.11.

@srebhan
Copy link
Member

srebhan commented Jun 22, 2022

@cmackenzie1 so you need to go with both versions then?

@cmackenzie1
Copy link
Contributor Author

@srebhan I think so. I'll try and work on the PR this week during my downtime.

@srebhan
Copy link
Member

srebhan commented Jul 12, 2022

@cmackenzie1 any update on this PR?

@cmackenzie1
Copy link
Contributor Author

Apologies @srebhan - I've been on a mix of vacation and being sick. Did you want me to close the PR for now until I get some time to work on it?

@cmackenzie1
Copy link
Contributor Author

@srebhan I managed to get some time this afternoon to work on the change to support multiple clients. Ready for a review at your leisure!

@cmackenzie1 cmackenzie1 changed the title feat(output.mqtt): Replace github.com/eclipse/paho.mqtt.golang with github.com/eclipse/paho.golang feat(output.mqtt): Add support for MQTT protocol version 5 Jul 14, 2022
Copy link
Member

@srebhan srebhan left a comment

Choose a reason for hiding this comment

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

Thanks for taking time to update this PR @cmackenzie1! I didn't mean to urge your with this, I just wanted to make sure this PR is not forgotten. :-)
The code looks nice and clean. Just some minor comments. One thing that would be nice is if you can add an integration test for version 5 similar to what is there for v3 as I think this is not covered currently....

go.mod Outdated Show resolved Hide resolved
plugins/outputs/mqtt/README.md Outdated Show resolved Hide resolved
plugins/outputs/mqtt/sample.conf Outdated Show resolved Hide resolved
plugins/outputs/mqtt/mqtt.go Outdated Show resolved Hide resolved
plugins/outputs/mqtt/mqtt.go Outdated Show resolved Hide resolved
plugins/outputs/mqtt/mqtt_v3.go Outdated Show resolved Hide resolved
plugins/outputs/mqtt/mqtt_v5.go Outdated Show resolved Hide resolved
@cmackenzie1
Copy link
Contributor Author

@srebhan no worries, I addressed those comments and even switched the test docker image over to use the official image from Eclipse.

Copy link
Member

@srebhan srebhan left a comment

Choose a reason for hiding this comment

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

That looks very good @cmackenzie1. Thanks for your quick update. I only have one more comment regarding your tests. I suggest to put the server configuration to a file and ship it instead of temporary file creation. That will save a lot of trouble and code. :-)

plugins/outputs/mqtt/mqtt_test.go Outdated Show resolved Hide resolved
@srebhan
Copy link
Member

srebhan commented Jul 20, 2022

Oh and please rebase to latest master as something strange happend to the CI tests. I'm pretty sure that you need to add github.com/eclipse/paho.golang to docs/LICENSE_OF_DEPENDENCIES.md. You can check locally by running make check-deps...

@cmackenzie1
Copy link
Contributor Author

Rebased, updated to include a testdata file with mosquitto.conf, and added the dependency docs/LICENSE_OF_DEPENDENCIES.md.!

@srebhan
Copy link
Member

srebhan commented Jul 21, 2022

@cmackenzie1 it also seems like you need to run make tidy to make the checks happy.

@cmackenzie1
Copy link
Contributor Author

@srebhan
Copy link
Member

srebhan commented Jul 21, 2022

Yeah go mod is picky... :-) Can you please also take a look at the other comments?

@cmackenzie1
Copy link
Contributor Author

@srebhan I think I addressed them already, unless they are still in "pending" on your end.

@srebhan
Copy link
Member

srebhan commented Jul 22, 2022

Oh boy, forgot to submit my review.... ;-)

Copy link
Member

@srebhan srebhan left a comment

Choose a reason for hiding this comment

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

Hey @cmackenzie1, sorry forgot to submit the review... Just two more comments for the test-cases and we are good to go from my side...

plugins/outputs/mqtt/mqtt_test.go Outdated Show resolved Hide resolved
plugins/outputs/mqtt/mqtt_test.go Outdated Show resolved Hide resolved
By refactoring into versioned clients and adding `github.com/eclipse/paho.golang`, the MQTT output plugin can now support MQTT protocols `3.1.1` and `5`, with the default remaining `3.1.1`

Other notable changes:
- The list of servers in the config can now be prefixed with a scheme (ie, `mqtt://` or `mqtts://`), with the default being `tcp://` if not present to maintain original behavior.
- The write timeout is for protocol `5` client is done using `context.WithTimeout`.
- `MQTT` config was reordered to group similar properties together and `toml` tags were added for all exported fields.
- `MQTT` integration tests were switched to the official [`eclipse-mosquitto`](https://hub.docker.com/_/eclipse-mosquitto) docker image
@cmackenzie1
Copy link
Contributor Author

@srebhan no worries! I addressed those two comments and rebased onto the latest master.

Copy link
Member

@srebhan srebhan left a comment

Choose a reason for hiding this comment

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

Perfect. Thank you @cmackenzie1 for all your effort!

@srebhan srebhan added the ready for final review This pull request has been reviewed and/or tested by multiple users and is ready for a final review. label Jul 27, 2022
@srebhan srebhan changed the title feat(output.mqtt): Add support for MQTT protocol version 5 feat(outputs.mqtt): Add support for MQTT protocol version 5 Jul 27, 2022
Copy link
Contributor

@MyaLongmire MyaLongmire left a comment

Choose a reason for hiding this comment

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

Thank you so much for adding this!

@MyaLongmire MyaLongmire merged commit af43d01 into influxdata:master Jul 27, 2022
@cmackenzie1 cmackenzie1 deleted the cole/mqtt-protocol-version branch July 27, 2022 15:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/mqtt feat Improvement on an existing feature such as adding a new setting/mode to an existing plugin plugin/output 1. Request for new output plugins 2. Issues/PRs that are related to out plugins ready for final review This pull request has been reviewed and/or tested by multiple users and is ready for a final review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants