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

Add ClickHouse input plugin #3894

Closed
wants to merge 10 commits into from
Closed

Conversation

kshvakov
Copy link

Required for all PRs:

  • Signed CLA.
  • Associated README.md updated.
  • Has appropriate unit tests.

@russorat russorat removed the triage label Mar 22, 2018
@subuk
Copy link
Contributor

subuk commented Aug 23, 2018

Will this plugin be released?

)

const sampleConfig = `
### ClickHouse DSN
Copy link
Contributor

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.

@glinton
Copy link
Contributor

glinton commented Aug 23, 2018

It looks like it's good to go, apart from the update to dep. Update the branch with our master and fix address this small change.

@kshvakov
Copy link
Author

Done!

@glinton
Copy link
Contributor

glinton commented Sep 4, 2018

@kshvakov You will need to remove the Godeps file and add your dependency with dep.

dep ensure -add github.com/[dependency]/[new-package]

Godeps Outdated
@@ -0,0 +1,97 @@
collectd.org 2ce144541b8903101fb8f1483cc0497a68798122
Copy link
Contributor

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

@kshvakov
Copy link
Author

kshvakov commented Sep 5, 2018

@glinton I updated the dependencies.

@alkersan
Copy link

Hi @glinton! Would be great to have it in 1.8. Is it possible?

@captify-daleksandrov
Copy link

@glinton @danielnelson Is it possible by any chance to make this into 1.9?

@danielnelson danielnelson added this to the 1.10.0 milestone Nov 6, 2018
@russorat russorat modified the milestones: 1.10.0, 1.11.0 Jan 14, 2019
@cedwardstesla
Copy link

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"

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.

Copy link
Contributor

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?

@alyarskiy
Copy link

Hi! Any chances to merge this request by the summer?)

@kshvakov
Copy link
Author

Conflicts resolved

@danielnelson danielnelson modified the milestones: 1.11.0, 1.12.0 May 24, 2019
Copy link
Contributor

@danielnelson danielnelson left a 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"
Copy link
Contributor

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"
Copy link
Contributor

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()
}
Copy link
Contributor

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
Copy link
Contributor

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 {
Copy link
Contributor

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
Copy link
Contributor

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"`
Copy link
Contributor

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 {
Copy link
Contributor

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"
Copy link
Contributor

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",
Copy link
Contributor

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?

@danielnelson danielnelson removed this from the 1.12.0 milestone Aug 5, 2019
@kshvakov
Copy link
Author

I opened a new PR #6441 instead of this

@kshvakov kshvakov closed this Sep 25, 2019
@kshvakov
Copy link
Author

@glinton @danielnelson

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants