fluent-plugin-viaq_data_model 0.0.1 → 0.0.2

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,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ffc8861a24c80f6044ffe80d9e38c5f675a46554
4
- data.tar.gz: 26a1dfb59dfacaac6975c8a76ef03aff6896380e
3
+ metadata.gz: f4ecf55fa6bf6e1001738e41876a8ba70f4fee67
4
+ data.tar.gz: 88d75546acb5b4db61dc09046a7873a2382c60d7
5
5
  SHA512:
6
- metadata.gz: 5b7314c78d6b2443aff7d31f5008e95dd2dad8192e248cd1a34d09f31c7828aef16d94fd4e7a4effd283b627ef2a6f641ee014cf6fa9e1fe5acfc0937246fd99
7
- data.tar.gz: b118bb6a73721dbb05e82492222b03530722ad6539bd10026bdc66a051fc5f9a2a8fa7772838b2ec2c81450f7edec100a1461096a5c77f472ef26b0e6e980c3a
6
+ metadata.gz: 9f2fd967b4d57cb6afe9c8a46d723e8e30c53f71a056bdb436e6fceb5dad489c52a8eded2068d95c6ccb47f7deb728f6a5d2b568034cc29d7cb8e3e11a9e4503
7
+ data.tar.gz: af3c09cabf0b8ece8a659bb8c1116be62d53f90da62768ccdc2d6be2cc87ce257fb12e051f1cd9d52565e29344c40e5f6aa4cebaee34f5ac70d60dccda27badb
data/.travis.yml ADDED
@@ -0,0 +1,12 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 2.1
5
+ - 2.2
6
+ - 2.3.1
7
+
8
+ gemfile:
9
+ - Gemfile
10
+
11
+ script: bundle exec rake test
12
+ sudo: false
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'codeclimate-test-reporter', :group => :test, :require => nil
4
+ gem 'rubocop', require: false
5
+
6
+ # Specify your gem's dependencies in fluent-plugin-add.gemspec
7
+ gemspec
data/README.md CHANGED
@@ -1,2 +1,118 @@
1
- # fluent-plugin-viaq_data_model
2
- helps format records into viaq data model
1
+ # fluent-plugin-viaq_data_model - a ViaQ data model filter plugin for [Fluentd](http://fluentd.org)
2
+ [![Travis CI](https://secure.travis-ci.org/ViaQ/fluent-plugin-viaq_data_model.png)](http://travis-ci.org/#!/ViaQ/fluent-plugin-viaq_data_model)
3
+
4
+ ## Introduction
5
+
6
+ This plugin formats Fluentd records in the proper [ViaQ data
7
+ model](https://github.com/ViaQ/elasticsearch-templates). It does the
8
+ following:
9
+
10
+ * Removes empty fields
11
+ * fields with a value of `nil`
12
+ * string fields with a value of `''` or the empty string
13
+ * hash valued fields with a value of `{}`
14
+ * hash valued fields which contain only empty fields as described above
15
+ * FixNum, Boolean and other field values are not removed - type must respond
16
+ to `:empty?` to be considered empty
17
+
18
+ * Moves "undefined" values to a top level field called `undefined`
19
+
20
+ The ViaQ data model wants all top level fields defined and described. These
21
+ can conflict with the fields defined by ViaQ. You can "move" these fields to
22
+ be under a hash valued top level field called `undefined` so as not to conflict
23
+ with the "well known" ViaQ top level fields. You can optionally keep some
24
+ fields as top level fields while moving others to the `undefined` container.
25
+
26
+ * Rename a time field to `@timestamp`
27
+
28
+ You cannot set the `@timestamp` field in a Fluentd `record_transformer` filter.
29
+ The plugin allows you to use some other field e.g. `time` and have that "moved"
30
+ to a top level field called `@timestamp`.
31
+
32
+ ## Configuration
33
+
34
+ NOTE: All fields are Optional - no required fields.
35
+
36
+ See `filter-viaq_data_model.conf` for an example filter configuration.
37
+
38
+ * `default_keep_fields` - comma delimited string - default: `''`
39
+ * This is the default list of fields to keep as top level fields in the record
40
+ * `default_keep_fields message,@timestamp,ident` - do not move these fields into the `undefined` field
41
+ * `extra_keep_fields` - comma delimited string - default: `''`
42
+ * This is an extra list of fields to keep in addition to
43
+ `default_keep_fields` - mostly useful as a way to hard code the
44
+ `default_keep_fields` list for configuration management purposes, but at the
45
+ same time allow customization in certain cases
46
+ * `extra_keep_fields myspecialfield1,myspecialfield2`
47
+ * `keep_empty_fields` - comma delimited string - default `''`
48
+ * Always keep these top level fields, even if they are empty
49
+ * `keep_empty_fields message` - keep the `message` field, even if empty
50
+ * `use_undefined` - boolean - default `false`
51
+ * If `true`, move fields not specified in `default_keep_fields` and
52
+ `extra_keep_fields` to the `undefined` top level field. If you use
53
+ `use_undefined` you should specify the fields you want to keep out of
54
+ `undefined` by using `default_keep_fields` and/or `extra_keep_fields`
55
+ * `undefined_name` - string - default `"undefined"`
56
+ * Name of undefined top level field to use if `use_undefined true` is set
57
+ * `undefined_name myfields` - keep undefined fields under field `myfields`
58
+ * `rename_time` - boolean - default `true`
59
+ * Rename the time field e.g. when you need to set `@timestamp` in the record
60
+ * NOTE: This will overwrite the `dest_time_name` if already set
61
+ * `rename_time_if_missing` - boolean - default `false`
62
+ * Rename the time field only if it is not present. For example, if some
63
+ records already have the `@timestamp` field and you do not want to overwrite
64
+ them, use `rename_time_if_missing true`
65
+ * `src_time_name` - string - default `time`
66
+ * Use this field to get the value of the time field in the resulting record.
67
+ This field will be removed from the record.
68
+ * NOTE: This field must be present in the `default_keep_fields` or
69
+ `extra_keep_fields` if `use_undefined true`
70
+ * `dest_time_name` - string - default `@timestamp`
71
+ * This is the name of the top level field to hold the time value. The value
72
+ is taken from the value of the `src_time_name` field.
73
+
74
+ ## Example
75
+
76
+ If the input record looks like this:
77
+
78
+ {
79
+ "a": "b",
80
+ "c": "d",
81
+ "e": '',
82
+ "f": {
83
+ "g": '',
84
+ "h": {}
85
+ },
86
+ "i": {
87
+ "j": 0,
88
+ "k": False,
89
+ "l": ''
90
+ },
91
+ "time": "2017-02-13 15:30:10.259106596-07:00"
92
+ }
93
+
94
+ The resulting record, using the defaults, would look like this:
95
+
96
+ {
97
+ "a": "b",
98
+ "c": "d",
99
+ "i": {
100
+ "j": 0,
101
+ "k": False,
102
+ },
103
+ "@timestamp": "2017-02-13 15:30:10.259106596-07:00"
104
+ }
105
+
106
+
107
+ ## Installation
108
+
109
+ gem install fluent-plugin-viaq_data_model
110
+
111
+ ## Contributing
112
+
113
+ 1. Fork it
114
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
115
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
116
+ 4. Test it (`GEM_HOME=vendor bundle install; GEM_HOME=vendor bundle exec rake test`)
117
+ 5. Push to the branch (`git push origin my-new-feature`)
118
+ 6. Create new Pull Request
@@ -6,6 +6,7 @@
6
6
  use_undefined "#{ENV['CDM_USE_UNDEFINED'] || false}"
7
7
  undefined_name "#{ENV['CDM_UNDEFINED_NAME'] || 'undefined'}"
8
8
  rename_time "#{ENV['CDM_RENAME_TIME'] || true}"
9
+ rename_time_if_missing "#{ENV['CDM_RENAME_TIME_IF_MISSING'] || false}"
9
10
  src_time_name "#{ENV['CDM_SRC_TIME_NAME'] || 'time'}"
10
11
  dest_time_name "#{ENV['CDM_DEST_TIME_NAME'] || '@timestamp'}"
11
12
  </filter>
@@ -4,12 +4,12 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |gem|
6
6
  gem.name = "fluent-plugin-viaq_data_model"
7
- gem.version = "0.0.1"
7
+ gem.version = "0.0.2"
8
8
  gem.authors = ["Rich Megginson"]
9
9
  gem.email = ["rmeggins@redhat.com"]
10
10
  gem.description = %q{Filter plugin to ensure data is in the ViaQ common data model}
11
11
  gem.summary = %q{Filter plugin to ensure data is in the ViaQ common data model}
12
- gem.homepage = "https://github.com/ViaQ/fluent-plugin-viaq_data_mode"
12
+ gem.homepage = "https://github.com/ViaQ/fluent-plugin-viaq_data_model"
13
13
  gem.license = "Apache-2.0"
14
14
 
15
15
  gem.files = `git ls-files`.split($/)
@@ -1,3 +1,20 @@
1
+ #
2
+ # Fluentd ViaQ data model Filter Plugin
3
+ #
4
+ # Copyright 2017 Red Hat, Inc.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
1
18
  require 'fluent/filter'
2
19
  require 'fluent/log'
3
20
 
@@ -33,6 +50,9 @@ module Fluent
33
50
  desc 'Rename timestamp field to Elasticsearch compatible name'
34
51
  config_param :rename_time, :bool, default: true
35
52
 
53
+ desc 'Rename timestamp field to Elasticsearch compatible name only if the destination field does not already exist'
54
+ config_param :rename_time_if_missing, :bool, default: false
55
+
36
56
  desc 'Name of source timestamp field'
37
57
  config_param :src_time_name, :string, default: 'time'
38
58
 
@@ -53,7 +73,7 @@ module Fluent
53
73
  if @use_undefined && @keep_fields.key?(@undefined_name)
54
74
  raise Fluent::ConfigError, "Do not put [#{@undefined_name}] in default_keep_fields or extra_keep_fields"
55
75
  end
56
- if @rename_time && @use_undefined && !@keep_fields.key?(@src_time_name)
76
+ if (@rename_time || @rename_time_if_not_exist) && @use_undefined && !@keep_fields.key?(@src_time_name)
57
77
  raise Fluent::ConfigError, "Field [#{@src_time_name}] must be listed in default_keep_fields or extra_keep_fields"
58
78
  end
59
79
  end
@@ -102,8 +122,11 @@ module Fluent
102
122
  # probably shouldn't remove everything . . .
103
123
  log.warn("Empty record! tag [#{tag}] time [#{time}]") if record.empty?
104
124
  # rename the time field
105
- if @rename_time && record.key?(@src_time_name)
106
- record[@dest_time_name] = record.delete(@src_time_name)
125
+ if (@rename_time || @rename_time_if_missing) && record.key?(@src_time_name)
126
+ val = record.delete(@src_time_name)
127
+ unless @rename_time_if_missing && record.key?(@dest_time_name)
128
+ record[@dest_time_name] = val
129
+ end
107
130
  end
108
131
  if ENV['CDM_DEBUG']
109
132
  unless tag == ENV['CDM_DEBUG_IGNORE_TAG']
@@ -164,6 +164,33 @@ class ViaqDataModelFilterTest < Test::Unit::TestCase
164
164
  assert_equal('b', rec['c'])
165
165
  assert_nil(rec['a'])
166
166
  end
167
+ test 'see if time field is renamed when checking if missing' do
168
+ rec = emit_with_tag('tag', {'a'=>'b'}, '
169
+ rename_time_if_missing true
170
+ src_time_name a
171
+ dest_time_name c
172
+ ')
173
+ assert_equal('b', rec['c'])
174
+ assert_nil(rec['a'])
175
+ end
176
+ test 'see if time field is renamed when already present' do
177
+ rec = emit_with_tag('tag', {'a'=>'b','c'=>'d'}, '
178
+ rename_time true
179
+ src_time_name a
180
+ dest_time_name c
181
+ ')
182
+ assert_equal('b', rec['c'])
183
+ assert_nil(rec['a'])
184
+ end
185
+ test 'see if time field is preserved when already present' do
186
+ rec = emit_with_tag('tag', {'a'=>'b','c'=>'d'}, '
187
+ rename_time_if_missing true
188
+ src_time_name a
189
+ dest_time_name c
190
+ ')
191
+ assert_equal('d', rec['c'])
192
+ assert_nil(rec['a'])
193
+ end
167
194
  test 'see if deeply nested empty fields are removed or preserved' do
168
195
  msg = {'a'=>{'b'=>{'c'=>{'d'=>{'e'=>'','f'=>{},'g'=>''}}}},'h'=>{'i'=>{'j'=>'','k'=>'l','m'=>99,'n'=>true}}}
169
196
  rec = emit_with_tag('tag', msg)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-viaq_data_model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rich Megginson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-13 00:00:00.000000000 Z
11
+ date: 2017-02-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd
@@ -116,6 +116,8 @@ extensions: []
116
116
  extra_rdoc_files: []
117
117
  files:
118
118
  - ".gitignore"
119
+ - ".travis.yml"
120
+ - Gemfile
119
121
  - LICENSE
120
122
  - README.md
121
123
  - Rakefile
@@ -124,7 +126,7 @@ files:
124
126
  - fluent-plugin-viaq_data_model.gemspec
125
127
  - lib/fluent/plugin/filter_viaq_data_model.rb
126
128
  - test/test_filter_viaq_data_model.rb
127
- homepage: https://github.com/ViaQ/fluent-plugin-viaq_data_mode
129
+ homepage: https://github.com/ViaQ/fluent-plugin-viaq_data_model
128
130
  licenses:
129
131
  - Apache-2.0
130
132
  metadata: {}