fluent-plugin-google-cloud 0.10.2 → 0.10.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
  SHA256:
3
- metadata.gz: 202c2767566b8903d03b55b211a5e29c55d77c08b2d8ab1b07c3c4a6c16ea4a9
4
- data.tar.gz: 9175afb12ae142d19ad72c80384b0e5ea22766524d599d1343f0a1c55a564a27
3
+ metadata.gz: 04bd17bad7dbead504f9f9e3e78fa36cb4ecf44409e0b6d817b16e8d80498631
4
+ data.tar.gz: 12d9f4b26e4876dbea235043e2fa1bb59707a5f66024c8becfa1f9ed2e037a5b
5
5
  SHA512:
6
- metadata.gz: 1bc3b60cac80908283a91c80f4db157117579119bfc13c7d233de706256a3e458d8d6c8c3fa5aea99ef840123caabb6fe45ae270f795a66720ab0742792107a6
7
- data.tar.gz: b987203a4b12ac2c1a0679362ae1fd6c1e332ae258a0fb8094d6a15f88d84cce9a15d8f76e3129cffa8a2f70f607a8b5f746f8840b67fd708b2ade66462d426d
6
+ metadata.gz: 94f7657e972697e89acda8d1a78663561a42e084170aed6cb03a2f606e1706ccce0c721495cd0270a005f1a2aa8bc0c59914fb66ccf9c03c4cd20fd71588b198
7
+ data.tar.gz: 2077ecebdfcf73f02594ab93e8f96bfd4c0dc61bf27b2c9f4768a875ed9419945375423309dadd41630610732f5734218cf8304411edaae79af5c4d6d3e34c03
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fluent-plugin-google-cloud (0.10.2)
4
+ fluent-plugin-google-cloud (0.10.3)
5
5
  fluentd (= 1.11.2)
6
6
  google-api-client (= 0.30.8)
7
7
  google-cloud-logging (= 1.6.6)
@@ -20,15 +20,14 @@ GEM
20
20
  public_suffix (>= 2.0.2, < 5.0)
21
21
  ast (2.4.1)
22
22
  concurrent-ruby (1.1.7)
23
- cool.io (1.6.0)
23
+ cool.io (1.7.0)
24
24
  coveralls (0.8.23)
25
25
  json (>= 1.8, < 3)
26
26
  simplecov (~> 0.16.1)
27
27
  term-ansicolor (~> 1.3)
28
28
  thor (>= 0.19.4, < 2.0)
29
29
  tins (~> 1.6)
30
- crack (0.4.3)
31
- safe_yaml (~> 1.0.0)
30
+ crack (0.4.4)
32
31
  declarative (0.0.20)
33
32
  declarative-option (0.1.0)
34
33
  docile (1.3.2)
@@ -129,7 +128,7 @@ GEM
129
128
  google-cloud-trace (~> 0.35)
130
129
  opencensus (~> 0.5)
131
130
  os (1.1.1)
132
- parser (2.7.1.4)
131
+ parser (2.7.1.5)
133
132
  ast (~> 2.4.1)
134
133
  power_assert (1.2.0)
135
134
  powerpack (0.1.2)
@@ -153,7 +152,6 @@ GEM
153
152
  ruby-progressbar (~> 1.7)
154
153
  unicode-display_width (~> 1.0, >= 1.0.1)
155
154
  ruby-progressbar (1.10.1)
156
- safe_yaml (1.0.5)
157
155
  serverengine (2.2.1)
158
156
  sigdump (~> 0.2.2)
159
157
  sigdump (0.2.4)
@@ -169,7 +167,7 @@ GEM
169
167
  simplecov-html (0.10.2)
170
168
  stackdriver-core (1.4.0)
171
169
  google-cloud-core (~> 1.2)
172
- strptime (0.2.4)
170
+ strptime (0.2.5)
173
171
  sync (0.5.0)
174
172
  term-ansicolor (1.7.1)
175
173
  tins (~> 1.0)
@@ -10,7 +10,7 @@ eos
10
10
  gem.homepage =
11
11
  'https://github.com/GoogleCloudPlatform/fluent-plugin-google-cloud'
12
12
  gem.license = 'Apache-2.0'
13
- gem.version = '0.10.2'
13
+ gem.version = '0.10.3'
14
14
  gem.authors = ['Stackdriver Agents Team']
15
15
  gem.email = ['stackdriver-agents@google.com']
16
16
  gem.required_ruby_version = Gem::Requirement.new('>= 2.2')
@@ -15,6 +15,9 @@
15
15
  require 'fileutils'
16
16
  require 'fluent/config'
17
17
  require 'fluent/config/v1_parser'
18
+ require 'googleauth'
19
+ require 'google/apis/logging_v2'
20
+ require 'open-uri'
18
21
  require 'set'
19
22
 
20
23
  require_relative 'common'
@@ -155,8 +158,8 @@ module Fluent
155
158
  super
156
159
  @log = $log # rubocop:disable Style/GlobalVars
157
160
 
158
- # Initialize the insertID.
159
- @log.info 'Started the analyze_config plugin to analyze configuration.'
161
+ @log.info(
162
+ 'analyze_config plugin: Started the plugin to analyze configuration.')
160
163
  end
161
164
 
162
165
  def parse_config(path)
@@ -205,6 +208,7 @@ module Fluent
205
208
 
206
209
  def configure(conf)
207
210
  super
211
+ @log.info('analyze_config plugin: Starting to configure the plugin.')
208
212
  if File.file?(@google_fluentd_config_path) &&
209
213
  File.file?(@google_fluentd_baseline_config_path)
210
214
  @log.info(
@@ -232,24 +236,28 @@ module Fluent
232
236
 
233
237
  unless Monitoring::MonitoringRegistryFactory.supports_monitoring_type(
234
238
  @monitoring_type)
235
- @log.warn "monitoring_type '#{@monitoring_type}' is unknown; "\
236
- 'there will be no metrics'
239
+ @log.warn(
240
+ "analyze_config plugin: monitoring_type #{@monitoring_type} is " \
241
+ 'unknown; there will be no metrics.')
237
242
  end
238
243
  registry = Monitoring::MonitoringRegistryFactory.create(
239
244
  @monitoring_type, project_id, resource, @gcm_service_address)
240
245
 
241
246
  plugin_usage = registry.counter(
242
- :stackdriver_enabled_plugins,
243
- [:plugin_name, :is_default_plugin, :has_default_value],
244
- 'Enabled plugins')
247
+ :enabled_plugins,
248
+ [:plugin_name, :is_default_plugin, :has_default_config],
249
+ 'Enabled plugins',
250
+ 'agent.googleapis.com/agent/internal/logging/config')
245
251
  config_usage = registry.counter(
246
- :stackdriver_config_usage,
247
- [:plugin_name, :param, :is_present, :has_default_value],
248
- 'Parameter usage for Google Cloud plugins')
252
+ :plugin_config,
253
+ [:plugin_name, :param, :is_present, :has_default_config],
254
+ 'Configuration parameter usage for plugins relevant to Google Cloud.',
255
+ 'agent.googleapis.com/agent/internal/logging/config')
249
256
  config_bool_values = registry.counter(
250
- :stackdriver_config_bool_values,
257
+ :config_bool_values,
251
258
  [:plugin_name, :param, :value],
252
- 'Values for bool parameters in Google Cloud plugins')
259
+ 'Values for bool parameters in Google Cloud plugins',
260
+ 'agent.googleapis.com/agent/internal/logging/config')
253
261
 
254
262
  config = parse_config(@google_fluentd_config_path)
255
263
  baseline_config = parse_config(@google_fluentd_baseline_config_path)
@@ -276,17 +284,17 @@ module Fluent
276
284
  plugin_name = default_plugin_name(e)
277
285
  if baseline_elements.key?(plugin_name)
278
286
  is_default_plugin = true
279
- has_default_value = (baseline_elements[plugin_name] == e)
287
+ has_default_config = (baseline_elements[plugin_name] == e)
280
288
  else
281
289
  plugin_name = custom_plugin_name(e)
282
290
  is_default_plugin = false
283
- has_default_value = false
291
+ has_default_config = false
284
292
  end
285
293
  plugin_usage.increment(
286
294
  labels: {
287
295
  plugin_name: plugin_name,
288
296
  is_default_plugin: is_default_plugin,
289
- has_default_value: has_default_value,
297
+ has_default_config: has_default_config,
290
298
  has_ruby_snippet: embedded_ruby?(e)
291
299
  },
292
300
  by: 1)
@@ -300,7 +308,7 @@ module Fluent
300
308
  plugin_name: e['@type'],
301
309
  param: p,
302
310
  is_present: e.key?(p),
303
- has_default_value: (e.key?(p) &&
311
+ has_default_config: (e.key?(p) &&
304
312
  baseline_google_element.key?(p) &&
305
313
  e[p] == baseline_google_element[p])
306
314
  },
@@ -317,17 +325,18 @@ module Fluent
317
325
  end
318
326
  else
319
327
  @log.info(
320
- 'google-fluentd configuration file does not exist at' \
321
- " #{@google_fluentd_config_path} or " \
322
- 'google-fluentd baseline configuration file does not exist at' \
323
- " #{@google_fluentd_baseline_config_path} or " \
324
- '. Skipping configuration analysis.')
328
+ 'analyze_config plugin: google-fluentd configuration file does not ' \
329
+ "exist at #{@google_fluentd_config_path} or google-fluentd " \
330
+ 'baseline configuration file does not exist at' \
331
+ " #{@google_fluentd_baseline_config_path}. Skipping configuration " \
332
+ 'analysis.')
325
333
  end
326
334
  rescue => e
327
335
  # Do not crash the agent due to configuration analysis failures.
328
336
  @log.warn(
329
- 'Failed to optionally analyze the google-fluentd configuration' \
330
- " file. Proceeding anyway. Error: #{e}")
337
+ 'analyze_config plugin: Failed to optionally analyze the ' \
338
+ "google-fluentd configuration file. Proceeding anyway. Error: #{e}. " \
339
+ "Trace: #{e.backtrace}")
331
340
  end
332
341
 
333
342
  def shutdown
@@ -52,7 +52,7 @@ module Monitoring
52
52
  def initialize(_project_id, _monitored_resource, _gcm_service_address)
53
53
  end
54
54
 
55
- def counter(_name, _labels, _docstring)
55
+ def counter(_name, _labels, _docstring, _prefix)
56
56
  BaseCounter.new
57
57
  end
58
58
 
@@ -75,7 +75,7 @@ module Monitoring
75
75
  end
76
76
 
77
77
  # Exception-driven behavior to avoid synchronization errors.
78
- def counter(name, _labels, docstring)
78
+ def counter(name, _labels, docstring, _prefix)
79
79
  # When we upgrade to Prometheus client 0.10.0 or higher, pass the
80
80
  # labels in the metric constructor. The 'labels' field in
81
81
  # Prometheus client 0.9.0 has a different function and will not
@@ -97,21 +97,14 @@ module Monitoring
97
97
  require 'opencensus'
98
98
  require 'opencensus-stackdriver'
99
99
  @log = $log # rubocop:disable Style/GlobalVars
100
- @recorder = OpenCensus::Stats.ensure_recorder
101
- @exporter = OpenCensus::Stats::Exporters::Stackdriver.new(
102
- project_id: project_id,
103
- metric_prefix: 'agent.googleapis.com/agent',
104
- resource_type: monitored_resource.type,
105
- resource_labels: monitored_resource.labels,
106
- gcm_service_address: gcm_service_address
107
- )
108
- OpenCensus.configure do |c|
109
- c.stats.exporter = @exporter
110
- end
111
- @log.debug "OpenCensus config=#{OpenCensus.config}"
100
+ @project_id = project_id
101
+ @metrics_monitored_resource = monitored_resource
102
+ @gcm_service_address = gcm_service_address
103
+ @recorders = {}
104
+ @exporters = {}
112
105
  end
113
106
 
114
- def counter(name, labels, docstring)
107
+ def counter(name, labels, docstring, prefix)
115
108
  translator = MetricTranslator.new(name, labels)
116
109
  measure = OpenCensus::Stats::MeasureRegistry.get(translator.name)
117
110
  if measure.nil?
@@ -121,6 +114,17 @@ module Monitoring
121
114
  description: docstring
122
115
  )
123
116
  end
117
+ unless @exporters.keys.include?(prefix)
118
+ @recorders[prefix] = OpenCensus::Stats.ensure_recorder
119
+ @exporters[prefix] = \
120
+ OpenCensus::Stats::Exporters::Stackdriver.new(
121
+ project_id: @project_id,
122
+ metric_prefix: prefix,
123
+ resource_type: @metrics_monitored_resource.type,
124
+ resource_labels: @metrics_monitored_resource.labels,
125
+ gcm_service_address: @gcm_service_address
126
+ )
127
+ end
124
128
  OpenCensus::Stats.create_and_register_view(
125
129
  name: translator.name,
126
130
  measure: measure,
@@ -128,11 +132,19 @@ module Monitoring
128
132
  description: docstring,
129
133
  columns: translator.view_labels.map(&:to_s)
130
134
  )
131
- OpenCensusCounter.new(@recorder, measure, translator)
135
+ OpenCensusCounter.new(@recorders[prefix], measure, translator)
136
+ rescue StandardError => e
137
+ @log.warn "Failed to count metrics for #{name}.", error: e
138
+ raise e
132
139
  end
