logstash-input-openwhisk 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9db13f2d4ca718f1a1535f0eddad8e2c85d91075
4
- data.tar.gz: e7c52b01737a328cb0da22e0181ecd5e6ac8cc8a
3
+ metadata.gz: d6085b13d1d676f730d1a6d122fdc692ed18956f
4
+ data.tar.gz: ef9b033a0d39f22c64a02d892fea5383c55a4808
5
5
  SHA512:
6
- metadata.gz: 64caf68777249d6c82830327f9e8d2a171d7cfd0db9f158816729e07973e53ea169953921b7055de2cb6a1c507e5c308979fca9e8323bc4b12bb9d87b17a8541
7
- data.tar.gz: c10fa9d69965376eb088b1c41673ccbaf7699e87bc0cf61e9fc88f496b412a4331e652d048d90b9f7650a0e8fcf7a0308588cfe2ccc795e716e03b7a82f10d9e
6
+ metadata.gz: 2db8d05321809c5c2e833a19fcd7e195da2e8627634240760fb6035ba790a0279ce90d2b53606d32eaddf721df9679ce725809ba2aed2c5444579a80b8658119
7
+ data.tar.gz: c9f43dd62b3c79fe67c566959d47681fcfad893face804a57ce6b136a29da25dc85d7b7064e572c3d360bfbc440842e81b8f501dfd1e34deee85627b33c0bd38
@@ -5,6 +5,7 @@ require "logstash/plugin_mixins/http_client"
5
5
  require "socket" # for Socket.gethostname
6
6
  require "manticore"
7
7
  require "rufus/scheduler"
8
+ require 'json'
8
9
 
9
10
  # This Logstash input plugin allows you to drain OpenWhisk Activation logs, decoding the output into event(s), and
10
11
  # send them on their merry way. Using the OpenWhisk platform API, we poll the activation logs API according to the config schedule.
@@ -184,6 +185,7 @@ class LogStash::Inputs::OpenWhisk < LogStash::Inputs::Base
184
185
 
185
186
  ## ignore results we have previously seen
186
187
  if !@activation_ids.include?(activation_id)
188
+ sanitize(decoded)
187
189
  event = @target ? LogStash::Event.new(@target => decoded.to_hash) : decoded
188
190
  update_logs_since(decoded.to_hash["end"])
189
191
  handle_decoded_event(queue, name, request, response, event, execution_time)
@@ -195,6 +197,15 @@ class LogStash::Inputs::OpenWhisk < LogStash::Inputs::Base
195
197
  @activation_ids = activation_ids
196
198
  end
197
199
 
200
+ # elastic search cannot handle attributes which change types.
201
+ # serialise annotations to JSON strings
202
+ private
203
+ def sanitize(activation)
204
+ annotations = activation.get("annotations")
205
+ annotations.each {|a| a["value"] = a["value"].to_json}
206
+ activation.set("annotations", annotations)
207
+ end
208
+
198
209
  # updates the query parameter for the next request
199
210
  # based upon the last activation's end time.
200
211
  private
@@ -1,12 +1,12 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'logstash-input-openwhisk'
3
- s.version = '0.1.0'
3
+ s.version = '0.1.1'
4
4
  s.licenses = ['Apache License (2.0)']
5
5
  s.summary = "Retrieve OpenWhisk logs with Logstash."
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/logstash-plugin install gemname. This gem is not a stand-alone program"
7
7
  s.authors = [ "James Thomas" ]
8
8
  s.email = 'james@jamesthom.as'
9
- s.homepage = "http://www.elastic.co/guide/en/logstash/current/index.html"
9
+ s.homepage = "http://github.com/jthomas/logstash-input-openwhisk"
10
10
  s.require_paths = ["lib"]
11
11
 
12
12
  # Files
@@ -428,7 +428,7 @@ describe LogStash::Inputs::OpenWhisk do
428
428
  end
429
429
 
430
430
  describe "a valid request and decoded response" do
431
- let(:payload) { [{"start" => 1476818509288, "end" => 1476818509888, "activationId" => "some_id"}] }
431
+ let(:payload) { [{"start" => 1476818509288, "end" => 1476818509888, "activationId" => "some_id", "annotations" => []}] }
432
432
  let(:opts) { default_opts }
433
433
  let(:instance) {
434
434
  klass.new(opts)
@@ -496,8 +496,17 @@ describe LogStash::Inputs::OpenWhisk do
496
496
  end
497
497
  end
498
498
 
499
+ context "with annotations" do
500
+ let(:annotations) { [{"key" => "a", "value" => { "child": "val" } }, {"key" => "b", "value" => "some_string"}] }
501
+ let(:payload) { [{"start" => 1476818509288, "end" => 1476818509888, "activationId" => "some_id", "annotations" => annotations}] }
502
+
503
+ it "should serialise annotations to JSON strings" do
504
+ expect(event.to_hash["annotations"]).to eql([{"key" => "a", "value" => '{"child":"val"}'}, {"key" => "b", "value" => "\"some_string\""}])
505
+ end
506
+ end
507
+
499
508
  context "with multiple activations" do
500
- let(:payload) { [{"end" => 1476818509288, "activationId" => "1"},{"end" => 1476818509289, "activationId" => "2"},{"end" => 1476818509287, "activationId" => "3"} ] }
509
+ let(:payload) { [{"end" => 1476818509288, "activationId" => "1", "annotations" => []},{"end" => 1476818509289, "activationId" => "2", "annotations" => []},{"end" => 1476818509287, "activationId" => "3", "annotations" => []} ] }
501
510
 
502
511
  it "should update logs since to latest epoch" do
503
512
  instance.instance_variable_set("@logs_since", 0)
@@ -509,7 +518,7 @@ describe LogStash::Inputs::OpenWhisk do
509
518
  end
510
519
 
511
520
  context "with previous activations" do
512
- let(:payload) { [{"end" => 1476818509288, "activationId" => "some_id"}] }
521
+ let(:payload) { [{"end" => 1476818509288, "activationId" => "some_id", "annotations" => []}] }
513
522
 
514
523
  subject(:size) {
515
524
  queue.size()
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-input-openwhisk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Thomas
@@ -160,7 +160,7 @@ files:
160
160
  - lib/logstash/inputs/openwhisk.rb
161
161
  - logstash-input-openwhisk.gemspec
162
162
  - spec/inputs/openwhisk_spec.rb
163
- homepage: http://www.elastic.co/guide/en/logstash/current/index.html
163
+ homepage: http://github.com/jthomas/logstash-input-openwhisk
164
164
  licenses:
165
165
  - Apache License (2.0)
166
166
  metadata: