fluent-plugin-stackdriver-monitoring 0.0.2 → 0.0.3

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
2
  SHA1:
3
- metadata.gz: de841f30d9480113027498e115279a23d3c29a3f
4
- data.tar.gz: 744a9b0c65955678fc31e9e2bbcbd64bc8cfb98c
3
+ metadata.gz: 0152a3a88115ba576c4fcc2deff4acfc308e96e8
4
+ data.tar.gz: 3caa5074ce36b5063bfd3645ca74ab4dbd230719
5
5
  SHA512:
6
- metadata.gz: a693d1e6cd876314ac24ee014c1d15748e895b52e5150d0c0b9e55bbf7c4a9e688886b74b46923763ae569f97c966f6dc7036d5c96c620d11064ae5e04f99196
7
- data.tar.gz: 18fb5725f580a0607ffed34dcd313110fc22bbec45e4c234960e03fdc7fa420f605d65401aa36d296a300e8a3f94310efc8b8c2054d3fa6de3091227f0245c72
6
+ metadata.gz: c26c808d1bfc6bab1310e91f6605d495ad02ce1e9343f4287447db306ceab75f16c3daa4d9e5fb1345e9a395e6f1208803f01091f49c8a0847775d02ccd30d3b
7
+ data.tar.gz: de8ad272f8fc05772a52e01cade86e08f7dc232158a96cc458636e235bbf18235f642fb0461e1df97eeca263e0e8c34f59497812b6a6f8c3a4d4030fb2771668
data/README.md CHANGED
@@ -41,10 +41,15 @@ Sample configuration is below.
41
41
  - Set name of descriptor. It must start with `custom.googleapis.com/`.
42
42
  - metric_kind(enum, required)
