fluent-plugin-prometheus 1.2.0 → 1.2.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
- SHA1:
3
- metadata.gz: da342f3a63fc1bb0e727eb1910c7b13734600dd2
4
- data.tar.gz: 46ec363b48352bad9e781695d7358172f06fb5c0
2
+ SHA256:
3
+ metadata.gz: 64ed448a556ffbc5fda04297363a53663dc2acff960d358bb24b07e227b99b3a
4
+ data.tar.gz: 2ad3f13b35c60b0fad6664831e9d4edcacfcf963a3a819c658aad761bc64af2f
5
5
  SHA512:
6
- metadata.gz: 771b4c6ee4ded81623869e6339b1f3ce56913a0042e82eeef210cba9825e3f0a5b6a2c071a884b7d4ad54e0689eaa4654f916cf797db4de7514dea21de2d2ee0
7
- data.tar.gz: ca7cc8da3dd94f4b3976901f471cb1238813210109e0e05932f58991d353c8bd289ba2633144a1094f41ec14164ab3a04557a0f20ad0f6c07a5d99ad3f53553c
6
+ metadata.gz: cb6b43bf8e18dea2ff324a1a75738b51513c652ca3afdea8bf941f5d56e0b44028d19726daef5ee704070597e243e0c5262db1edaf6027adb3f1a2f6baf3c76a
7
+ data.tar.gz: 0dd07480d6a1a4db6345e14727f932b1c2ce09ce9683f01f4fe4c3e008c608742ef47a68aca27371f182dc1b8cd995420bef3a4d666abe6ff0ec6ed218513916
data/README.md CHANGED
@@ -339,9 +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
343
 
344
- 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`.
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.
345
347
 
346
348
  Reserved placeholders are:
347
349
 
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "fluent-plugin-prometheus"
3
- spec.version = "1.2.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.}
@@ -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)
@@ -18,7 +18,13 @@ module Fluent
18
18
  labels.first.each do |key, value|
19
19
  labels.first.has_key?(key)
20
20
 
21
- base_labels[key.to_sym] = PluginHelper::RecordAccessor::Accessor.new(value)
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
22
28
  end
23
29
  end
24
30
 
@@ -102,8 +108,11 @@ module Fluent
102
108
  def labels(record, expander, placeholders)
103
109
  label = {}
104
110
  @base_labels.each do |k, v|
105
- accessor_value = v.call(record)
106
- label[k] = accessor_value.nil? ? expander.expand(v.keys, placeholders) : accessor_value
111
+ if v.is_a?(String)
112
+ label[k] = expander.expand(v, placeholders)
113
+ else
114
+ label[k] = v.call(record)
115
+ end
107
116
  end
108
117
  label
109
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.2.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-11-01 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
@@ -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
@@ -151,12 +152,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
151
152
  version: '0'
152
153
  requirements: []
153
154
  rubyforge_project:
154
- rubygems_version: 2.6.14.1
155
+ rubygems_version: 2.7.6
155
156
  signing_key:
156
157
  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