logstash-output-cassandra 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CONTRIBUTORS +7 -0
- data/Gemfile +4 -0
- data/LICENSE +218 -0
- data/README.md +148 -0
- data/lib/logstash/outputs/cassandra.rb +164 -0
- data/lib/logstash/outputs/cassandra/backoff_retry_policy.rb +65 -0
- data/lib/logstash/outputs/cassandra/buffer.rb +125 -0
- data/lib/logstash/outputs/cassandra/event_parser.rb +161 -0
- data/lib/logstash/outputs/cassandra/safe_submitter.rb +118 -0
- data/logstash-output-cassandra.gemspec +35 -0
- data/spec/cassandra_spec_helper.rb +14 -0
- data/spec/integration/outputs/cassandra_spec.rb +115 -0
- data/spec/integration/outputs/integration_helper.rb +91 -0
- data/spec/unit/outputs/backoff_retry_policy_spec.rb +131 -0
- data/spec/unit/outputs/buffer_spec.rb +119 -0
- data/spec/unit/outputs/cassandra_spec.rb +5 -0
- data/spec/unit/outputs/event_parser_spec.rb +304 -0
- data/spec/unit/outputs/safe_submitter_spec.rb +201 -0
- metadata +266 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: eb924301f2fb18274dadf7937c5fb10ddab91a80
|
4
|
+
data.tar.gz: d05bf1803112c866ffdc2ac13d5a7f4116709f31
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ad63bb3d2685b22ec636c0af391689b4353231f448b2806bb05c2617dfa2cfcc391772ba7d1b23c921eccaad1281c63f7ccd080ba3d8463299d14df9f01a029d
|
7
|
+
data.tar.gz: 1dcda642fb5e9ab2f26930810ecc8ef99253a0cea977fb242823892a50e38fcd1025f17dc6a6ef42a44d6d0505c663d3293271e6e57a41d8846b865f52de0cad
|
data/CONTRIBUTORS
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
The following is a list of people who have contributed (in chronological order) ideas, code, bug
|
2
|
+
reports, or in general have helped this plugin along its way.
|
3
|
+
|
4
|
+
Contributors:
|
5
|
+
* Oleg Tokarev (otokarev)
|
6
|
+
* Elad Amit (eladamitpxi, amitelad7)
|
7
|
+
* Valentin Fischer (valentinul)
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,218 @@
|
|
1
|
+
<<<<<<< HEAD
|
2
|
+
Copyright (c) 2012-2015 Elasticsearch <http://www.elasticsearch.org>
|
3
|
+
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
you may not use this file except in compliance with the License.
|
6
|
+
You may obtain a copy of the License at
|
7
|
+
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
See the License for the specific language governing permissions and
|
14
|
+
limitations under the License.
|
15
|
+
=======
|
16
|
+
Apache License
|
17
|
+
Version 2.0, January 2004
|
18
|
+
http://www.apache.org/licenses/
|
19
|
+
|
20
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
21
|
+
|
22
|
+
1. Definitions.
|
23
|
+
|
24
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
25
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
26
|
+
|
27
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
28
|
+
the copyright owner that is granting the License.
|
29
|
+
|
30
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
31
|
+
other entities that control, are controlled by, or are under common
|
32
|
+
control with that entity. For the purposes of this definition,
|
33
|
+
"control" means (i) the power, direct or indirect, to cause the
|
34
|
+
direction or management of such entity, whether by contract or
|
35
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
36
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
37
|
+
|
38
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
39
|
+
exercising permissions granted by this License.
|
40
|
+
|
41
|
+
"Source" form shall mean the preferred form for making modifications,
|
42
|
+
including but not limited to software source code, documentation
|
43
|
+
source, and configuration files.
|
44
|
+
|
45
|
+
"Object" form shall mean any form resulting from mechanical
|
46
|
+
transformation or translation of a Source form, including but
|
47
|
+
not limited to compiled object code, generated documentation,
|
48
|
+
and conversions to other media types.
|
49
|
+
|
50
|
+
"Work" shall mean the work of authorship, whether in Source or
|
51
|
+
Object form, made available under the License, as indicated by a
|
52
|
+
copyright notice that is included in or attached to the work
|
53
|
+
(an example is provided in the Appendix below).
|
54
|
+
|
55
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
56
|
+
form, that is based on (or derived from) the Work and for which the
|
57
|
+
editorial revisions, annotations, elaborations, or other modifications
|
58
|
+
represent, as a whole, an original work of authorship. For the purposes
|
59
|
+
of this License, Derivative Works shall not include works that remain
|
60
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
61
|
+
the Work and Derivative Works thereof.
|
62
|
+
|
63
|
+
"Contribution" shall mean any work of authorship, including
|
64
|
+
the original version of the Work and any modifications or additions
|
65
|
+
to that Work or Derivative Works thereof, that is intentionally
|
66
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
67
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
68
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
69
|
+
means any form of electronic, verbal, or written communication sent
|
70
|
+
to the Licensor or its representatives, including but not limited to
|
71
|
+
communication on electronic mailing lists, source code control systems,
|
72
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
73
|
+
Licensor for the purpose of discussing and improving the Work, but
|
74
|
+
excluding communication that is conspicuously marked or otherwise
|
75
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
76
|
+
|
77
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
78
|
+
on behalf of whom a Contribution has been received by Licensor and
|
79
|
+
subsequently incorporated within the Work.
|
80
|
+
|
81
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
82
|
+
this License, each Contributor hereby grants to You a perpetual,
|
83
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
84
|
+
copyright license to reproduce, prepare Derivative Works of,
|
85
|
+
publicly display, publicly perform, sublicense, and distribute the
|
86
|
+
Work and such Derivative Works in Source or Object form.
|
87
|
+
|
88
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
89
|
+
this License, each Contributor hereby grants to You a perpetual,
|
90
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
91
|
+
(except as stated in this section) patent license to make, have made,
|
92
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
93
|
+
where such license applies only to those patent claims licensable
|
94
|
+
by such Contributor that are necessarily infringed by their
|
95
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
96
|
+
with the Work to which such Contribution(s) was submitted. If You
|
97
|
+
institute patent litigation against any entity (including a
|
98
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
99
|
+
or a Contribution incorporated within the Work constitutes direct
|
100
|
+
or contributory patent infringement, then any patent licenses
|
101
|
+
granted to You under this License for that Work shall terminate
|
102
|
+
as of the date such litigation is filed.
|
103
|
+
|
104
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
105
|
+
Work or Derivative Works thereof in any medium, with or without
|
106
|
+
modifications, and in Source or Object form, provided that You
|
107
|
+
meet the following conditions:
|
108
|
+
|
109
|
+
(a) You must give any other recipients of the Work or
|
110
|
+
Derivative Works a copy of this License; and
|
111
|
+
|
112
|
+
(b) You must cause any modified files to carry prominent notices
|
113
|
+
stating that You changed the files; and
|
114
|
+
|
115
|
+
(c) You must retain, in the Source form of any Derivative Works
|
116
|
+
that You distribute, all copyright, patent, trademark, and
|
117
|
+
attribution notices from the Source form of the Work,
|
118
|
+
excluding those notices that do not pertain to any part of
|
119
|
+
the Derivative Works; and
|
120
|
+
|
121
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
122
|
+
distribution, then any Derivative Works that You distribute must
|
123
|
+
include a readable copy of the attribution notices contained
|
124
|
+
within such NOTICE file, excluding those notices that do not
|
125
|
+
pertain to any part of the Derivative Works, in at least one
|
126
|
+
of the following places: within a NOTICE text file distributed
|
127
|
+
as part of the Derivative Works; within the Source form or
|
128
|
+
documentation, if provided along with the Derivative Works; or,
|
129
|
+
within a display generated by the Derivative Works, if and
|
130
|
+
wherever such third-party notices normally appear. The contents
|
131
|
+
of the NOTICE file are for informational purposes only and
|
132
|
+
do not modify the License. You may add Your own attribution
|
133
|
+
notices within Derivative Works that You distribute, alongside
|
134
|
+
or as an addendum to the NOTICE text from the Work, provided
|
135
|
+
that such additional attribution notices cannot be construed
|
136
|
+
as modifying the License.
|
137
|
+
|
138
|
+
You may add Your own copyright statement to Your modifications and
|
139
|
+
may provide additional or different license terms and conditions
|
140
|
+
for use, reproduction, or distribution of Your modifications, or
|
141
|
+
for any such Derivative Works as a whole, provided Your use,
|
142
|
+
reproduction, and distribution of the Work otherwise complies with
|
143
|
+
the conditions stated in this License.
|
144
|
+
|
145
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
146
|
+
any Contribution intentionally submitted for inclusion in the Work
|
147
|
+
by You to the Licensor shall be under the terms and conditions of
|
148
|
+
this License, without any additional terms or conditions.
|
149
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
150
|
+
the terms of any separate license agreement you may have executed
|
151
|
+
with Licensor regarding such Contributions.
|
152
|
+
|
153
|
+
6. Trademarks. This License does not grant permission to use the trade
|
154
|
+
names, trademarks, service marks, or product names of the Licensor,
|
155
|
+
except as required for reasonable and customary use in describing the
|
156
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
157
|
+
|
158
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
159
|
+
agreed to in writing, Licensor provides the Work (and each
|
160
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
161
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
162
|
+
implied, including, without limitation, any warranties or conditions
|
163
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
164
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
165
|
+
appropriateness of using or redistributing the Work and assume any
|
166
|
+
risks associated with Your exercise of permissions under this License.
|
167
|
+
|
168
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
169
|
+
whether in tort (including negligence), contract, or otherwise,
|
170
|
+
unless required by applicable law (such as deliberate and grossly
|
171
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
172
|
+
liable to You for damages, including any direct, indirect, special,
|
173
|
+
incidental, or consequential damages of any character arising as a
|
174
|
+
result of this License or out of the use or inability to use the
|
175
|
+
Work (including but not limited to damages for loss of goodwill,
|
176
|
+
work stoppage, computer failure or malfunction, or any and all
|
177
|
+
other commercial damages or losses), even if such Contributor
|
178
|
+
has been advised of the possibility of such damages.
|
179
|
+
|
180
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
181
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
182
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
183
|
+
or other liability obligations and/or rights consistent with this
|
184
|
+
License. However, in accepting such obligations, You may act only
|
185
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
186
|
+
of any other Contributor, and only if You agree to indemnify,
|
187
|
+
defend, and hold each Contributor harmless for any liability
|
188
|
+
incurred by, or claims asserted against, such Contributor by reason
|
189
|
+
of your accepting any such warranty or additional liability.
|
190
|
+
|
191
|
+
END OF TERMS AND CONDITIONS
|
192
|
+
|
193
|
+
APPENDIX: How to apply the Apache License to your work.
|
194
|
+
|
195
|
+
To apply the Apache License to your work, attach the following
|
196
|
+
boilerplate notice, with the fields enclosed by brackets "{}"
|
197
|
+
replaced with your own identifying information. (Don't include
|
198
|
+
the brackets!) The text should be enclosed in the appropriate
|
199
|
+
comment syntax for the file format. We also recommend that a
|
200
|
+
file or class name and description of purpose be included on the
|
201
|
+
same "printed page" as the copyright notice for easier
|
202
|
+
identification within third-party archives.
|
203
|
+
|
204
|
+
Copyright {yyyy} {name of copyright owner}
|
205
|
+
|
206
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
207
|
+
you may not use this file except in compliance with the License.
|
208
|
+
You may obtain a copy of the License at
|
209
|
+
|
210
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
211
|
+
|
212
|
+
Unless required by applicable law or agreed to in writing, software
|
213
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
214
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
215
|
+
See the License for the specific language governing permissions and
|
216
|
+
limitations under the License.
|
217
|
+
|
218
|
+
>>>>>>> 56f47bec0cc3d3230ae48792e7ac094823872298
|
data/README.md
ADDED
@@ -0,0 +1,148 @@
|
|
1
|
+
# Logstash Cassandra Output Plugin
|
2
|
+
|
3
|
+
This is a plugin for [Logstash](https://github.com/elastic/logstash).
|
4
|
+
|
5
|
+
It is fully free and fully open source. The license is Apache 2.0, meaning you are pretty much free to use it however you want in whatever way.
|
6
|
+
|
7
|
+
It was originally a fork of the [logstash-output-cassandra](https://github.com/otokarev/logstash-output-cassandra) plugin by [Oleg Tokarev](https://github.com/otokarev), which has gone unmaintained and went through a major re-design in this version we built.
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
<pre><code>
|
12
|
+
output {
|
13
|
+
cassandra {
|
14
|
+
# List of Cassandra hostname(s) or IP-address(es)
|
15
|
+
hosts => [ "cass-01", "cass-02" ]
|
16
|
+
|
17
|
+
# The port cassandra is listening to
|
18
|
+
port => 9042
|
19
|
+
|
20
|
+
# The protocol version to use with cassandra
|
21
|
+
protocol_version => 4
|
22
|
+
|
23
|
+
# Cassandra consistency level.
|
24
|
+
# Options: "any", "one", "two", "three", "quorum", "all", "local_quorum", "each_quorum", "serial", "local_serial", "local_one"
|
25
|
+
# Default: "one"
|
26
|
+
consistency => 'any'
|
27
|
+
|
28
|
+
# The keyspace to use
|
29
|
+
keyspace => "a_ks"
|
30
|
+
|
31
|
+
# The table to use (event level processing (e.g. %{[key]}) is supported)
|
32
|
+
table => "%{[@metadata][cassandra_table]}"
|
33
|
+
|
34
|
+
# Username
|
35
|
+
username => "cassandra"
|
36
|
+
|
37
|
+
# Password
|
38
|
+
password => "cassandra"
|
39
|
+
|
40
|
+
# An optional hints hash which will be used in case filter_transform or filter_transform_event_key are not in use
|
41
|
+
# It is used to trigger a forced type casting to the cassandra driver types in
|
42
|
+
# the form of a hash from column name to type name in the following manner:
|
43
|
+
hints => {
|
44
|
+
id => "int"
|
45
|
+
at => "timestamp"
|
46
|
+
resellerId => "int"
|
47
|
+
errno => "int"
|
48
|
+
duration => "float"
|
49
|
+
ip => "inet"
|
50
|
+
}
|
51
|
+
|
52
|
+
# The retry policy to use (the default is the default retry policy)
|
53
|
+
# the hash requires the name of the policy and the params it requires
|
54
|
+
# The available policy names are:
|
55
|
+
# * default => retry once if needed / possible
|
56
|
+
# * downgrading_consistency => retry once with a best guess lowered consistency
|
57
|
+
# * failthrough => fail immediately (i.e. no retries)
|
58
|
+
# * backoff => a version of the default retry policy but with configurable backoff retries
|
59
|
+
# The backoff options are as follows:
|
60
|
+
# * backoff_type => either * or ** for linear and exponential backoffs respectively
|
61
|
+
# * backoff_size => the left operand for the backoff type in seconds
|
62
|
+
# * retry_limit => the maximum amount of retries to allow per query
|
63
|
+
# example:
|
64
|
+
# using { "type" => "backoff" "backoff_type" => "**" "backoff_size" => 2 "retry_limit" => 10 } will perform 10 retries with the following wait times: 1, 2, 4, 8, 16, ... 1024
|
65
|
+
# NOTE: there is an underlying assumption that the insert query is idempotent !!!
|
66
|
+
# NOTE: when the backoff retry policy is used, it will also be used to handle pure client timeouts and not just ones coming from the coordinator
|
67
|
+
retry_policy => { "type" => "default" }
|
68
|
+
|
69
|
+
# The command execution timeout
|
70
|
+
request_timeout => 1
|
71
|
+
|
72
|
+
# Ignore bad values
|
73
|
+
ignore_bad_values => false
|
74
|
+
|
75
|
+
# In Logstashes >= 2.2 this setting defines the maximum sized bulk request Logstash will make
|
76
|
+
# You you may want to increase this to be in line with your pipeline's batch size.
|
77
|
+
# If you specify a number larger than the batch size of your pipeline it will have no effect,
|
78
|
+
# save for the case where a filter increases the size of an inflight batch by outputting
|
79
|
+
# events.
|
80
|
+
#
|
81
|
+
# In Logstashes <= 2.1 this plugin uses its own internal buffer of events.
|
82
|
+
# This config option sets that size. In these older logstashes this size may
|
83
|
+
# have a significant impact on heap usage, whereas in 2.2+ it will never increase it.
|
84
|
+
# To make efficient bulk API calls, we will buffer a certain number of
|
85
|
+
# events before flushing that out to Cassandra. This setting
|
86
|
+
# controls how many events will be buffered before sending a batch
|
87
|
+
# of events. Increasing the `flush_size` has an effect on Logstash's heap size.
|
88
|
+
# Remember to also increase the heap size using `LS_HEAP_SIZE` if you are sending big commands
|
89
|
+
# or have increased the `flush_size` to a higher value.
|
90
|
+
flush_size => 500
|
91
|
+
|
92
|
+
# The amount of time since last flush before a flush is forced.
|
93
|
+
#
|
94
|
+
# This setting helps ensure slow event rates don't get stuck in Logstash.
|
95
|
+
# For example, if your `flush_size` is 100, and you have received 10 events,
|
96
|
+
# and it has been more than `idle_flush_time` seconds since the last flush,
|
97
|
+
# Logstash will flush those 10 events automatically.
|
98
|
+
#
|
99
|
+
# This helps keep both fast and slow log streams moving along in
|
100
|
+
# near-real-time.
|
101
|
+
idle_flush_time => 1
|
102
|
+
}
|
103
|
+
}
|
104
|
+
</code></pre>
|
105
|
+
|
106
|
+
## Running Plugin in Logstash
|
107
|
+
### Run in a local Logstash clone
|
108
|
+
|
109
|
+
Edit Logstash Gemfile and add the local plugin path, for example:
|
110
|
+
```
|
111
|
+
gem "logstash-output-cassandra", :path => "/your/local/logstash-output-cassandra"
|
112
|
+
```
|
113
|
+
|
114
|
+
Install plugin
|
115
|
+
```
|
116
|
+
bin/plugin install --no-verify
|
117
|
+
```
|
118
|
+
Run Logstash with the plugin
|
119
|
+
```
|
120
|
+
bin/logstash -e 'output {cassandra {}}'
|
121
|
+
```
|
122
|
+
|
123
|
+
### Run in an installed Logstash
|
124
|
+
|
125
|
+
You can use the same method to run your plugin in an installed Logstash by editing its Gemfile and pointing the :path to your local plugin development directory or you can build the gem and install it using:
|
126
|
+
|
127
|
+
Build your plugin gem
|
128
|
+
```
|
129
|
+
gem build logstash-output-cassandra.gemspec
|
130
|
+
```
|
131
|
+
Install the plugin from the Logstash home
|
132
|
+
```
|
133
|
+
bin/plugin install /your/local/plugin/logstash-output-cassandra.gem
|
134
|
+
```
|
135
|
+
Run Logstash with the plugin
|
136
|
+
```
|
137
|
+
bin/logstash -e 'output {cassandra {}}'
|
138
|
+
```
|
139
|
+
|
140
|
+
## TODO
|
141
|
+
* Finish integration specs
|
142
|
+
* it "properly works with counter columns"
|
143
|
+
* it "properly adds multiple events to multiple tables in the same bulk"
|
144
|
+
* Improve retries to include (but probably only handle Errors::Timeout and Errors::NoHostsAvailable):
|
145
|
+
* \#get_query
|
146
|
+
* \#execute_async
|
147
|
+
* Upgrade / test with logstash 2.3
|
148
|
+
* Upgrade / test with cassandra 3
|
@@ -0,0 +1,164 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'logstash/outputs/base'
|
3
|
+
require 'logstash/namespace'
|
4
|
+
require 'logstash/outputs/cassandra/buffer'
|
5
|
+
require 'logstash/outputs/cassandra/event_parser'
|
6
|
+
require 'logstash/outputs/cassandra/safe_submitter'
|
7
|
+
|
8
|
+
class LogStash::Outputs::CassandraOutput < LogStash::Outputs::Base
|
9
|
+
|
10
|
+
milestone 1
|
11
|
+
|
12
|
+
config_name 'cassandra'
|
13
|
+
|
14
|
+
# List of Cassandra hostname(s) or IP-address(es)
|
15
|
+
config :hosts, :validate => :array, :required => true
|
16
|
+
|
17
|
+
# The port cassandra is listening to
|
18
|
+
config :port, :validate => :number, :default => 9042, :required => true
|
19
|
+
|
20
|
+
# The protocol version to use with cassandra
|
21
|
+
config :protocol_version, :validate => :number, :default => 4
|
22
|
+
|
23
|
+
# Cassandra consistency level.
|
24
|
+
# Options: "any", "one", "two", "three", "quorum", "all", "local_quorum", "each_quorum", "serial", "local_serial", "local_one"
|
25
|
+
# Default: "one"
|
26
|
+
config :consistency, :validate => [ 'any', 'one', 'two', 'three', 'quorum', 'all', 'local_quorum', 'each_quorum', 'serial', 'local_serial', 'local_one' ], :default => 'one'
|
27
|
+
|
28
|
+
# The keyspace to use
|
29
|
+
config :keyspace, :validate => :string, :required => true
|
30
|
+
|
31
|
+
# The table to use (event level processing (e.g. %{[key]}) is supported)
|
32
|
+
config :table, :validate => :string, :required => true
|
33
|
+
|
34
|
+
# Username
|
35
|
+
config :username, :validate => :string, :required => true
|
36
|
+
|
37
|
+
# Password
|
38
|
+
config :password, :validate => :string, :required => true
|
39
|
+
|
40
|
+
# An optional hash describing how / what to transform / filter from the original event
|
41
|
+
# Each key is expected to be of the form { event_key => "..." column_name => "..." cassandra_type => "..." }
|
42
|
+
# Event level processing (e.g. %{[key]}) is supported for all three
|
43
|
+
config :filter_transform, :validate => :array, :default => []
|
44
|
+
|
45
|
+
# An optional string which points to the event specific location from which to pull the filter_transform definition
|
46
|
+
# The contents need to conform with those defined for the filter_transform config setting
|
47
|
+
# Event level processing (e.g. %{[key]}) is supported
|
48
|
+
config :filter_transform_event_key, :validate => :string, :default => nil
|
49
|
+
|
50
|
+
# An optional hints hash which will be used in case filter_transform or filter_transform_event_key are not in use
|
51
|
+
# It is used to trigger a forced type casting to the cassandra driver types in
|
52
|
+
# the form of a hash from column name to type name in the following manner:
|
53
|
+
# hints => {
|
54
|
+
# id => "int"
|
55
|
+
# at => "timestamp"
|
56
|
+
# resellerId => "int"
|
57
|
+
# errno => "int"
|
58
|
+
# duration => "float"
|
59
|
+
# ip => "inet" }
|
60
|
+
config :hints, :validate => :hash, :default => {}
|
61
|
+
|
62
|
+
# The retry policy to use (the default is the default retry policy)
|
63
|
+
# the hash requires the name of the policy and the params it requires
|
64
|
+
# The available policy names are:
|
65
|
+
# * default => retry once if needed / possible
|
66
|
+
# * downgrading_consistency => retry once with a best guess lowered consistency
|
67
|
+
# * failthrough => fail immediately (i.e. no retries)
|
68
|
+
# * backoff => a version of the default retry policy but with configurable backoff retries
|
69
|
+
# The backoff options are as follows:
|
70
|
+
# * backoff_type => either * or ** for linear and exponential backoffs respectively
|
71
|
+
# * backoff_size => the left operand for the backoff type in seconds
|
72
|
+
# * retry_limit => the maximum amount of retries to allow per query
|
73
|
+
# example:
|
74
|
+
# using { "type" => "backoff" "backoff_type" => "**" "backoff_size" => 2 "retry_limit" => 10 } will perform 10 retries with the following wait times: 1, 2, 4, 8, 16, ... 1024
|
75
|
+
# NOTE: there is an underlying assumption that the insert query is idempotent !!!
|
76
|
+
# NOTE: when the backoff retry policy is used, it will also be used to handle pure client timeouts and not just ones coming from the coordinator
|
77
|
+
config :retry_policy, :validate => :hash, :default => { 'type' => 'default' }, :required => true
|
78
|
+
|
79
|
+
# The command execution timeout
|
80
|
+
config :request_timeout, :validate => :number, :default => 1
|
81
|
+
|
82
|
+
# Ignore bad values
|
83
|
+
config :ignore_bad_values, :validate => :boolean, :default => false
|
84
|
+
|
85
|
+
# In Logstashes >= 2.2 this setting defines the maximum sized bulk request Logstash will make
|
86
|
+
# You you may want to increase this to be in line with your pipeline's batch size.
|
87
|
+
# If you specify a number larger than the batch size of your pipeline it will have no effect,
|
88
|
+
# save for the case where a filter increases the size of an inflight batch by outputting
|
89
|
+
# events.
|
90
|
+
#
|
91
|
+
# In Logstashes <= 2.1 this plugin uses its own internal buffer of events.
|
92
|
+
# This config option sets that size. In these older logstashes this size may
|
93
|
+
# have a significant impact on heap usage, whereas in 2.2+ it will never increase it.
|
94
|
+
# To make efficient bulk API calls, we will buffer a certain number of
|
95
|
+
# events before flushing that out to Cassandra. This setting
|
96
|
+
# controls how many events will be buffered before sending a batch
|
97
|
+
# of events. Increasing the `flush_size` has an effect on Logstash's heap size.
|
98
|
+
# Remember to also increase the heap size using `LS_HEAP_SIZE` if you are sending big commands
|
99
|
+
# or have increased the `flush_size` to a higher value.
|
100
|
+
config :flush_size, :validate => :number, :default => 500
|
101
|
+
|
102
|
+
# The amount of time since last flush before a flush is forced.
|
103
|
+
#
|
104
|
+
# This setting helps ensure slow event rates don't get stuck in Logstash.
|
105
|
+
# For example, if your `flush_size` is 100, and you have received 10 events,
|
106
|
+
# and it has been more than `idle_flush_time` seconds since the last flush,
|
107
|
+
# Logstash will flush those 10 events automatically.
|
108
|
+
#
|
109
|
+
# This helps keep both fast and slow log streams moving along in
|
110
|
+
# near-real-time.
|
111
|
+
config :idle_flush_time, :validate => :number, :default => 1
|
112
|
+
|
113
|
+
def register
|
114
|
+
setup_event_parser
|
115
|
+
setup_safe_submitter
|
116
|
+
setup_buffer_and_handler
|
117
|
+
end
|
118
|
+
|
119
|
+
def receive(event)
|
120
|
+
@buffer << @event_parser.parse(event)
|
121
|
+
end
|
122
|
+
|
123
|
+
def multi_receive(events)
|
124
|
+
events.each_slice(@flush_size) do |slice|
|
125
|
+
@safe_submitter.submit(slice.map {|event| @event_parser.parse(event) })
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def teardown
|
130
|
+
close
|
131
|
+
end
|
132
|
+
|
133
|
+
def close
|
134
|
+
@buffer.stop
|
135
|
+
end
|
136
|
+
|
137
|
+
def flush
|
138
|
+
@buffer.flush
|
139
|
+
end
|
140
|
+
|
141
|
+
private
|
142
|
+
def setup_event_parser
|
143
|
+
@event_parser = ::LogStash::Outputs::Cassandra::EventParser.new(
|
144
|
+
'logger' => @logger, 'table' => @table,
|
145
|
+
'filter_transform_event_key' => @filter_transform_event_key, 'filter_transform' => @filter_transform,
|
146
|
+
'hints' => @hints, 'ignore_bad_values' => @ignore_bad_values
|
147
|
+
)
|
148
|
+
end
|
149
|
+
|
150
|
+
def setup_safe_submitter
|
151
|
+
@safe_submitter = ::LogStash::Outputs::Cassandra::SafeSubmitter.new(
|
152
|
+
'logger' => @logger, 'cassandra' => ::Cassandra,
|
153
|
+
'hosts' => @hosts, 'port' => @port, 'username' => @username, 'password' => @password,
|
154
|
+
'consistency' => @consistency, 'request_timeout' => @request_timeout, 'retry_policy' => @retry_policy,
|
155
|
+
'keyspace' => @keyspace
|
156
|
+
)
|
157
|
+
end
|
158
|
+
|
159
|
+
def setup_buffer_and_handler
|
160
|
+
@buffer = ::LogStash::Outputs::Cassandra::Buffer.new(@logger, @flush_size, @idle_flush_time) do |actions|
|
161
|
+
@safe_submitter.submit(actions)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|