logstash-output-clickhouse 0.1.3 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +3 -0
- data/lib/logstash/outputs/clickhouse.rb +17 -44
- data/logstash-output-clickhouse.gemspec +1 -1
- metadata +2 -3
- data/lib/logstash/util/shortname_resolver.rb +0 -40
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 34905df0e9293b2ff6471b904e018e8fe3d2d2f1bc372196422d5fa30107d50e
|
4
|
+
data.tar.gz: a20ec2301377b218b8395f6664be86f4b978e6ad72c42280fa2bfc0c889c0569
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ccbd71994f6b705088616315a3340312381fce0ccae1dc4f97b793d417041d987ede5962c6f256111d6a78620bed275997153c9fa37bc86ca4770c4642469726
|
7
|
+
data.tar.gz: e0b00ed0a0b0f1e8a664698cd0c1258d48d67bf872afe983b26d9134ddead047852bfecebaa7d9fa7668400c94de76d0e1bd1475b074f11308d0b87a7f3a6284
|
data/README.md
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
# Logstash Plugin
|
2
|
+
[](https://badge.fury.io/rb/logstash-output-clickhouse)
|
3
|
+
|
4
|
+
This repo forked from [here](https://github.com/funcmike/logstash-output-clickhouse).
|
2
5
|
|
3
6
|
This plugin is a modified version of the Lucidworks logstash json_batch. That plugin is available [here](https://github.com/lucidworks/logstash-output-json_batch).
|
4
7
|
|
@@ -2,7 +2,6 @@
|
|
2
2
|
require "logstash/outputs/base"
|
3
3
|
require "logstash/namespace"
|
4
4
|
require "logstash/json"
|
5
|
-
require "logstash/util/shortname_resolver"
|
6
5
|
require "uri"
|
7
6
|
require "stud/buffer"
|
8
7
|
require "logstash/plugin_mixins/http_client"
|
@@ -59,7 +58,6 @@ class LogStash::Outputs::ClickHouse < LogStash::Outputs::Base
|
|
59
58
|
:idle_flush_time => @idle_flush_time,
|
60
59
|
:request_tokens => @pool_max,
|
61
60
|
:http_hosts => @http_hosts,
|
62
|
-
:http_query => @http_query,
|
63
61
|
:headers => request_headers)
|
64
62
|
end
|
65
63
|
|
@@ -75,12 +73,7 @@ class LogStash::Outputs::ClickHouse < LogStash::Outputs::Base
|
|
75
73
|
@pool_max.times { |t| @request_tokens << true }
|
76
74
|
@requests = Array.new
|
77
75
|
|
78
|
-
|
79
|
-
@http_query = "?#{URI.encode_www_form(params)}"
|
80
|
-
|
81
|
-
@hostnames_pool =
|
82
|
-
parse_http_hosts(http_hosts,
|
83
|
-
ShortNameResolver.new(ttl: @host_resolve_ttl_sec, logger: @logger))
|
76
|
+
@table_name = table
|
84
77
|
|
85
78
|
buffer_initialize(
|
86
79
|
:max_items => @flush_size,
|
@@ -91,42 +84,18 @@ class LogStash::Outputs::ClickHouse < LogStash::Outputs::Base
|
|
91
84
|
print_plugin_info()
|
92
85
|
end # def register
|
93
86
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
ip_re = /^[\d]+\.[\d]+\.[\d]+\.[\d]+$/
|
98
|
-
|
99
|
-
lambda {
|
100
|
-
hosts.flat_map { |h|
|
101
|
-
scheme = URI(h).scheme
|
102
|
-
host = URI(h).host
|
103
|
-
port = URI(h).port
|
104
|
-
path = URI(h).path
|
105
|
-
|
106
|
-
if ip_re !~ host
|
107
|
-
resolver.get_addresses(host).map { |ip|
|
108
|
-
"#{scheme}://#{ip}:#{port}#{path}"
|
109
|
-
}
|
110
|
-
else
|
111
|
-
[h]
|
112
|
-
end
|
113
|
-
}
|
114
|
-
}
|
87
|
+
# This module currently does not support parallel requests as that would circumvent the batching
|
88
|
+
def receive(event)
|
89
|
+
buffer_receive(event)
|
115
90
|
end
|
116
91
|
|
117
|
-
|
118
|
-
|
119
|
-
def get_host_addresses()
|
120
|
-
begin
|
121
|
-
@hostnames_pool.call
|
122
|
-
rescue Exception => ex
|
123
|
-
@logger.error("Error while resolving host", :error => ex.to_s)
|
124
|
-
end
|
92
|
+
def generate_table_name(event)
|
93
|
+
event.sprintf(@table_name)
|
125
94
|
end
|
126
95
|
|
127
|
-
|
128
|
-
|
129
|
-
|
96
|
+
def generate_http_query(table_name)
|
97
|
+
params = { "query" => "INSERT INTO #{table_name} FORMAT JSONEachRow" }.merge(@extra_params)
|
98
|
+
return "?#{URI.encode_www_form(params)}"
|
130
99
|
end
|
131
100
|
|
132
101
|
def mutate(src)
|
@@ -153,15 +122,19 @@ class LogStash::Outputs::ClickHouse < LogStash::Outputs::Base
|
|
153
122
|
public
|
154
123
|
|
155
124
|
def flush(events, close = false)
|
156
|
-
documents =
|
125
|
+
documents = {}
|
157
126
|
|
158
127
|
events.each do |event|
|
159
|
-
|
128
|
+
table_name = generate_table_name(event)
|
129
|
+
documents[table_name] ||= ""
|
130
|
+
documents[table_name] << LogStash::Json.dump(mutate(event.to_hash())) << "\n"
|
160
131
|
end
|
161
132
|
|
162
|
-
hosts =
|
133
|
+
hosts = @http_hosts.clone
|
163
134
|
|
164
|
-
|
135
|
+
documents.each do |table_name, document|
|
136
|
+
make_request(document, hosts, generate_http_query(table_name), 1, 1, hosts.sample)
|
137
|
+
end
|
165
138
|
end
|
166
139
|
|
167
140
|
private
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "logstash-output-clickhouse"
|
3
|
-
s.version = "0.1.
|
3
|
+
s.version = "0.1.5"
|
4
4
|
s.licenses = ["Apache-2.0"]
|
5
5
|
s.summary = "This output lets you `POST` messages as JSON in a batched fashion to ClickHouse HTTP endpoint"
|
6
6
|
s.description = "This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logstash-output-clickhouse
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kmajk
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2023-05-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: logstash-core-plugin-api
|
@@ -125,7 +125,6 @@ files:
|
|
125
125
|
- LICENSE
|
126
126
|
- README.md
|
127
127
|
- lib/logstash/outputs/clickhouse.rb
|
128
|
-
- lib/logstash/util/shortname_resolver.rb
|
129
128
|
- logstash-output-clickhouse.gemspec
|
130
129
|
homepage: https://github.com/maltoze/logstash-output-clickhouse
|
131
130
|
licenses:
|
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'resolv'
|
2
|
-
require 'mini_cache'
|
3
|
-
|
4
|
-
class ShortNameResolver
|
5
|
-
def initialize(ttl:, logger:)
|
6
|
-
@ttl = ttl
|
7
|
-
@store = MiniCache::Store.new
|
8
|
-
@logger = logger
|
9
|
-
end
|
10
|
-
|
11
|
-
private
|
12
|
-
def resolve_cached(shortname)
|
13
|
-
@store.get_or_set(shortname) do
|
14
|
-
addresses = resolve(shortname)
|
15
|
-
raise "Bad shortname '#{shortname}'" if addresses.empty?
|
16
|
-
MiniCache::Data.new(addresses, expires_in: @ttl)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
private
|
21
|
-
def resolve(shortname)
|
22
|
-
addresses = Resolv::DNS.open do |dns|
|
23
|
-
dns.getaddresses(shortname).map { |r| r.to_s }
|
24
|
-
end
|
25
|
-
|
26
|
-
@logger.info("Resolved shortname '#{shortname}' to addresses #{addresses}")
|
27
|
-
|
28
|
-
return addresses
|
29
|
-
end
|
30
|
-
|
31
|
-
public
|
32
|
-
def get_address(shortname)
|
33
|
-
return resolve_cached(shortname).sample
|
34
|
-
end
|
35
|
-
|
36
|
-
public
|
37
|
-
def get_addresses(shortname)
|
38
|
-
return resolve_cached(shortname)
|
39
|
-
end
|
40
|
-
end
|