-
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
Add ClickHouse input plugin #3894
Conversation
Will this plugin be released? |
) | ||
|
||
const sampleConfig = ` | ||
### ClickHouse DSN |
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.
Add two spaces before each of these.
It looks like it's good to go, apart from the update to |
Done! |
@kshvakov You will need to remove the
|
Godeps
Outdated
@@ -0,0 +1,97 @@ | |||
collectd.org 2ce144541b8903101fb8f1483cc0497a68798122 |
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.
Remove this file and use dep
@glinton I updated the dependencies. |
Hi @glinton! Would be great to have it in |
@glinton @danielnelson Is it possible by any chance to make this into |
Any chance this can be merged for the 1.10 release? |
``` | ||
# Read metrics from one or many ClickHouse servers | ||
[[inputs.clickhouse]] | ||
dsn = "native://localhost:9000?username=user&password=qwerty" |
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.
Recommend updating this to specify that a database reference is required. I built off of this branch and ran into some issues with getting the plugin to work without specifying a database, but didn't get an obvious error (either silent failure or driver: bad connection
). This might be obvious for people who are familiar with Clickhouse but I only maintain the TICK stack so it wasn't immediately obvious to me. I looked up the documentation here to figure out what else may have been needed, ended up just the DB name reference.
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'm not seeing this myself in testing, though I just have a small cluster and a user defined like:
<yandex>
<users>
<dbn>
<password>dbn</password>
<profile>default</profile>
<quota>default</quota>
<networks>
<ip>192.168.122.0/24</ip>
</networks>
</dbn>
</users>
</yandex>
I do notice I have a default_database set, perhaps it is related?
Hi! Any chances to merge this request by the summer?) |
Conflicts resolved |
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.
@kshvakov Thanks so much for the contribution and your patience, below is my review.
I do also have one question on the driver code, what is the purpose of this goroutine? We want to ensure that we don't need to devote resources to this plugin when it isn't being used, so we try to keep static initialization and especially static goroutine creation out of the dependencies.
@@ -224,6 +224,10 @@ | |||
source = "https://github.com/fsnotify/fsnotify/archive/v1.4.7.tar.gz" | |||
name = "gopkg.in/fsnotify.v1" | |||
|
|||
[[constraint]] | |||
branch = "master" |
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.
Use a version
constraint instead of a branch contraint.
``` | ||
# Read metrics from one or many ClickHouse servers | ||
[[inputs.clickhouse]] | ||
dsn = "native://localhost:9000?username=user&password=qwerty" |
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.
Is there a difference between using the native://
scheme and tcp://
? All documentation I have seen is using the tcp://
form so I suggest we switch over to avoid confusion setting up the DSN.
{ | ||
baseQuery.Del("alt_hosts") | ||
baseDSN.RawQuery = baseQuery.Encode() | ||
} |
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 is the significance of this scope { block }?
[[inputs.clickhouse]] | ||
dsn = "native://localhost:9000?username=user&password=qwerty" | ||
cluster = true # If a setting is "true" plugin tries to connect to all servers in the cluster (system.clusters) | ||
ignored_clusters = ["test_shard_localhost"] ## ignored cluster names |
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'm a little confused by this, but it probably has to do with my limited knowledge of Clickhouse. Can a clickhouse server be part of multiple clusters?
} | ||
conns := make([]*connect, 0, len(ch.clustersConn)) | ||
for _, conn := range ch.clustersConn { | ||
if err := conn.Ping(); err == nil { |
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 think we should remove the ping, if we can't reach the cluster server I think it should be an error in Gather. You would need to fix network connectivity, ignore the cluster, or switch off of cluster discovery mode.
if err := rows.Scan(&key, &value); err != nil { | ||
return err | ||
} | ||
fields[key] = value |
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.
We should snake_case the field keys, you can use internal.SnakeCase(key)
.
type ClickHouse struct { | ||
DSN string `toml:"dsn"` | ||
Cluster bool `toml:"cluster"` | ||
IgnoredClusters []string `toml:"ignored_clusters"` |
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'd like to add two options for this: cluster_include
and cluster_exclude
, then we can build a filter.IncludeExcludeFilter
and use it to control which clusters we collect. This just fits in with other plugins a bit more seamlessly.
return err | ||
} | ||
for _, conn := range conns { | ||
if err := ch.gather(conn, acc); err != nil { |
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.
Since each connection here is to a different server, I suggest we run a goroutine for each database and, of course, wait for them with a sync.WaitGroup before returning.
``` | ||
# Read metrics from one or many ClickHouse servers | ||
[[inputs.clickhouse]] | ||
dsn = "native://localhost:9000?username=user&password=qwerty" |
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'm not seeing this myself in testing, though I just have a small cluster and a user defined like:
<yandex>
<users>
<dbn>
<password>dbn</password>
<profile>default</profile>
<quota>default</quota>
<networks>
<ip>192.168.122.0/24</ip>
</networks>
</dbn>
</users>
</yandex>
I do notice I have a default_database set, perhaps it is related?
if len(conn.shardNum) != 0 { | ||
tags["shard_num"] = conn.shardNum | ||
} | ||
acc.AddFields("clickhouse_tables", |
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.
My understanding is that this metric is mergetree specific, and not just any table will appear here. With that in mind, perhaps a more descriptive name would be clickhouse_mergetree
or clickhouse_parts
?
I opened a new PR #6441 instead of this |
Required for all PRs: