logstash-output-chronix 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 809b920a229b6a68d3d15a66c006255f7130fe55
4
+ data.tar.gz: 243a71edf32944d0e2d11c4b481b3382c2600efb
5
+ SHA512:
6
+ metadata.gz: 7051227f0486a1de7944c917fa967e043e6e45419376a35b4a0cf85bc87344465e1771c4607271d1910c297d9bdf32a73f75112354f93f0d2a1177d5b3082195
7
+ data.tar.gz: 0387b6a2ee030d7ee24eadceaa57400c956e729e9f7b35b1364257813aa705acb4af6b33ece4b5fa5431c16e5eedbab5769be2cb93e81a9d88eaf1866974913a
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "{}"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright {yyyy} {name of copyright owner}
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
data/NOTICE.TXT ADDED
@@ -0,0 +1,5 @@
1
+ Elasticsearch
2
+ Copyright 2012-2015 Elasticsearch
3
+
4
+ This product includes software developed by The Apache Software
5
+ Foundation (http://www.apache.org/).
data/README.md ADDED
@@ -0,0 +1,61 @@
1
+ # Logstash Plugin
2
+
3
+ [![Build Status](https://travis-ci.org/ChronixDB/chronix.logstash.svg?branch=master)](https://travis-ci.org/ChronixDB/chronix.logstash)
4
+
5
+ This is a plugin for [Logstash](https://github.com/elastic/logstash) to write time series to [Chronix](https://github.com/ChronixDB) released under the Apache 2.0 license.
6
+
7
+ ## Install the plugin
8
+
9
+ There are two options to install the plugin. (check one the official [Logstash Repos](https://github.com/logstash-plugins/logstash-output-example#2-running-your-unpublished-plugin-in-logstash) for reference)
10
+
11
+ ### Install in a local Logstash Clone:
12
+ - Edit Logstash `Gemfile` and add the local plugin path, for example:
13
+ ```ruby
14
+ gem "logstash-output-chronix", :path => "/path/to/logstash-output-chronix"
15
+ ```
16
+ - Install plugin
17
+ ```sh
18
+ bin/plugin install --no-verify
19
+ ```
20
+ - Run Logstash with a config for the plugin (see the Configuration section for help)
21
+ ```sh
22
+ bin/logstash -e your_config.conf
23
+ ```
24
+
25
+ ### Run in an installed Logstash
26
+
27
+ 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:
28
+
29
+ - Build your plugin gem
30
+ ```sh
31
+ gem build logstash-output-chronix.gemspec
32
+ ```
33
+ - Install the plugin from the Logstash home
34
+ ```sh
35
+ bin/plugin install /path/to/logstash/plugin/logstash-output-chronix.gem
36
+ ```
37
+ - Start Logstash and proceed to test the plugin
38
+
39
+
40
+ ## Configuration
41
+
42
+ Chronix always needs a 'metric' and a 'value' to store your data.
43
+ If your data doesn't contain a metric yet, you should add one during the filter-phase:
44
+ ```
45
+ filter {
46
+ mutate { add_field => { "metric" => "your_metric" } }
47
+ }
48
+ ```
49
+
50
+ You also have to add Chronix to your output. You can add some custom values to configure the plugin.
51
+ Here is an example with all the configuration options:
52
+ ```
53
+ chronix {
54
+ host => "192.168.0.1" # default is 'localhost'
55
+ port => "8983" # default is '8983'
56
+ path => "/solr/chronix/" # default is '/solr/chronix/'
57
+ flush_size => 100 # default is '100' (Number of events to queue up before writing to Solr)
58
+ idle_flush_time => 30 # default is '30' (Amount of time since the last flush before a flush is done)
59
+ }
60
+ ```
61
+
@@ -0,0 +1,120 @@
1
+ # encoding: utf-8
2
+
3
+ # based on: https://github.com/logstash-plugins/logstash-output-solr_http/blob/master/lib/logstash/outputs/solr_http.rb
4
+
5
+ require "base64"
6
+ require "date"
7
+ require "logstash/namespace"
8
+ require "logstash/outputs/base"
9
+ require "protobuf"
10
+ require "rsolr"
11
+ require "rubygems"
12
+ require "stud/buffer"
13
+ require "zlib"
14
+ require_relative "proto/Point.rb"
15
+
16
+ class LogStash::Outputs::Chronix < LogStash::Outputs::Base
17
+ include Stud::Buffer
18
+
19
+ config_name "chronix"
20
+
21
+ # IP or hostname of chronix installation, default: localhost
22
+ config :host, :validate => :string, :default => "localhost"
23
+
24
+ # chronix port, default: 8983
25
+ config :port, :validate => :string, :default => "8983"
26
+
27
+ # path to chronix, default: /solr/chronix/
28
+ config :path, :validate => :string, :default => "/solr/chronix/"
29
+
30
+ # Number of events to queue up before writing to Solr
31
+ config :flush_size, :validate => :number, :default => 100
32
+
33
+ # Amount of time since the last flush before a flush is done even if
34
+ # the number of buffered events is smaller than flush_size
35
+ config :idle_flush_time, :validate => :number, :default => 30
36
+
37
+ public
38
+ def register
39
+ # initialize the buffer
40
+ buffer_initialize(
41
+ :max_items => @flush_size,
42
+ :max_interval => @idle_flush_time,
43
+ :logger => @logger
44
+ )
45
+
46
+ connectToChronix
47
+ end # def register
48
+
49
+ # open the connection to chronix
50
+ def connectToChronix
51
+ @url = "http://" + @host + ":" + @port + @path
52
+ @solr = RSolr.connect :url => @url
53
+ end # def connectToChronix
54
+
55
+ public
56
+ def receive(event)
57
+ buffer_receive(event)
58
+ end # def receive
59
+
60
+ public
61
+ def flush(events, close=false)
62
+ pointHash = Hash.new
63
+
64
+ # add each event to our hash, sorted by metrics as key
65
+ events.each do |event|
66
+ eventData = event.to_hash()
67
+
68
+ # format the timestamp to unix format
69
+ timestamp = DateTime.iso8601("#{eventData["@timestamp"]}").to_time.to_i
70
+ metric = eventData["metric"]
71
+
72
+ # if there is no list for the current metric -> create a new one
73
+ if pointHash[metric] == nil
74
+ pointHash[metric] = {"startTime" => timestamp, "endTime" => timestamp, "points" => Chronix::Points.new}
75
+ end
76
+
77
+ pointHash[metric]["endTime"] = timestamp
78
+
79
+ # insert the current point in our list
80
+ pointHash[metric]["points"].p << createChronixPoint(timestamp, eventData["value"])
81
+
82
+ end #end do
83
+
84
+ documents = []
85
+
86
+ # iterate through pointHash and create a solr document
87
+ pointHash.each { |metric, phash|
88
+ documents << createSolrDocument(metric, phash)
89
+ }
90
+
91
+ # send to chronix
92
+ @solr.add documents
93
+ @solr.update :data => '<commit/>'
94
+ end #def flush
95
+
96
+ # this method zips and base64 encodes the list of points
97
+ def zipAndEncode(points)
98
+ # encode protobuf-list
99
+ proto_bytes = points.encode
100
+ string_io = StringIO.new("w")
101
+
102
+ # compress the encoded protobuf-list
103
+ gz = Zlib::GzipWriter.new(string_io)
104
+ gz.write(proto_bytes)
105
+ gz.close
106
+ data = string_io.string
107
+
108
+ # encode base64 (without \n)
109
+ return Base64.strict_encode64(data)
110
+ end
111
+
112
+ def createChronixPoint(timestamp, value)
113
+ return Chronix::Point.new( :t => timestamp, :v => value )
114
+ end
115
+
116
+ def createSolrDocument(metric, phash)
117
+ return { :metric => metric, :start => phash["startTime"], :end => phash["endTime"], :data => zipAndEncode(phash["points"]) }
118
+ end
119
+
120
+ end # class LogStash::Outputs::Chronix
@@ -0,0 +1,15 @@
1
+ syntax = "proto3";
2
+ option optimize_for = SPEED;
3
+
4
+ //Our point
5
+ message Point {
6
+ //The date as int64 (java long)
7
+ int64 t = 1;
8
+ double v = 2;
9
+ }
10
+
11
+ //The data of a time series is a list of points
12
+ message Points {
13
+ //The list of points
14
+ repeated Point p = 1;
15
+ }
@@ -0,0 +1,14 @@
1
+ # NOT GENERATED
2
+
3
+ require 'protobuf/message'
4
+
5
+ module Chronix
6
+ class Point < ::Protobuf::Message
7
+ optional :int64, :t, 1
8
+ required :double, :v, 2
9
+ end
10
+
11
+ class Points < ::Protobuf::Message
12
+ repeated ::Chronix::Point, :p, 1
13
+ end
14
+ end
@@ -0,0 +1,27 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'logstash-output-chronix'
3
+ s.version = "0.1.0"
4
+ s.licenses = ["Apache License (2.0)"]
5
+ s.summary = "This output stores your logs in chronix"
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"
7
+ s.authors = ["Max Jalowski"]
8
+ s.email = "max.jalowski@fau.de"
9
+ s.homepage = "http://www.elastic.co/guide/en/logstash/current/index.html"
10
+ s.require_paths = ["lib"]
11
+
12
+ # Files
13
+ s.files = Dir['lib/**/*','spec/**/*','vendor/**/*','*.gemspec','*.md','CONTRIBUTORS','Gemfile','LICENSE','NOTICE.TXT']
14
+ # Tests
15
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
16
+
17
+ # Special flag to let us know this is actually a logstash plugin
18
+ s.metadata = { "logstash_plugin" => "true", "logstash_group" => "output" }
19
+
20
+ # Gem dependencies
21
+ s.add_runtime_dependency "logstash-core", ">= 2.0.0", "< 3.0.0"
22
+ s.add_runtime_dependency "logstash-codec-plain"
23
+ s.add_runtime_dependency "stud"
24
+ s.add_runtime_dependency "rsolr"
25
+ s.add_runtime_dependency "protobuf"
26
+ s.add_development_dependency "logstash-devutils"
27
+ end
@@ -0,0 +1,51 @@
1
+ module Mocks
2
+ class Chronix
3
+
4
+ def initialize
5
+ @data = Hash.new
6
+ end
7
+
8
+ def add(documents)
9
+ documents.each do |document|
10
+ metric = document[:metric]
11
+ if @data[metric] == nil
12
+ @data[metric] = Array.new
13
+ end
14
+ @data[metric] << document
15
+ end
16
+ end
17
+
18
+ def get(metric)
19
+ return @data[metric]
20
+ end
21
+
22
+ def delete(metric=nil)
23
+ if metric == nil
24
+ @data.each do |metric, data|
25
+ @data.delete(metric)
26
+ end
27
+ else
28
+ @data.delete(metric)
29
+ end
30
+ end
31
+
32
+ def size(metric=nil)
33
+ if metric == nil
34
+ return @data.size
35
+ else
36
+ return @data[metric].size
37
+ end
38
+ end
39
+
40
+ def numDocuments
41
+ num = 0
42
+ @data.each do |metric, data|
43
+ num = num + data.size
44
+ end
45
+ return num
46
+ end
47
+
48
+ def update(data_hash)
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,171 @@
1
+ # encoding: utf-8
2
+
3
+ require_relative "../spec_helper"
4
+
5
+ describe LogStash::Outputs::Chronix do
6
+
7
+ let(:solr) { subject.solr }
8
+
9
+ before :each do
10
+ subject.register
11
+
12
+ events.each do |event|
13
+ subject.receive(event)
14
+ end
15
+ end
16
+
17
+ context "simple adding and removing test" do
18
+ subject { LogStash::Outputs::Chronix.new( "flush_size" => 1, "idle_flush_time" => 10 ) }
19
+
20
+ let(:tmetric) { "test1" }
21
+ let(:events) { [LogStash::Event.new("metric" => tmetric, "value" => "1.5")] }
22
+
23
+ it "create one event" do
24
+ expect(solr.size).to eq(1)
25
+ end
26
+
27
+ it "should retrieve document" do
28
+ doc = solr.get(tmetric)
29
+ expect(doc[0][:data]).to_not be_nil
30
+ end
31
+
32
+ it "should remove document" do
33
+ solr.delete(tmetric)
34
+ expect(solr.size).to eq(0)
35
+ end
36
+ end
37
+
38
+ context "test basic functions zip and encode, createPoint, createDocument" do
39
+ subject { LogStash::Outputs::Chronix.new( "flush_size" => 3, "idle_flush_time" => 10 ) }
40
+
41
+ let(:ttimestamp) { "1459353272" }
42
+ let(:tmetric) { "test1" }
43
+ let(:tvalue) { "10.5" }
44
+ let(:events) { [LogStash::Event.new("metric" => tmetric, "value" => tvalue)] }
45
+
46
+ it "should return a Chronix::Point" do
47
+ point = subject.createChronixPoint(ttimestamp, tvalue)
48
+ expectedResult = Chronix::Point.new( :t => ttimestamp, :v => tvalue )
49
+ expect(point).to eq(expectedResult)
50
+ end
51
+
52
+ it "should return a zipped and base64 encoded string containing the data" do
53
+ points = Chronix::Points.new
54
+ points.p << subject.createChronixPoint(ttimestamp, tvalue)
55
+ expectedResult = "H4sIAAAAAAAA/+Pi59jx9v12VkEGMFB1AACWVOXHEQAAAA=="
56
+ expect(subject.zipAndEncode(points)).to eq(expectedResult)
57
+ end
58
+
59
+ it "should create a valid document" do
60
+ points = Chronix::Points.new
61
+ points.p << subject.createChronixPoint(ttimestamp, tvalue)
62
+ phash = {"startTime" => ttimestamp, "endTime" => ttimestamp, "points" => points}
63
+ document = subject.createSolrDocument(tmetric, phash)
64
+ sampleDoc = { :metric => tmetric, :start => phash["startTime"], :end => phash["endTime"], :data => "H4sIAAAAAAAA/+Pi59jx9v12VkEGMFB1AACWVOXHEQAAAA==" }
65
+ expect(document).to eq(sampleDoc)
66
+ end
67
+
68
+ it "should remove test documents" do
69
+ solr.delete(tmetric)
70
+ expect(solr.size).to eq(0)
71
+ end
72
+ end
73
+
74
+ # these events are needed for the next two test-contexts
75
+ e1 = LogStash::Event.new("metric" => "test1", "value" => "1.5")
76
+ e2 = LogStash::Event.new("metric" => "test2", "value" => "2.5")
77
+ e3 = LogStash::Event.new("metric" => "test1", "value" => "3.5")
78
+ e4 = LogStash::Event.new("metric" => "test1", "value" => "4.5")
79
+ e5 = LogStash::Event.new("metric" => "test2", "value" => "5.5")
80
+ e6 = LogStash::Event.new("metric" => "test3", "value" => "6.5")
81
+ e7 = LogStash::Event.new("metric" => "test1", "value" => "7.5")
82
+ e8 = LogStash::Event.new("metric" => "test2", "value" => "8.5")
83
+
84
+ context "adding and removing tests with different metrics" do
85
+ subject { LogStash::Outputs::Chronix.new( "flush_size" => 1, "idle_flush_time" => 10 ) }
86
+
87
+ let(:events) { [e1, e2, e3, e4, e5, e6, e7, e8] }
88
+
89
+ it "should have 3 different metrics" do
90
+ expect(solr.size).to eq(3)
91
+ end
92
+
93
+ it "should have 8 documents" do
94
+ expect(solr.numDocuments).to eq(8)
95
+ end
96
+
97
+ it "should have 4 documents with metric 'test1'" do
98
+ expect(solr.size("test1")).to eq(4)
99
+ end
100
+
101
+ it "should have 3 documents with metric 'test2'" do
102
+ expect(solr.size("test2")).to eq(3)
103
+ end
104
+
105
+ it "should have 1 document with metric 'test3'" do
106
+ expect(solr.size("test3")).to eq(1)
107
+ end
108
+
109
+ it "should remove all documents" do
110
+ solr.delete
111
+ expect(solr.size).to eq(0)
112
+ end
113
+ end
114
+
115
+ # test1[0]: 3 elem, test1[1]: 1 elem
116
+ # test2[0]: 1 elem, test2[1]: 2 elem
117
+ # test3[0]: 1 elem
118
+ context "adding and removing tests with different metrics and buffer-settings" do
119
+ subject { LogStash::Outputs::Chronix.new( "flush_size" => 4, "idle_flush_time" => 10 ) }
120
+
121
+ let(:events) { [e1, e2, e3, e4, e5, e6, e7, e8] }
122
+
123
+ it "should have 3 different metrics" do
124
+ expect(solr.size).to eq(3)
125
+ end
126
+
127
+ it "should have 5 documents" do
128
+ expect(solr.numDocuments).to eq(5)
129
+ end
130
+
131
+ it "should have 2 documents with metric 'test1'" do
132
+ expect(solr.size("test1")).to eq(2)
133
+ end
134
+
135
+ it "should have 2 documents with metric 'test2'" do
136
+ expect(solr.size("test2")).to eq(2)
137
+ end
138
+
139
+ it "should have 1 document with metric 'test3'" do
140
+ expect(solr.size("test3")).to eq(1)
141
+ end
142
+
143
+ it "get all documents with metric 'test1', compare data-fields, the first one should be longer than the second one" do
144
+ res1 = solr.get("test1")
145
+ expect(res1[0][:data].length).to be > res1[1][:data].length
146
+ end
147
+
148
+ it "compare data-field-lengths from 'test1' and 'test2', expect res1[0].length > res2[1].length" do
149
+ res1 = solr.get("test1")
150
+ res2 = solr.get("test2")
151
+ expect(res1[0][:data].length).to be > res2[1][:data].length
152
+ end
153
+
154
+ it "compare data-field-lengths from 'test2', expect res2[1].length > res2[0].length" do
155
+ res2 = solr.get("test2")
156
+ expect(res2[1][:data].length).to be > res2[0][:data].length
157
+ end
158
+
159
+ it "compare data-field-lengths from 'test1' and 'test3', expect res1[1].length == res3[0].length" do
160
+ res1 = solr.get("test1")
161
+ res3 = solr.get("test3")
162
+ expect(res1[1][:data].length).to equal(res3[0][:data].length)
163
+ end
164
+
165
+ it "should remove all documents" do
166
+ solr.delete
167
+ expect(solr.size).to eq(0)
168
+ end
169
+ end
170
+
171
+ end
@@ -0,0 +1,12 @@
1
+ require "logstash/devutils/rspec/spec_helper"
2
+ require "logstash/outputs/chronix"
3
+ require_relative "../lib/logstash/outputs/proto/Point.rb"
4
+ require_relative "chronix_helper"
5
+
6
+ class LogStash::Outputs::Chronix
7
+ attr_reader :solr
8
+
9
+ def connectToChronix
10
+ @solr = Mocks::Chronix.new
11
+ end
12
+ end
metadata ADDED
@@ -0,0 +1,151 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-output-chronix
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Max Jalowski
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-04-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: logstash-core
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 2.0.0
20
+ - - <
21
+ - !ruby/object:Gem::Version
22
+ version: 3.0.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 2.0.0
30
+ - - <
31
+ - !ruby/object:Gem::Version
32
+ version: 3.0.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: logstash-codec-plain
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: stud
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rsolr
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :runtime
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: protobuf
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :runtime
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: logstash-devutils
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ description: This gem is a logstash plugin required to be installed on top of the
104
+ Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not
105
+ a stand-alone program
106
+ email: max.jalowski@fau.de
107
+ executables: []
108
+ extensions: []
109
+ extra_rdoc_files: []
110
+ files:
111
+ - lib/logstash/outputs/chronix.rb
112
+ - lib/logstash/outputs/proto/Point.proto
113
+ - lib/logstash/outputs/proto/Point.rb
114
+ - spec/chronix_helper.rb
115
+ - spec/outputs/chronix_spec.rb
116
+ - spec/spec_helper.rb
117
+ - logstash-output-chronix.gemspec
118
+ - README.md
119
+ - Gemfile
120
+ - LICENSE
121
+ - NOTICE.TXT
122
+ homepage: http://www.elastic.co/guide/en/logstash/current/index.html
123
+ licenses:
124
+ - Apache License (2.0)
125
+ metadata:
126
+ logstash_plugin: 'true'
127
+ logstash_group: output
128
+ post_install_message:
129
+ rdoc_options: []
130
+ require_paths:
131
+ - lib
132
+ required_ruby_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - '>='
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ requirements: []
143
+ rubyforge_project:
144
+ rubygems_version: 2.0.14
145
+ signing_key:
146
+ specification_version: 4
147
+ summary: This output stores your logs in chronix
148
+ test_files:
149
+ - spec/chronix_helper.rb
150
+ - spec/outputs/chronix_spec.rb
151
+ - spec/spec_helper.rb