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(output): add mongodb output plugin #9923

Merged
merged 29 commits into from
Oct 28, 2021
Merged

Conversation

bustedware
Copy link
Contributor

@bustedware bustedware commented Oct 13, 2021

Added an output plugin to gather metrics and output them to mongodb v5.0+ time series collections

@telegraf-tiger
Copy link
Contributor

Thanks so much for the pull request!
🤝 ✒️ Just a reminder that the CLA has not yet been signed, and we'll need it before merging. Please sign the CLA when you get a chance, then post a comment here saying !signed-cla

@bustedware
Copy link
Contributor Author

!signed-cla

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 @bustedware, thanks for this nice PR!
Please check if you can implement this plugin using the go.mongodb.org/mongo-driver driver instead of using the unmaintained library used now. I have some more comments in the code...

@srebhan srebhan self-assigned this Oct 14, 2021
@srebhan srebhan added area/mongodb new plugin plugin/output 1. Request for new output plugins 2. Issues/PRs that are related to out plugins labels Oct 14, 2021
bustedware and others added 3 commits October 14, 2021 07:15
Co-authored-by: Sven Rebhan <36194019+srebhan@users.noreply.github.com>
Co-authored-by: Thomas Casteleyn <thomas.casteleyn@me.com>
… member variable. fmt statements used previouslly for logging/debugging are now using log instead
…e plugin interface. refactored some additional variable names and modified README.md to reflect those names.
bustedware and others added 6 commits October 15, 2021 18:53
…. using testutil for test metrics in mongodb_test output test.
- MongoDBGetCollections is now member function
- removed TODO from Init()
- ctx now using Background() from Connect() method
- no longer storing context in struct
- removed errorneous comments and TODOs
Comment on lines 57 to 60
CAFile string `toml:"cafile"`
X509clientpem string `toml:"x509clientpem"`
X509clientpempwd string `toml:"x509clientpempwd"`
Allow_tls_insecure bool `toml:"allow_tls_insecure"`
Copy link
Member

Choose a reason for hiding this comment

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

Maybe you should add this option to TLSConfig then for other plugins to profit as well. Do you think this can be done?

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.

@bustedware, we are getting closer. Some more comments in the code. Please try to export as less as possible. Looking forward to the next round!

Comment on lines 34 to 39
// create time series collection when it doesn't exist
myTestMetricName := "testMetricName"
if !s.DoesCollectionExist(myTestMetricName) {
err = s.MongoDBCreateTimeSeriesCollection(myTestMetricName)
require.NoError(t, err)
}
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this be done by Write automatically?

Copy link
Contributor

Choose a reason for hiding this comment

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

This is a different test, should be in its own func.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct. Write does this automatically. I have added a lot more tests. Please let me know if the tests span enough cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

note that MongoDBCreateTimeSeriesCollection is no longer exported and is now named createTimeSeriesCollection. I think leaving Write to perform the testing of this specific functionality should be enough.

@Hipska Hipska self-assigned this Oct 18, 2021
bustedware and others added 4 commits October 25, 2021 17:17
…Dockerfile and mongodb.sh in mongodb output plugin
assign client only after checking err status.

Co-authored-by: Sven Rebhan <36194019+srebhan@users.noreply.github.com>
@bustedware bustedware requested review from Hipska and srebhan October 25, 2021 23:07
Copy link
Contributor

@Hipska Hipska left a comment

Choose a reason for hiding this comment

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

Great improvements, 2 small comments!

Comment on lines 165 to 166
serverSelectionTimeoutSeconds := int64(s.ServerSelectTimeout / 1000000000)
s.clientOptions = s.clientOptions.SetServerSelectionTimeout(time.Duration(serverSelectionTimeoutSeconds) * time.Second)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this conversion? s.ServerSelectTimeout is already a Duration type.

Copy link
Contributor Author

@bustedware bustedware Oct 26, 2021

Choose a reason for hiding this comment

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

invalid operation: mismatched types config.Duration and time.Duration - compiler MismatchedTypes. when I try:
s.clientOptions = s.clientOptions.SetServerSelectionTimeout(s.ServerSelectTimeout * time.Second)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

check slack thread for more details

fixed misleading error message regarding a missing username from configuration

Co-authored-by: Thomas Casteleyn <thomas.casteleyn@me.com>
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 @bustedware you nicely worked this trough with @Hipska. Good job! I only have some minor comments, the most severe is the handling of the timeout which already is a duration.

Can you also elaborate on what you use that PKI (certificates) for?

bustedware and others added 4 commits October 26, 2021 21:16
error checking added to ensure name of collection returned is of type string to prevent panic.
default value added for database option
default value added for granularity option
updated to use switch statement for metric granularity value checks
using HasPrefix to be explicit instead of Contains() for Dsn checks
updated to use err within local/in scope contexts of method calls
removed superfilous lines from NoAuth test for brevity and cleanliness

Co-authored-by: Sven Rebhan <36194019+srebhan@users.noreply.github.com>
…y now defaulted. removed return statement which will always be nil. golang fixed space formatting from previous commit suggestions
…ranularity setting. fixed mongodb.go to actually set the default values and not set the sample config. updated mongodb_test.go to pass new short test cases where config no longer requires database or granularity field to pass init
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.

This leaves us with the timeout/duration setting. :-)

verified and applied suggestion for invoking SetServerSelectionTimeout

Co-authored-by: Sven Rebhan <36194019+srebhan@users.noreply.github.com>
@bustedware bustedware requested a review from srebhan October 27, 2021 10:36
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 good to me. Thanks @bustedware for the nice PR and the constructive discussions!

@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 Oct 27, 2021
@telegraf-tiger
Copy link
Contributor

🥳 This pull request decreases the Telegraf binary size by -1.09 % for linux amd64 (new size: 130.7 MB, nightly size 132.1 MB)

📦 Looks like new artifacts were built from this PR.

Expand this list to get them here! 🐯

Artifact URLs

DEB RPM TAR GZ ZIP
amd64.deb aarch64.rpm darwin_amd64.tar.gz windows_amd64.zip
arm64.deb armel.rpm freebsd_amd64.tar.gz windows_i386.zip
armel.deb armv6hl.rpm freebsd_armv7.tar.gz
armhf.deb i386.rpm freebsd_i386.tar.gz
i386.deb ppc64le.rpm linux_amd64.tar.gz
mips.deb s390x.rpm linux_arm64.tar.gz
mipsel.deb x86_64.rpm linux_armel.tar.gz
ppc64el.deb linux_armhf.tar.gz
s390x.deb linux_i386.tar.gz
linux_mips.tar.gz
linux_mipsel.tar.gz
linux_ppc64le.tar.gz
linux_s390x.tar.gz
static_linux_amd64.tar.gz

@bustedware bustedware requested a review from Hipska October 28, 2021 00:58
Copy link
Contributor

@Hipska Hipska left a comment

Choose a reason for hiding this comment

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

Perfect! Nice collaboration 👏

@powersj powersj merged commit 7d6672c into influxdata:master Oct 28, 2021
@srebhan srebhan mentioned this pull request Nov 5, 2021
3 tasks
VladislavSenkevich pushed a commit to gwos/telegraf that referenced this pull request Nov 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/mongodb new 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