43
43
  - See [metric kind](https://cloud.google.com/monitoring/api/ref_v3/rest/v3/projects.metricDescriptors#MetricKind).
44
- - You can specify `GAUGE`, `DELTA` or `CUMULATIVE`.
44
+ - You can specify `GAUGE` or `CUMULATIVE`.
45
+ - Custom metric does not support `DELTA`. See [here](https://cloud.google.com/monitoring/api/v3/metrics?hl=en#metric-kinds).
45
46
  - value_type(enum, required)
46
47
  - See [value type](https://cloud.google.com/monitoring/api/ref_v3/rest/v3/projects.metricDescriptors#valuetype).
47
- - You can specify `BOOL`, `INT64`, `DOUBLE` or `STRING`.
48
+ - You can specify `BOOL`, `INT64` or `DOUBLE` if metric_kind is `GAUGE`. And `INT64` or `DOUBLE` can be specified if metric_kind is `CUMULATIVE`.
49
+ - Custom metric does not support `MONEY` and `STRING`. See [here](https://cloud.google.com/monitoring/api/v3/metrics?hl=en#metric-kinds).
50
+ - time_interval(time, optional)
51
+ - This param is used as the difference between start time and end time.
52
+ - It must be greater than 0s if metric_kind is set to `CUMULATIVE`.
48
53
 
49
54
  ## TODO
50
55
 
@@ -6,7 +6,7 @@ Gem::Specification.new do |gem|
6
6
  gem.license = 'MIT'
7
7
  gem.homepage = 'https://github.com/mia-0032/fluent-plugin-stackdriver-monitoring'
8
8
  gem.summary = gem.description
9
- gem.version = '0.0.2'
9
+ gem.version = '0.0.3'
10
10
  gem.authors = ['Yoshihiro MIYAI']
11
11
  gem.email = 'msparrow17@gmail.com'
12
12
  gem.has_rdoc = false
@@ -12,8 +12,9 @@ module Fluent
12
12
  config_section :custom_metrics, required: true, multi: false do
13
13
  config_param :key, :string
14
14
  config_param :type, :string
15
- config_param :metric_kind, :enum, list: [:GAUGE, :DELTA, :CUMULATIVE]
16
- config_param :value_type, :enum, list: [:BOOL, :INT64, :DOUBLE, :STRING] # todo: implement :DISTRIBUTION, :MONEY
15
+ config_param :metric_kind, :enum, list: [:GAUGE, :CUMULATIVE]
16
+ config_param :value_type, :enum, list: [:BOOL, :INT64, :DOUBLE] # todo: implement :DISTRIBUTION
17
+ config_param :time_interval, :time, default: 0
17
18
  end
18
19
 
19
20
  TYPE_PREFIX = 'custom.googleapis.com/'.freeze
@@ -21,8 +22,17 @@ module Fluent
21
22
  def configure(conf)
22
23
  super
23
24
 
24
- unless @custom_metrics.type.start_with? TYPE_PREFIX
25
- raise "custom_metrics.type must start with \"#{TYPE_PREFIX}\""
25
+ unless is_custom_metric? @custom_metrics.type
26
+ raise Fluent::ConfigError.new "custom_metrics.type must start with \"#{TYPE_PREFIX}\""
27
+ end
28
+
29
+ if @custom_metrics.metric_kind == :CUMULATIVE
30
+ if @custom_metrics.time_interval == 0
31
+ raise Fluent::ConfigError.new 'time_interval must be greater than 0 if metric_kind is set to CUMULATIVE'
32
+ end
33
+ if @custom_metrics.value_type == :BOOL
34
+ raise Fluent::ConfigError.new 'custom metric does not support BOOL value type if metric_kind is set to CUMULATIVE'
35
+ end
26
36
  end
27
37
 
28
38
  @project_name = Google::Cloud::Monitoring::V3::MetricServiceClient.project_path @project
@@ -46,7 +56,7 @@ module Fluent
46
56
  value = record[@custom_metrics.key]
47
57
 
48
58
  point = Google::Monitoring::V3::Point.new
49
- point.interval = create_time_interval time
59
+ point.interval = create_time_interval time, @custom_metrics.time_interval
50
60
  point.value = create_typed_value value
51
61
  time_series.points.push point
52
62
 
@@ -57,6 +67,10 @@ module Fluent
57
67
  end
58
68
 
59
69
  private
70
+ def is_custom_metric?(metric_type)
71
+ metric_type.start_with? TYPE_PREFIX
72
+ end
73
+
60
74
  def create_metric_descriptor
61
75
  begin
62
76
  metric_descriptor = @metric_service_client.get_metric_descriptor(@metric_name)
@@ -89,9 +103,9 @@ module Fluent
89
103
  time_series
90
104
  end
91
105
 
92
- def create_time_interval(time)
106
+ def create_time_interval(time, interval)
93
107
  time_interval = Google::Monitoring::V3::TimeInterval.new
94
- time_interval.start_time = Google::Protobuf::Timestamp.new seconds: time
108
+ time_interval.start_time = Google::Protobuf::Timestamp.new seconds: (time - interval)
95
109
  time_interval.end_time = Google::Protobuf::Timestamp.new seconds: time
96
110
 
97
111
  time_interval
@@ -101,13 +115,11 @@ module Fluent
101
115
  typed_value = Google::Monitoring::V3::TypedValue.new
102
116
  case @metric_descriptor.value_type
103
117
  when :BOOL
104
- typed_value.bool_value = value.to_bool
118
+ typed_value.bool_value = !!value
105
119
  when :INT64
106
120
  typed_value.int64_value = value.to_i
107
121
  when :DOUBLE
108
122
  typed_value.double_value = value.to_f
109
- when :STRING
110
- typed_value.string_value = value.to_s
111
123
  else
112
124
  raise 'Unknown value_type!'
113
125
  end
@@ -0,0 +1,77 @@
1
+ require_relative '../test_helper'
2
+
3
+ class StackdriverMonitoringOutputTest < Test::Unit::TestCase
4
+ CONFIG = %[
5
+ project project-test
6
+ <custom_metrics>
7
+ key hoge_key
8
+ type custom.googleapis.com/hoge_type
9
+ metric_kind GAUGE
10
+ value_type INT64
11
+ </custom_metrics>
12
+ ]
13
+
14
+ def create_driver(conf = CONFIG)
15
+ Fluent::Test::BufferedOutputTestDriver.new(Fluent::StackdriverMonitoringOutput).configure(conf)
16
+ end
17
+
18
+ setup do
19
+ Fluent::Test.setup
20
+ end
21
+
22
+ sub_test_case 'configure' do
23
+ test 'values are configured' do
24
+ d = create_driver
25
+
26
+ assert_equal('project-test', d.instance.project)
27
+ assert_equal('hoge_key', d.instance.custom_metrics.key)
28
+ assert_equal('custom.googleapis.com/hoge_type', d.instance.custom_metrics.type)
29
+ assert_equal(:GAUGE, d.instance.custom_metrics.metric_kind)
30
+ assert_equal(:INT64, d.instance.custom_metrics.value_type)
31
+ assert_equal(0, d.instance.custom_metrics.time_interval)
32
+ end
33
+
34
+ test 'custom_metrics.type must start with custom.googleapis.com' do
35
+ assert_raises Fluent::ConfigError do
36
+ create_driver(%[
37
+ project project-test
38
+ <custom_metrics>
39
+ key hoge_key
40
+ type invalid_type
41
+ metric_kind GAUGE
42
+ value_type INT64
43
+ </custom_metrics>
44
+ ])
45
+ end
46
+ end
47
+
48
+ test 'time_interval must be greater than 0 if metric_kind is set to CUMULATIVE' do
49
+ assert_raises Fluent::ConfigError do
50
+ create_driver(%[
51
+ project project-test
52
+ <custom_metrics>
53
+ key hoge_key
54
+ type invalid_type
55
+ metric_kind CUMULATIVE
56
+ value_type INT64
57
+ time_interval 0s
58
+ </custom_metrics>
59
+ ])
60
+ end
61
+ end
62
+
63
+ test 'custom metric does not support BOOL value type if metric_kind is set to CUMULATIVE' do
64
+ assert_raises Fluent::ConfigError do
65
+ create_driver(%[
66
+ project project-test
67
+ <custom_metrics>
68
+ key hoge_key
69
+ type invalid_type
70
+ metric_kind CUMULATIVE
71
+ value_type BOOL
72
+ </custom_metrics>
73
+ ])
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,30 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require "test/unit/rr"
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+
16
+ require 'fluent/test'
17
+ unless ENV.has_key?('VERBOSE')
18
+ nulllogger = Object.new
19
+ nulllogger.instance_eval {|obj|
20
+ def method_missing(method, *args)
21
+ # pass
22
+ end
23
+ }
24
+ $log = nulllogger
25
+ end
26
+
27
+ require 'fluent/plugin/out_stackdriver_monitoring'
28
+
29
+ class Test::Unit::TestCase
30
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-stackdriver-monitoring
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yoshihiro MIYAI
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-02 00:00:00.000000000 Z
11
+ date: 2017-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd
@@ -115,6 +115,8 @@ files:
115
115
  - Rakefile
116
116
  - fluent-plugin-stackdriver-monitoring.gemspec
117
117
  - lib/fluent/plugin/out_stackdriver_monitoring.rb
118
+ - test/plugin/test_out_stackdriver_monitoring.rb
119
+ - test/test_helper.rb
118
120
  homepage: https://github.com/mia-0032/fluent-plugin-stackdriver-monitoring
119
121
  licenses:
120
122
  - MIT
@@ -139,4 +141,6 @@ rubygems_version: 2.5.1
139
141
  signing_key:
140
142
  specification_version: 4
141
143
  summary: Stackdriver Monitoring custom metrics output plugin for Fluentd
142
- test_files: []
144
+ test_files:
145
+ - test/plugin/test_out_stackdriver_monitoring.rb
146
+ - test/test_helper.rb