133
140
 
134
141
  def export
135
- @exporter.export @recorder.views_data
142
+ @exporters.keys.each do |prefix|
143
+ @exporters[prefix].export @recorders[prefix].views_data
144
+ end
145
+ rescue StandardError => e
146
+ @log.warn 'Failed to export some metrics.', error: e
147
+ raise e
136
148
  end
137
149
  end
138
150
 
@@ -563,32 +563,38 @@ module Fluent
563
563
  # Uptime should be a gauge, but the metric definition is a counter and
564
564
  # we can't change it.
565
565
  @uptime_metric = @registry.counter(
566
- :uptime, [:version], 'Uptime of Logging agent')
566
+ :uptime, [:version], 'Uptime of Logging agent',
567
+ 'agent.googleapis.com/agent')
567
568
  update_uptime
568
569
  timer_execute(:update_uptime, 1) { update_uptime }
569
570
  @successful_requests_count = @registry.counter(
570
571
  :stackdriver_successful_requests_count,
571
572
  [:grpc, :code],
572
- 'A number of successful requests to the Stackdriver Logging API')
573
+ 'A number of successful requests to the Stackdriver Logging API',
574
+ 'agent.googleapis.com/agent')
573
575
  @failed_requests_count = @registry.counter(
574
576
  :stackdriver_failed_requests_count,
575
577
  [:grpc, :code],
576
578
  'A number of failed requests to the Stackdriver Logging '\
577
- 'API, broken down by the error code')
579
+ 'API, broken down by the error code',
580
+ 'agent.googleapis.com/agent')
578
581
  @ingested_entries_count = @registry.counter(
579
582
  :stackdriver_ingested_entries_count,
580
583
  [:grpc, :code],
581
- 'A number of log entries ingested by Stackdriver Logging')
584
+ 'A number of log entries ingested by Stackdriver Logging',
585
+ 'agent.googleapis.com/agent')
582
586
  @dropped_entries_count = @registry.counter(
583
587
  :stackdriver_dropped_entries_count,
584
588
  [:grpc, :code],
585
- 'A number of log entries dropped by the Stackdriver output plugin')
589
+ 'A number of log entries dropped by the Stackdriver output plugin',
590
+ 'agent.googleapis.com/agent')
586
591
  @retried_entries_count = @registry.counter(
587
592
  :stackdriver_retried_entries_count,
588
593
  [:grpc, :code],
589
594
  'The number of log entries that failed to be ingested by '\
590
595
  'the Stackdriver output plugin due to a transient error '\
591
- 'and were retried')
596
+ 'and were retried',
597
+ 'agent.googleapis.com/agent')
592
598
  @ok_code = @use_grpc ? GRPC::Core::StatusCodes::OK : 200
593
599
  end
594
600
 
@@ -169,10 +169,11 @@ module BaseTest
169
169
  assert_true d.instance.instance_variable_get(:@enable_monitoring)
170
170
  registry = d.instance.instance_variable_get(:@registry)
171
171
  assert_not_nil registry
172
- exporter = registry.instance_variable_get(:@exporter)
173
- assert_equal 'custom_resource', exporter.resource_type, "Index #{index}"
172
+ monitored_resource = registry.instance_variable_get(
173
+ :@metrics_monitored_resource)
174
+ assert_equal('custom_resource', monitored_resource.type, "Index #{index}")
174
175
  assert_equal({ 'label1' => '123', 'label2' => 'abc' },
175
- exporter.resource_labels, "Index #{index}")
176
+ monitored_resource.labels, "Index #{index}")
176
177
  end
177
178
  end
178
179
 
@@ -55,81 +55,81 @@ class FilterAnalyzeConfigTest < Test::Unit::TestCase
55
55
 
56
56
  # Default plugins, with default config.
57
57
  assert_metric_value.call(
58
- :stackdriver_enabled_plugins,
58
+ :enabled_plugins,
59
59
  1,
60
60
  plugin_name: 'source/syslog/tcp',
61
61
  is_default_plugin: true,
62
- has_default_value: true,
62
+ has_default_config: true,
63
63
  has_ruby_snippet: false)
64
64
  assert_metric_value.call(
65
- :stackdriver_enabled_plugins,
65
+ :enabled_plugins,
66
66
  1,
67
67
  plugin_name: 'source/tail/apache-access',
68
68
  is_default_plugin: true,
69
- has_default_value: true,
69
+ has_default_config: true,
70
70
  has_ruby_snippet: false)
71
71
  assert_metric_value.call(
72
- :stackdriver_enabled_plugins,
72
+ :enabled_plugins,
73
73
  1,
74
74
  plugin_name: 'filter/add_insert_ids',
75
75
  is_default_plugin: true,
76
- has_default_value: true,
76
+ has_default_config: true,
77
77
  has_ruby_snippet: false)
78
78
 
79
79
  # Default plugins, with custom config.
80
80
  assert_metric_value.call(
81
- :stackdriver_enabled_plugins,
81
+ :enabled_plugins,
82
82
  1,
83
83
  plugin_name: 'match/google_cloud',
84
84
  is_default_plugin: true,
85
- has_default_value: false,
85
+ has_default_config: false,
86
86
  has_ruby_snippet: false)
87
87
 
88
88
  # Custom plugins, some with embedded Ruby.
89
89
  assert_metric_value.call(
90
- :stackdriver_enabled_plugins,
90
+ :enabled_plugins,
91
91
  1,
92
92
  plugin_name: 'filter',
93
93
  is_default_plugin: false,
94
- has_default_value: false,
94
+ has_default_config: false,
95
95
  has_ruby_snippet: false)
96
96
  assert_metric_value.call(
97
- :stackdriver_enabled_plugins,
97
+ :enabled_plugins,
98
98
  1,
99
99
  plugin_name: 'filter/record_transformer',
100
100
  is_default_plugin: false,
101
- has_default_value: false,
101
+ has_default_config: false,
102
102
  has_ruby_snippet: true)
103
103
  assert_metric_value.call(
104
- :stackdriver_enabled_plugins,
104
+ :enabled_plugins,
105
105
  1,
106
106
  plugin_name: 'match/stdout',
107
107
  is_default_plugin: false,
108
- has_default_value: false,
108
+ has_default_config: false,
109
109
  has_ruby_snippet: true)
110
110
 
111
111
  # For out_google_cloud, 3 params are present.
112
112
  assert_metric_value.call(
113
- :stackdriver_config_usage,
113
+ :plugin_config,
114
114
  1,
115
115
  plugin_name: 'google_cloud',
116
116
  param: 'adjust_invalid_timestamps',
117
117
  is_present: true,
118
- has_default_value: true)
118
+ has_default_config: true)
119
119
  assert_metric_value.call(
120
- :stackdriver_config_usage,
120
+ :plugin_config,
121
121
  1,
122
122
  plugin_name: 'google_cloud',
123
123
  param: 'autoformat_stackdriver_trace',
124
124
  is_present: true,
125
- has_default_value: false)
125
+ has_default_config: false)
126
126
  assert_metric_value.call(
127
- :stackdriver_config_usage,
127
+ :plugin_config,
128
128
  1,
129
129
  plugin_name: 'google_cloud',
130
130
  param: 'coerce_to_utf8',
131
131
  is_present: true,
132
- has_default_value: false)
132
+ has_default_config: false)
133
133
  # The remaining "google_cloud" params are not present.
134
134
  # The are no params for "detect_exceptions".
135
135
  %w(
@@ -163,29 +163,29 @@ class FilterAnalyzeConfigTest < Test::Unit::TestCase
163
163
  zone
164
164
  ).each do |p|
165
165
  assert_metric_value.call(
166
- :stackdriver_config_usage,
166
+ :plugin_config,
167
167
  1,
168
168
  plugin_name: 'google_cloud',
169
169
  param: p,
170
170
  is_present: false,
171
- has_default_value: false)
171
+ has_default_config: false)
172
172
  end
173
173
 
174
174
  # We also export values for the bools.
175
175
  assert_metric_value.call(
176
- :stackdriver_config_bool_values,
176
+ :config_bool_values,
177
177
  1,
178
178
  plugin_name: 'google_cloud',
179
179
  param: 'adjust_invalid_timestamps',
180
180
  value: true)
181
181
  assert_metric_value.call(
182
- :stackdriver_config_bool_values,
182
+ :config_bool_values,
183
183
  1,
184
184
  plugin_name: 'google_cloud',
185
185
  param: 'autoformat_stackdriver_trace',
186
186
  value: false)
187
187
  assert_metric_value.call(
188
- :stackdriver_config_bool_values,
188
+ :config_bool_values,
189
189
  1,
190
190
  plugin_name: 'google_cloud',
191
191
  param: 'coerce_to_utf8',
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-google-cloud
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.2
4
+ version: 0.10.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stackdriver Agents Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-10 00:00:00.000000000 Z
11
+ date: 2020-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd