fluent-plugin-growthforecast 0.2.4 → 0.2.5

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: 865e153a44d5b24396037e62f80b811d3e8289a1
4
- data.tar.gz: 2482017862d4aa533da0f493c1447e5a7fefac73
3
+ metadata.gz: 772deca02038a2f899139be565322d168b3b199b
4
+ data.tar.gz: 9ecf9b2b47b1bfcbe4ceae8aa25b9d07b5c765a1
5
5
  SHA512:
6
- metadata.gz: c4be0e7f1b76d4edfc035b01f1d50aceef0a79890a715cd034b7a4bfef9497494f97db137a6795dd24eee73aefdf275077c714d4637322aa9f8f21893c5de8ea
7
- data.tar.gz: 6cadc77b0cb9c0611b106b0aa27d74a9d45974394bb269c0d1afa3cd7651b22e7caa8abbbd234403ba5060ef6c98dc65f999d4f5eb1a9d2ff600cd58d4085002
6
+ metadata.gz: 860093327616cabe40be6f9a6bdd8236c2fc4b29f0f6891d68339714fb74b5b535de5eede2a8cae357c0be963cf435e502d16052f5f0460dbbbac839f372b621
7
+ data.tar.gz: e88c43227e32d4b80cd93fee3bd0179149c1236e1739b194aebe88afa864e9e61e41cded15f1b87b6b952305d3c6235ce0bd08ba0f9f97c56bfecf312324a8e5
data/README.md CHANGED
@@ -58,6 +58,22 @@ If you want to use tags for `section` or `service` in GrowthForecast, use `tag_
58
58
 
59
59
  This configuration matches only with metrics.field1, metrics.key20, .... and doesn't match with metrics.field or metrics.foo.
60
60
 
61
+ If you want to customise for more flexible graph path, use `graph_path` option with `${tag}` and `${name}` placeholders.
62
+
63
+ <match test.service1>
64
+ type growthforecast
65
+ gfapi_url http://growthforecast.local/api/
66
+ graph_path ${tag}/metrics1/${tag}_${key_name}
67
+ name_keys field1,field2,field3diff
68
+ remove_prefix test
69
+ </match>
70
+
71
+ With this configuration, out_growthforecast posts urls below.
72
+
73
+ http://growthforecast.local/api/service1/metrics1/service1_field1
74
+ http://growthforecast.local/api/service1/metrics1/service1_field2
75
+ http://growthforecast.local/api/service1/metrics1/service1_field3diff
76
+
61
77
  If your GrowthForecast protected with basic authentication, specify `authentication` option:
62
78
 
63
79
  <match metrics.**>
@@ -82,12 +98,17 @@ Version v0.2.0 or later, this plugin uses HTTP connection keep-alive for a batch
82
98
  keepalive no
83
99
  </match>
84
100
 
101
+
85
102
  ## Parameters
86
103
 
87
104
  * gfapi\_url (required)
88
105
 
89
106
  The URL of a GrowthForecast API endpoint like `http://growth.forecast.local/api/`.
90
107
 
108
+ * graph\_path
109
+
110
+ The graph path for GrowthForecast API endpoint with the order of service, section, graph_name.
111
+
91
112
  * tag\_for
92
113
 
93
114
  Either of `name_prefix`, `section`, `service`, or `ignore`. Default is `name_prefix`.
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |gem|
4
4
  gem.name = "fluent-plugin-growthforecast"
5
- gem.version = "0.2.4"
5
+ gem.version = "0.2.5"
6
6
  gem.authors = ["TAGOMORI Satoshi"]
7
7
  gem.email = ["tagomoris@gmail.com"]
8
8
  gem.summary = %q{Fluentd output plugin to post numbers to GrowthForecast (by kazeburo)}
@@ -9,6 +9,7 @@ class Fluent::GrowthForecastOutput < Fluent::Output
9
9
  end
10
10
 
11
11
  config_param :gfapi_url, :string # growth.forecast.local/api/
12
+ config_param :graph_path, :string, :default => nil
12
13
  config_param :service, :string, :default => nil
13
14
  config_param :section, :string, :default => nil
14
15
  config_param :graphs, :string, :default => nil
@@ -35,12 +36,22 @@ class Fluent::GrowthForecastOutput < Fluent::Output
35
36
  config_param :username, :string, :default => ''
36
37
  config_param :password, :string, :default => ''
37
38
 
39
+ DEFAULT_GRAPH_PATH = {
40
+ :ignore => '${service}/${section}/${key_name}',
41
+ :service => '${tag}/${section}/${key_name}',
42
+ :section => '${service}/${tag}/${key_name}',
43
+ :name_prefix => '${service}/${section}/${tag}_${key_name}',
44
+ }
45
+
38
46
  def configure(conf)
39
47
  super
40
48
 
41
49
  if @gfapi_url !~ /\/api\/\Z/
42
50
  raise Fluent::ConfigError, "gfapi_url must end with /api/"
43
51
  end
52
+ if not @graph_path.nil? and @graph_path !~ /^[^\/]+\/[^\/]+\/[^\/]+$/
53
+ raise Fluent::ConfigError, "graph_path must be like '${service}/${section}/${tag}_${key_name}'"
54
+ end
44
55
 
45
56
  if @name_keys.nil? and @name_key_pattern.nil?
46
57
  raise Fluent::ConfigError, "missing both of name_keys and name_key_pattern"
@@ -72,6 +83,7 @@ class Fluent::GrowthForecastOutput < Fluent::Output
72
83
  else
73
84
  :gauge
74
85
  end
86
+
75
87
  @tag_for = case @tag_for
76
88
  when 'ignore' then :ignore
77
89
  when 'section' then :section
@@ -79,11 +91,14 @@ class Fluent::GrowthForecastOutput < Fluent::Output
79
91
  else
80
92
  :name_prefix
81
93
  end
82
- if @tag_for != :section and @section.nil?
83
- raise Fluent::ConfigError, "section parameter is needed when tag_for is not 'section'"
84
- end
85
- if @tag_for != :service and @service.nil?
86
- raise Fluent::ConfigError, "service parameter is needed when tag_for is not 'service'"
94
+ if @graph_path.nil?
95
+ if @tag_for != :section and @section.nil?
96
+ raise Fluent::ConfigError, "section parameter is needed when tag_for is not 'section'"
97
+ end
98
+ if @tag_for != :service and @service.nil?
99
+ raise Fluent::ConfigError, "service parameter is needed when tag_for is not 'service'"
100
+ end
101
+ @graph_path = DEFAULT_GRAPH_PATH[@tag_for]
87
102
  end
88
103
 
89
104
  if @remove_prefix
@@ -138,22 +153,17 @@ class Fluent::GrowthForecastOutput < Fluent::Output
138
153
  end
139
154
  end
140
155
 
141
- def format_url(tag, name)
156
+ def placeholder_mapping(tag, name)
142
157
  if @remove_prefix and
143
158
  ( (tag.start_with?(@removed_prefix_string) and tag.length > @removed_length) or tag == @remove_prefix)
144
159
  tag = tag[@removed_length..-1]
145
160
  end
161
+ {'${service}' => @service, '${section}' => @section, '${tag}' => tag, '${key_name}' => name}
162
+ end
146
163
 
147
- case @tag_for
148
- when :ignore
149
- @gfapi_url + URI.escape(@service + '/' + @section + '/' + name)
150
- when :section
151
- @gfapi_url + URI.escape(@service + '/' + tag + '/' + name)
152
- when :service
153
- @gfapi_url + URI.escape(tag + '/' + @section + '/' + name)
154
- when :name_prefix
155
- @gfapi_url + URI.escape(@service + '/' + @section + '/' + tag + '_' + name)
156
- end
164
+ def format_url(tag, name)
165
+ graph_path = @graph_path.gsub(/(\${[_a-z]+})/, placeholder_mapping(tag, name))
166
+ return @gfapi_url + URI.escape(graph_path)
157
167
  end
158
168
 
159
169
  def connect_to(tag, name)
@@ -112,6 +112,13 @@ class GrowthForecastOutputTest < Test::Unit::TestCase
112
112
  enable_float_number true
113
113
  ]
114
114
 
115
+ CONFIG_GFAPI_PATH = %[
116
+ gfapi_url http://127.0.0.1:5125/api/
117
+ graph_path ${tag}/metrics/${tag}_${key_name}
118
+ name_keys field1,field2,otherfield
119
+ remove_prefix test
120
+ ]
121
+
115
122
  def create_driver(conf=CONFIG1, tag='test.metrics')
116
123
  Fluent::Test::OutputTestDriver.new(Fluent::GrowthForecastOutput, tag).configure(conf)
117
124
  end
@@ -515,6 +522,31 @@ class GrowthForecastOutputTest < Test::Unit::TestCase
515
522
  assert_equal 'test.metrics_otherfield', v3rd[:name]
516
523
  end
517
524
 
525
+ def test_gfapi_path
526
+ d = create_driver(CONFIG_GFAPI_PATH, 'test.service')
527
+ # recent ruby's Hash saves elements order....
528
+ d.emit({ 'field1' => 50, 'field2' => 20, 'field3' => 10, 'otherfield' => 1 })
529
+ d.run
530
+
531
+ assert_equal 3, @posted.size
532
+ v1st = @posted[0]
533
+ v2nd = @posted[1]
534
+ v3rd = @posted[2]
535
+
536
+ assert_equal 50, v1st[:data][:number]
537
+ assert_equal 'gauge', v1st[:data][:mode]
538
+ assert_nil v1st[:auth]
539
+ assert_equal 'service', v1st[:service]
540
+ assert_equal 'metrics', v1st[:section]
541
+ assert_equal 'service_field1', v1st[:name]
542
+
543
+ assert_equal 20, v2nd[:data][:number]
544
+ assert_equal 'service_field2', v2nd[:name]
545
+
546
+ assert_equal 1, v3rd[:data][:number]
547
+ assert_equal 'service_otherfield', v3rd[:name]
548
+ end
549
+
518
550
  # setup / teardown for servers
519
551
  def setup
520
552
  Fluent::Test.setup
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-growthforecast
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - TAGOMORI Satoshi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-02 00:00:00.000000000 Z
11
+ date: 2013-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake