logstash-filter-docker_container 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: 1622d74b418ee109102656edde38f595b14fa112
4
- data.tar.gz: 784f7e6c23f0b874b3207d089f85286b7a7fe6a9
3
+ metadata.gz: b2cc55c3d6f9e8078a710db5fbd901b297ddd237
4
+ data.tar.gz: 949d74ea2a51e4f91cd8cf304782ad233c3f9244
5
5
  SHA512:
6
- metadata.gz: 043d0a774f01e72fb9e810b35a09ec741c9ae0ad51f994630ac3dd0008abf40acee9e5ea5e01aa90b759491747c91c1a70ad860b21acd3a5c9252c521cecbc57
7
- data.tar.gz: a083587689682b383597c4d8c5b648256940a9894402b6ce1188796840a8ad8747a69ddc42b5592ccfa6c298d0df8d994ea877270355bf5efbeb3ebf124a5c65
6
+ metadata.gz: 3dde8958c591688700178a63c40ae05496f1bd549e14416be6f975ee1953198de5ef5c6eaf1e88cb8546ef2b6f189aeb10ac371fdc9ea1a76c62d8c665b8cd74
7
+ data.tar.gz: 4422d701531969609f71dfa0453250bebc6e31304f3ec3ae0fa2cb0a6618576e7b8e80935ede591e324579c4f376d9c63e082964ab42ccdea39064566d1c2f43
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  require 'logstash/filters/base'
3
3
  require 'logstash/namespace'
4
- require 'lib/logstash/filters/docker_container/docker_container_inspector'
4
+ require 'logstash/filters/docker_container/docker_container_inspector'
5
5
  require 'json'
6
6
 
7
7
  class LogStash::Filters::DockerContainer < LogStash::Filters::Base
@@ -18,6 +18,7 @@ class LogStash::Filters::DockerContainer < LogStash::Filters::Base
18
18
  def register
19
19
  # Add instance variables
20
20
  @inspector = LogStash::Filters::DockerContainerSupport::DockerContainerInspector.new(@docker_client, @client_options)
21
+ @cached = Hash.new
21
22
  end # def register
22
23
 
23
24
  public
@@ -32,13 +33,17 @@ class LogStash::Filters::DockerContainer < LogStash::Filters::Base
32
33
  end
33
34
 
34
35
  def resolve_from(container_id)
36
+ if @cached.has_key?(container_id)
37
+ return @cached[container_id]
38
+ end
39
+
35
40
  blob = @inspector.inspect container_id
36
41
  details = JSON.parse(blob)
37
42
 
38
43
  return nil if details.empty?
39
44
 
40
45
  detail = details.first
41
- detail['Name']
46
+ @cached[container_id] = detail['Name']
42
47
 
43
48
  end # def filter
44
49
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'logstash-filter-docker_container'
3
- s.version = '0.1.0'
3
+ s.version = '0.1.1'
4
4
  s.licenses = ['Apache License (2.0)']
5
5
  s.summary = "Resolves Docker container IDs into the container's name."
6
6
  s.description = "With Docker's syslog log-driver the log entries contain just container ID, but seeing the name is even better"
@@ -9,7 +9,7 @@ describe LogStash::Filters::DockerContainer do
9
9
  allow(LogStash::Filters::DockerContainerSupport::DockerContainerInspector).to receive(:new).and_return(inspector)
10
10
  end
11
11
 
12
- describe "typical case" do
12
+ describe "typical case and cached" do
13
13
  let(:config) do <<-CONFIG
14
14
  filter {
15
15
  docker_container {
@@ -21,14 +21,18 @@ describe LogStash::Filters::DockerContainer do
21
21
 
22
22
  before do
23
23
  content = File.new(File.join(File.dirname(__FILE__),'container_logstash.json')).read()
24
- expect(inspector).to receive(:inspect)
24
+ # Due to caching of the Docker findings, the inspector should only be consulted once
25
+ # since the sample includes the same container ID both times
26
+ expect(inspector).to receive(:inspect).once
25
27
  .with('bd30193a3b9d')
26
28
  .and_return(content)
27
29
  end
28
30
 
29
- sample('container_id' => 'bd30193a3b9d') do
30
- expect(subject).to include('container_name')
31
- expect(subject['container_name']).to eq('/logstash')
31
+ sample([{'seq' => 1, 'container_id' => 'bd30193a3b9d'}, {'seq' => 2, 'container_id' => 'bd30193a3b9d'}]) do
32
+ subject.each do |e|
33
+ expect(e).to include('container_name')
34
+ expect(e['container_name']).to eq('/logstash')
35
+ end
32
36
  end
33
37
  end
34
38
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-filter-docker_container
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
  - Geoff Bourne
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-19 00:00:00.000000000 Z
11
+ date: 2015-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logstash-core