-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
CrateDB output plugin #3210
CrateDB output plugin #3210
Conversation
Not really needed here, but I want circleci to be happy :) https://circleci.com/gh/influxdata/telegraf/8149?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-build-link
Allows connecting without setting up auth stuff. Probably also a better idea for this in general.
Otherwise it passes on my machine, but not on circle-ci. See https://circleci.com/gh/influxdata/telegraf/8152?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-build-link
Thanks for the pull request @felixge, I'm pretty far behind on reviews, so it might take me a little while before I am able to review. One thing I notice though is that the plugin uses a different postgres library than the one we use in existing plugins, is it possible to switch to pgx? |
@danielnelson good idea, I didn't even notice pgx was used already, as I was just looking at other output plugins. That being said, unfortunately using pgx causes my tests to fail with the following error:
This is because pgx queries the postgres catalog when connecting, and CrateDB doesn't implement those catalog tables. As far as I can tell this feature cannot be disabled in pgx. So if possible, I'd like to keep using Cheers |
Thanks for opening the upstream issue. Lets try to get it resolved in pgx so we can avoid increasing the size of the Telegraf binary. In the meantime it makes sense to leave your pull request with pq in case anyone would like to do their own testing. |
@danielnelson yes, this is related to prepared statements. Prepared statements should always be used when trying to safely inject data into a SQL query. Unfortunately CrateDB doesn't support a certain variant of the Extended Query format (which is used for prepared statements):
CrateDB however doesn't determine the number of parameters by looking at the number of placeholders, but instead looks at the length of the array of parameter type OIDs. Pgx (and lib/pq) are not setting this array (as it's optional), causing CrateDB to always complain about too many parameters being given. Of course one can always try to inject the data by manually escaping it on the client site (which is what The only question is: Would you prefer to use the escaping/sanitize mechanism from pgx over the code in this PR? If yes, I'll try to change my code accordingly. But it will most likely require giving up on using the Please let me know how you'd like to proceed. I agree about the object literals. I've added good test coverage for that code to make sure it works. |
I guess using sanitize is not an option due to being internal, maybe in the future after pgx gains the ability to not use prepared statements we can update it. |
@danielegozzi yeah. I also think CrateDB will fix the problem preventing prepared statement support on their end at some point. That will be even better. Anyway, do you think we can move forward with this PR? If yes, are there any remaining improvements you'd like me to make? |
I'll try to do a closer review soon, shouldn't be a problem to finish this for 1.5. |
plugins/outputs/cratedb/cratedb.go
Outdated
// -> ERROR: SQLParseException: For input string: "14305102049502225714" | ||
|
||
cols := []interface{}{ | ||
int64(m.HashID()), |
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 hadn't considered the values of this hash to be part stable across versions, would it be a problem if this hash changed even if the series key (measurement name + tagset) did not?
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.
Np. I think a cryptographic hash function makes more sense for the use case (deduplication) anyway. Let me know if you think 626f653 works for you.
plugins/outputs/cratedb/cratedb.go
Outdated
|
||
cols := []interface{}{ | ||
int64(m.HashID()), | ||
m.Time().In(loc), |
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.
Why in local time, what about just sending all times in UTC?
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.
CrateDB converts to UTC anyway, but you're right, this actually makes things a bit simpler. e246032
{map[string]interface{}{}, `{}`}, | ||
{map[string]interface{}(nil), `{}`}, | ||
{map[string]interface{}{"foo": "bar"}, `{"foo" = 'bar'}`}, | ||
{map[string]interface{}{"foo": "bar", "one": "more"}, `{"foo" = 'bar', "one" = 'more'}`}, |
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.
Can you add some extra test cases for string escaping, here are some ideas:
map[string]interface{}{"fo"o": "b'ar", "ab'c": `xy"z`, `on"""e`: "mo'''re"}
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.
Makefile
Outdated
@@ -86,6 +86,12 @@ docker-run: | |||
-e SLAPD_CONFIG_ROOTPW="secret" \ | |||
-p "389:389" -p "636:636" \ | |||
-d cobaugh/openldap-alpine | |||
docker run \--name cratedb \ |
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.
Do we need to remove the backslash here? \--name
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.
plugins/outputs/cratedb/README.md
Outdated
|
||
## Table Schema | ||
|
||
The plugin requires a a table with the following schema. |
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.
Extra a
in this sentence
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.
@@ -0,0 +1,7 @@ | |||
version: "3" |
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.
What do we need the docker compose file for?
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 was using it for local testing. Shouldn't have checked it in. It's gone as of a54054f
I just used this for local testing.
CrateDB converts to UTC anyway, and this simplifies the code a bit.
@danielnelson Thanks for taking the time to review this PR. I've addressed all concerns you raised, please let me know if you'd like me to make any additional changes. For some reason some circleci tests failed:
But I think those are unrelated to my changes. |
I just merged master into this branch, and there is now an additional test failure:
That being said, the latest commit on master is also failing CircleCI right now, so I still think those failures are unrelated to this PR. |
I fixed the http_listener issue and it should pass now if you rebase. |
The test below failed on the previous run, but it seems unrelated to this PR. --- FAIL: TestRunTimeout (0.10s) <autogenerated>:1: Error Trace: internal_test.go:57 Error: Should be true FAIL FAIL github.com/influxdata/telegraf/internal 0.267s
@danielnelson I merged the latest changes from master into this PR and got b0d6723 to pass the circleci checks. Please let me know if this makes this PR mergeable or if you'd like to see some more improvements. |
@danielnelson thank you so much for taking the time to review and merge this PR. 🙏 |
Hello,
this PR implements an output plugin for CrateDB using their Postgres Wire Protocol.
Please let me know what kind of changes, if any, you'd like me to make in order to get this merged.
Many thanks in advance 😊
Felix
Required for all PRs: