Skip to content

Commit

Permalink
Update to plugin v2.0 api
Browse files Browse the repository at this point in the history
  • Loading branch information
ph committed May 3, 2016
1 parent 028de91 commit 558eaed
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 10 deletions.
6 changes: 5 additions & 1 deletion .travis.yml
@@ -1,6 +1,10 @@
---
sudo: false
language: ruby
cache: bundler
rvm:
- jruby-1.7.22
- jruby-1.7.25
script: bundle exec rspec spec && bundle exec rspec spec --tag integration
jdk: oraclejdk8
before_install:
- git clone -b feature/event_interface https://github.com/elastic/logstash
8 changes: 8 additions & 0 deletions Gemfile
@@ -1,2 +1,10 @@
source 'https://rubygems.org'
gemspec

gem "logstash-core", :path => "./logstash/logstash-core"
gem "logstash-core-plugin-api", :path => "./logstash/logstash-core-plugin-api"
gem "logstash-core-event-java", :path => "./logstash/logstash-core-event-java"
gem "logstash-devutils", :github => "elastic/logstash-devutils", :branch => "feature/plugin-api-2_0"
gem "logstash-codec-plain", :github => "logstash-plugins/logstash-codec-plain", :branch => "feature/plugin-api-2_0"
gem "logstash-codec-json", :github => "logstash-plugins/logstash-codec-json", :branch => "feature/plugin-api-2_0"
gem "logstash-mixin-http_client", :github => "logstash-plugins/logstash-mixin-http_client", :branch => "feature/plugin-api-2_0"
6 changes: 3 additions & 3 deletions lib/logstash/inputs/http_poller.rb
Expand Up @@ -194,13 +194,13 @@ def handle_failure(queue, name, request, exception, execution_time)

# This is also in the metadata, but we send it anyone because we want this
# persisted by default, whereas metadata isn't. People don't like mysterious errors
event["http_request_failure"] = {
event.set("http_request_failure", {
"request" => structure_request(request),
"name" => name,
"error" => exception.to_s,
"backtrace" => exception.backtrace,
"runtime_seconds" => execution_time
}
})

queue << event
rescue StandardError, java.lang.Exception => e
Expand All @@ -216,7 +216,7 @@ def handle_failure(queue, name, request, exception, execution_time)
private
def apply_metadata(event, name, request, response=nil, execution_time=nil)
return unless @metadata_target
event[@metadata_target] = event_metadata(name, request, response, execution_time)
event.set(@metadata_target, event_metadata(name, request, response, execution_time))
end

private
Expand Down
2 changes: 1 addition & 1 deletion logstash-input-http_poller.gemspec
Expand Up @@ -18,7 +18,7 @@ Gem::Specification.new do |s|
s.metadata = { "logstash_plugin" => "true", "logstash_group" => "input" }

# Gem dependencies
s.add_runtime_dependency "logstash-core-plugin-api", "~> 1.0"
s.add_runtime_dependency "logstash-core-plugin-api", "~> 2.0"
s.add_runtime_dependency 'logstash-codec-plain'
s.add_runtime_dependency 'logstash-mixin-http_client', ">= 2.2.4", "< 3.0.0"
s.add_runtime_dependency 'stud', "~> 0.0.22"
Expand Down
10 changes: 5 additions & 5 deletions spec/inputs/http_poller_spec.rb
Expand Up @@ -153,7 +153,7 @@

describe "events" do
shared_examples("matching metadata") {
let(:metadata) { event[metadata_target] }
let(:metadata) { event.get(metadata_target) }

it "should have the correct name" do
expect(metadata["name"]).to eql(name)
Expand Down Expand Up @@ -191,11 +191,11 @@
end

it "should enqueue a message with 'http_request_failure' set" do
expect(event["http_request_failure"]).to be_a(Hash)
expect(event.get("http_request_failure")).to be_a(Hash)
end

it "should tag the event with '_http_request_failure'" do
expect(event["tags"]).to include('_http_request_failure')
expect(event.get("tags")).to include('_http_request_failure')
end

it "should invoke handle failure exactly once" do
Expand Down Expand Up @@ -276,7 +276,7 @@

it "should not have any metadata on the event" do
instance.send(:run_once, queue)
expect(event[metadata_target]).to be_nil
expect(event.get(metadata_target)).to be_nil
end
end

Expand Down Expand Up @@ -316,7 +316,7 @@
# When events go through the pipeline they are java-ified
# this normalizes the payload to java types
payload_normalized = LogStash::Json.load(LogStash::Json.dump(payload))
expect(event[target]).to include(payload_normalized)
expect(event.get(target)).to include(payload_normalized)
end
end
end
Expand Down

0 comments on commit 558eaed

Please sign in to comment.