fluent-plugin-prometheus 1.1.0 → 1.2.1

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
  SHA256:
3
- metadata.gz: bc058ef050bbdee33044783899fc6af14b731d974cb5f2b827997683a82ddb85
4
- data.tar.gz: aef907fc671770e55a4fb1cad4de41b09c6a0b053b6fbcc5fbde8193d71faa0d
3
+ metadata.gz: 64ed448a556ffbc5fda04297363a53663dc2acff960d358bb24b07e227b99b3a
4
+ data.tar.gz: 2ad3f13b35c60b0fad6664831e9d4edcacfcf963a3a819c658aad761bc64af2f
5
5
  SHA512:
6
- metadata.gz: 4888508f00beb7f8654e7139f1d26962e1f3a2193b81a97b4f874a61d82ea759bde7f14558fba123565a01758478d6e30aad46937e7715bed8489099424579de
7
- data.tar.gz: ea29389ae6b63bf8a8f20124d7cd8651f88dbe45db66e40a74eecc2ce73762f400385ae73adf8074a2e8733cb132340233f282cb1d27aecfb627fbdd7e9bd468
6
+ metadata.gz: cb6b43bf8e18dea2ff324a1a75738b51513c652ca3afdea8bf941f5d56e0b44028d19726daef5ee704070597e243e0c5262db1edaf6027adb3f1a2f6baf3c76a
7
+ data.tar.gz: 0dd07480d6a1a4db6345e14727f932b1c2ce09ce9683f01f4fe4c3e008c608742ef47a68aca27371f182dc1b8cd995420bef3a4d666abe6ff0ec6ed218513916
data/README.md CHANGED
@@ -339,7 +339,11 @@ You can add labels with static value or dynamic value from records. In `promethe
339
339
 
340
340
  All labels sections has same format. Each lines have key/value for label.
341
341
 
342
- You can use placeholder for label values. The placeholders will be expanded from records or reserved values. If you specify `${foo}`, it will be expanded by value of `foo` in record.
342
+ You can access nested fields in records via dot or bracket notation (https://docs.fluentd.org/v1.0/articles/api-plugin-helper-record_accessor#syntax), for example: `$.kubernetes.namespace`, `$['key1'][0]['key2']`. The record accessor is enable only if the value starts with `$.` or `$[`. Other values are handled as raw string as is and may be expanded by placeholder described later.
343
+
344
+ You can use placeholder for label values. The placeholders will be expanded from reserved values and records.
345
+ If you specify `${hostname}`, it will be expanded by value of a hostname where fluentd runs.
346
+ The placeholder for records is deprecated. Use record accessor syntax instead.
343
347
 
344
348
  Reserved placeholders are:
345
349
 
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "fluent-plugin-prometheus"
3
- spec.version = "1.1.0"
3
+ spec.version = "1.2.1"
4
4
  spec.authors = ["Masahiro Sano"]
5
5
  spec.email = ["sabottenda@gmail.com"]
6
6
  spec.summary = %q{A fluent plugin that collects metrics and exposes for Prometheus.}
@@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
13
13
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
14
14
  spec.require_paths = ["lib"]
15
15
 
16
- spec.add_dependency "fluentd", ">= 0.14.8", "< 2"
16
+ spec.add_dependency "fluentd", ">= 0.14.20", "< 2"
17
17
  spec.add_dependency "prometheus-client"
18
18
  spec.add_development_dependency "bundler"
19
19
  spec.add_development_dependency "rake"
@@ -27,7 +27,9 @@ module Fluent::Plugin
27
27
  placeholders = expander.prepare_placeholders({'hostname' => hostname, 'worker_id' => fluentd_worker_id})
28
28
  @base_labels = Fluent::Plugin::Prometheus.parse_labels_elements(conf)
29
29
  @base_labels.each do |key, value|
30
- @base_labels[key] = expander.expand(value, placeholders)
30
+ if value.is_a?(String)
31
+ @base_labels[key] = expander.expand(value, placeholders)
32
+ end
31
33
  end
32
34
 
33
35
  if defined?(Fluent::Plugin) && defined?(Fluent::Plugin::MonitorAgentInput)
@@ -17,7 +17,14 @@ module Fluent
17
17
  unless labels.empty?
18
18
  labels.first.each do |key, value|
19
19
  labels.first.has_key?(key)
20
- base_labels[key.to_sym] = value
20
+
21
+ # use RecordAccessor only for $. and $[ syntax
22
+ # otherwise use the value as is or expand the value by RecordTransformer for ${} syntax
23
+ if value.start_with?('$.') || value.start_with?('$[')
24
+ base_labels[key.to_sym] = PluginHelper::RecordAccessor::Accessor.new(value)
25
+ else
26
+ base_labels[key.to_sym] = value
27
+ end
21
28
  end
22
29
  end
23
30
 
@@ -101,7 +108,11 @@ module Fluent
101
108
  def labels(record, expander, placeholders)
102
109
  label = {}
103
110
  @base_labels.each do |k, v|
104
- label[k] = expander.expand(v, placeholders)
111
+ if v.is_a?(String)
112
+ label[k] = expander.expand(v, placeholders)
113
+ else
114
+ label[k] = v.call(record)
115
+ end
105
116
  end
106
117
  label
107
118
  end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+ require 'fluent/plugin/in_prometheus_monitor'
3
+ require 'fluent/test/driver/input'
4
+
5
+ describe Fluent::Plugin::PrometheusMonitorInput do
6
+ MONITOR_CONFIG = %[
7
+ @type prometheus_monitor
8
+ <labels>
9
+ host ${hostname}
10
+ foo bar
11
+ no_effect1 $.foo.bar
12
+ no_effect2 $[0][1]
13
+ </labels>
14
+ ]
15
+
16
+ let(:config) { MONITOR_CONFIG }
17
+ let(:port) { 24231 }
18
+ let(:driver) { Fluent::Test::Driver::Input.new(Fluent::Plugin::PrometheusMonitorInput).configure(config) }
19
+
20
+ describe '#configure' do
21
+ it 'does not raise error' do
22
+ expect{driver}.not_to raise_error
23
+ end
24
+ end
25
+ end
@@ -73,6 +73,18 @@ PLACEHOLDER_CONFIG = BASE_CONFIG + %[
73
73
  </labels>
74
74
  ]
75
75
 
76
+ ACCESSOR_CONFIG = BASE_CONFIG + %[
77
+ <metric>
78
+ name accessor_foo
79
+ type counter
80
+ desc Something foo.
81
+ key foo
82
+ <labels>
83
+ foo $.foo
84
+ </labels>
85
+ </metric>
86
+ ]
87
+
76
88
  COUNTER_WITHOUT_KEY_CONFIG = BASE_CONFIG + %[
77
89
  <metric>
78
90
  name without_key_foo
@@ -107,6 +119,13 @@ shared_context 'placeholder_config' do
107
119
  let(:counter) { registry.get(name) }
108
120
  end
109
121
 
122
+ shared_context 'accessor_config' do
123
+ let(:orig_name) { 'accessor_foo' }
124
+ let(:config) { ACCESSOR_CONFIG.gsub(orig_name, name.to_s) }
125
+ let(:name) { "#{orig_name}_#{gen_time_suffix}".to_sym }
126
+ let(:counter) { registry.get(name) }
127
+ end
128
+
110
129
  shared_context 'counter_without_key_config' do
111
130
  let(:orig_name) { 'without_key_foo' }
112
131
  let(:config) { COUNTER_WITHOUT_KEY_CONFIG.gsub(orig_name, name.to_s) }
@@ -137,6 +156,11 @@ shared_examples_for 'output configuration' do
137
156
  it { expect{driver}.not_to raise_error }
138
157
  end
139
158
 
159
+ describe 'configure accessor configuration' do
160
+ include_context 'accessor_config'
161
+ it { expect{driver}.not_to raise_error }
162
+ end
163
+
140
164
  describe 'configure counter without key configuration' do
141
165
  include_context 'counter_without_key_config'
142
166
  it { expect{driver}.not_to raise_error }
@@ -217,6 +241,22 @@ shared_examples_for 'instruments record' do
217
241
  end
218
242
  end
219
243
 
244
+ context 'accessor config' do
245
+ include_context 'accessor_config'
246
+
247
+ before :each do
248
+ es
249
+ end
250
+
251
+ it 'expands accessor with record values' do
252
+ expect(registry.metrics.map(&:name)).to include(name)
253
+ expect(counter).to be_kind_of(::Prometheus::Client::Metric)
254
+ key, _ = counter.values.find {|k,v| v == 100 }
255
+ expect(key).to be_kind_of(Hash)
256
+ expect(key[:foo]).to eq(100)
257
+ end
258
+ end
259
+
220
260
  context 'counter_without config' do
221
261
  include_context 'counter_without_key_config'
222
262
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-prometheus
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masahiro Sano
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-09 00:00:00.000000000 Z
11
+ date: 2018-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd
@@ -16,7 +16,7 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.14.8
19
+ version: 0.14.20
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
22
  version: '2'
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: 0.14.8
29
+ version: 0.14.20
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '2'
@@ -127,6 +127,7 @@ files:
127
127
  - misc/prometheus.yaml
128
128
  - misc/prometheus_alerts.yaml
129
129
  - spec/fluent/plugin/filter_prometheus_spec.rb
130
+ - spec/fluent/plugin/in_prometheus_monitor_spec.rb
130
131
  - spec/fluent/plugin/out_prometheus_spec.rb
131
132
  - spec/fluent/plugin/prometheus_spec.rb
132
133
  - spec/fluent/plugin/shared.rb
@@ -157,6 +158,7 @@ specification_version: 4
157
158
  summary: A fluent plugin that collects metrics and exposes for Prometheus.
158
159
  test_files:
159
160
  - spec/fluent/plugin/filter_prometheus_spec.rb
161
+ - spec/fluent/plugin/in_prometheus_monitor_spec.rb
160
162
  - spec/fluent/plugin/out_prometheus_spec.rb
161
163
  - spec/fluent/plugin/prometheus_spec.rb
162
164
  - spec/fluent/plugin/shared.rb