fluent-plugin-mesosphere-filter 0.1.6 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NjYxZWVmZDQzNDc2MTRmN2Y2YTcwMWQ1NDExM2ZjMjY4YzRjYjgzYQ==
4
+ YjI3ZjFmNGQxNmE0NWRkN2M0YWIzM2Q2MTU3OGRmYTE4ZTg5MmMxYg==
5
5
  data.tar.gz: !binary |-
6
- ODY0YWJlZWZkYTc5MmM4NDI5MjhjMzU5NGUzMjE1NGExZDM2MzZhNA==
6
+ NGY0OWIwMjA4OTZhYWE0Mjk3MmQxMWQ0MjViMmY5ZDFhYWNjM2UzNA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NGE3OGM2NTAzYjgwMTZlZmM4OTUwYWMxNTVmYmFmOTMyYWY0NzUyNDgxMDJm
10
- OTZmMThlNTM1ZTY5ZWI4MThhNjQzN2RhZjYyOTU4NzQ4M2RjZDUxZTY3NTUy
11
- NDVjNzczZTQ0YmY5ZGY4NTk1MWMzZTA1NGM5MjgxZjM4NGNiNmQ=
9
+ NDZlY2JlZTM0Njc5ZjZhNmM2ZjYyMTllOTRmMGNlMzZiMTMzOWVmNTQ2MTY1
10
+ YjEwMTQwMWY2M2RjMzA4YWY1OWQ3NzlhZWNkMTFjMWNjZDA0NmQ2M2QyZmE2
11
+ MDBhNjk4NmZjZjc0YWVlNWIyOGFhZWFlZmE4OThhNDY2NjQ4ZWI=
12
12
  data.tar.gz: !binary |-
13
- NTJkMDY4YjkyMDc5YTdiZjEwMDZlOTk3YTY2NWVkMzM5ZjIyYThlMmJlNmU3
14
- ZDMxNmJjYWM0OWM1MTY0MWM2ZTU0MzIzYzhlMjBkMTI2OTQ3ODhhNjIxOTA5
15
- ODVjODM5MDk5NWFhYjY2YjdiMGExMGI5MDcyMTUwOWMzZDE5ODM=
13
+ ODM3OTRkZmY4YjdiYmM0YzE0NGQ1NjQ4ZDc1OWNhNzk1YTI2NGMxMTlkMmNl
14
+ M2MyMDhmNDRmMzhmMjFhYTFiN2NkODRjMGEzMGZlOGM0YjIyOGMwNzdhY2I2
15
+ MDc3Yzg4ZDI1YWUwYTkyMjI2N2FkZDk1ZTY2NzMzOWM3NWYyNmE=
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |gem|
6
6
  gem.name = 'fluent-plugin-mesosphere-filter'
7
- gem.version = '0.1.6'
7
+ gem.version = '0.1.7'
8
8
  gem.authors = ['Joseph Hughes']
9
9
  gem.email = ['jjhughes57@gmail.com']
10
10
  gem.description = 'Filter plugin to add Mesosphere metadata'
@@ -26,10 +26,11 @@ module Fluent
26
26
  config_param :get_container_id_tag, :bool, default: true
27
27
  config_param :container_id_attr, :string, default: 'container_id'
28
28
 
29
+ config_param :timestamp_key, :string, default: '@timestamp'
29
30
  config_param :merge_json_log, :bool, default: true
30
31
  config_param :cronos_task_regex,
31
32
  :string,
32
- default: '(?<app>[a-z0-9]([-a-z0-9_]*[a-z0-9_]))-(?<date>[^-]+)-(?<time>[^-]+)-(?<task_type>[^-]+)-(?<run>[^-]+)-(?<epoc>[^-]+)'
33
+ default: '^(?<app>[a-z0-9]([-a-z0-9.]*[a-z0-9]))-(?<date>[^-]+)-(?<time>[^-]+)-(?<task_type>[^-]+)-(?<run>[^-]+)-(?<epoc>[^-]+)$'
33
34
 
34
35
  # Get the configuration for the plugin
35
36
  def configure(conf)
@@ -38,6 +39,7 @@ module Fluent
38
39
  require 'docker-api'
39
40
  require 'lru_redux'
40
41
  require 'oj'
42
+ require 'time'
41
43
 
42
44
  @cache_ttl = :none if @cache_ttl < 0
43
45
 
@@ -45,7 +47,7 @@ module Fluent
45
47
 
46
48
  @chronos_task_regex_compiled = Regexp.compile(@cronos_task_regex)
47
49
 
48
- marathon_regex = '\/(?<app>[a-z0-9]([-a-z0-9_]*[a-z0-9_]))'
50
+ marathon_regex = '\/(?<app>[a-z0-9]([-a-z0-9_.]*[a-z0-9_.]))'
49
51
  @marathon_app_regex_compiled = Regexp.compile(marathon_regex)
50
52
  end
51
53
 
@@ -61,11 +63,23 @@ module Fluent
61
63
  container_id =
62
64
  get_container_id_from_record(record) if container_id.empty?
63
65
  next unless container_id
66
+ record[@timestamp_key] = generate_time_stamp(time)
64
67
  new_es.add(time, modify_record(record, get_mesos_data(container_id)))
65
68
  end
66
69
  new_es
67
70
  end
68
71
 
72
+ # Generates a timestamp that the elasticsearch plugin can understand.
73
+ #
74
+ # ==== Attributes:
75
+ # * +time+ - A time record from the event stream
76
+ # ==== Returns:
77
+ # * A string with the correct datatime format for the elasticsearch plugin
78
+ # to consume
79
+ def generate_time_stamp(time)
80
+ Time.at(time).utc.strftime('%Y-%m-%dT%H:%M:%S%z')
81
+ end
82
+
69
83
  # Injects the meso framework data into the record and also merges
70
84
  # the json log if that configuration is enabled.
71
85
  #
@@ -65,6 +65,26 @@ class AmplifierFilterTest < Test::Unit::TestCase
65
65
  assert_equal task_id, log_entry['mesos_task_id']
66
66
  end
67
67
 
68
+ def test_timestamp
69
+ setup_marathon_container('foobar123', 'marathon')
70
+ time_string = ''
71
+ filtered = {}
72
+ Timecop.freeze(Time.now) do
73
+ d1 = create_driver(CONFIG, 'docker.foobar123')
74
+ d1.run do
75
+ 1000.times do
76
+ d1.filter('log' => 'Hello World 4')
77
+ end
78
+ end
79
+ time_string = Time.now.utc.strftime('%Y-%m-%dT%H:%M:%S%z')
80
+ filtered = d1.filtered_as_array
81
+ end
82
+
83
+ log_entry = filtered[0][2]
84
+
85
+ assert_equal time_string, log_entry['@timestamp']
86
+ end
87
+
68
88
  def test_container_cache
69
89
  setup_marathon_container('foobar123', 'marathon')
70
90
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-mesosphere-filter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joseph Hughes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-29 00:00:00.000000000 Z
11
+ date: 2015-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd