fluent-plugin-google-cloud 0.10.3 → 0.10.8

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: 04bd17bad7dbead504f9f9e3e78fa36cb4ecf44409e0b6d817b16e8d80498631
4
- data.tar.gz: 12d9f4b26e4876dbea235043e2fa1bb59707a5f66024c8becfa1f9ed2e037a5b
3
+ metadata.gz: bdb89243a3a885adb16b15fe5293c5a1e791f4ab7e26f22e8ccd3f63934ebcde
4
+ data.tar.gz: c1ca844d4f5466f7bc3a3a4b76c35771432e157bbb0b3e11e3563e1a004bffcc
5
5
  SHA512:
6
- metadata.gz: 94f7657e972697e89acda8d1a78663561a42e084170aed6cb03a2f606e1706ccce0c721495cd0270a005f1a2aa8bc0c59914fb66ccf9c03c4cd20fd71588b198
7
- data.tar.gz: 2077ecebdfcf73f02594ab93e8f96bfd4c0dc61bf27b2c9f4768a875ed9419945375423309dadd41630610732f5734218cf8304411edaae79af5c4d6d3e34c03
6
+ metadata.gz: 2a0ed81d5df9648182b62e713ca7f420ccf6a2acf076b282e37739c84a845509b2fcf4d41bb0e052abf495a591057bf75acdb7bd2256a6dbed97992d8b1c1d20
7
+ data.tar.gz: c004d81fcb8d413e630c0918714f9601cbddf2e2982c564bb99410d1a85be8e8d346af1f0645fec4eb6a0e4bedbf4cca79940efff96176f09bf6fc9c4801af11
data/Gemfile.lock CHANGED
@@ -1,12 +1,12 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fluent-plugin-google-cloud (0.10.3)
4
+ fluent-plugin-google-cloud (0.10.8)
5
5
  fluentd (= 1.11.2)
6
6
  google-api-client (= 0.30.8)
7
7
  google-cloud-logging (= 1.6.6)
8
- google-protobuf (= 3.12.2)
9
- googleapis-common-protos (= 1.3.9)
8
+ google-protobuf (= 3.15.8)
9
+ googleapis-common-protos (= 1.3.10)
10
10
  googleauth (= 0.9.0)
11
11
  grpc (= 1.31.1)
12
12
  json (= 2.2.0)
@@ -18,20 +18,21 @@ GEM
18
18
  specs:
19
19
  addressable (2.7.0)
20
20
  public_suffix (>= 2.0.2, < 5.0)
21
- ast (2.4.1)
22
- concurrent-ruby (1.1.7)
23
- cool.io (1.7.0)
21
+ ast (2.4.2)
22
+ concurrent-ruby (1.1.8)
23
+ cool.io (1.7.1)
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.4)
30
+ crack (0.4.5)
31
+ rexml
31
32
  declarative (0.0.20)
32
33
  declarative-option (0.1.0)
33
- docile (1.3.2)
34
- faraday (0.17.3)
34
+ docile (1.3.5)
35
+ faraday (0.17.4)
35
36
  multipart-post (>= 1.2, < 3)
36
37
  fluentd (1.11.2)
37
38
  cool.io (>= 1.4.5, < 2.0.0)
@@ -57,12 +58,12 @@ GEM
57
58
  representable (~> 3.0)
58
59
  retriable (>= 2.0, < 4.0)
59
60
  signet (~> 0.10)
60
- google-cloud-core (1.5.0)
61
+ google-cloud-core (1.6.0)
61
62
  google-cloud-env (~> 1.0)
62
63
  google-cloud-errors (~> 1.0)
63
- google-cloud-env (1.3.3)
64
+ google-cloud-env (1.5.0)
64
65
  faraday (>= 0.17.3, < 2.0)
65
- google-cloud-errors (1.0.1)
66
+ google-cloud-errors (1.1.0)
66
67
  google-cloud-logging (1.6.6)
67
68
  concurrent-ruby (~> 1.1)
68
69
  google-cloud-core (~> 1.2)
@@ -73,16 +74,16 @@ GEM
73
74
  google-gax (~> 1.8)
74
75
  googleapis-common-protos (>= 1.3.9, < 2.0)
75
76
  googleapis-common-protos-types (>= 1.0.4, < 2.0)
76
- google-cloud-trace (0.40.0)
77
+ google-cloud-trace (0.41.0)
77
78
  concurrent-ruby (~> 1.1)
78
79
  google-cloud-core (~> 1.5)
79
80
  google-cloud-trace-v1 (~> 0.0)
80
81
  google-cloud-trace-v2 (~> 0.0)
81
82
  stackdriver-core (~> 1.3)
82
- google-cloud-trace-v1 (0.1.2)
83
+ google-cloud-trace-v1 (0.3.0)
83
84
  gapic-common (~> 0.3)
84
85
  google-cloud-errors (~> 1.0)
85
- google-cloud-trace-v2 (0.1.2)
86
+ google-cloud-trace-v2 (0.3.0)
86
87
  gapic-common (~> 0.3)
87
88
  google-cloud-errors (~> 1.0)
88
89
  google-gax (1.8.1)
@@ -91,13 +92,13 @@ GEM
91
92
  googleauth (~> 0.9)
92
93
  grpc (~> 1.24)
93
94
  rly (~> 0.2.3)
94
- google-protobuf (3.12.2)
95
- googleapis-common-protos (1.3.9)
96
- google-protobuf (~> 3.0)
97
- googleapis-common-protos-types (~> 1.0)
98
- grpc (~> 1.0)
99
- googleapis-common-protos-types (1.0.5)
95
+ google-protobuf (3.15.8)
96
+ googleapis-common-protos (1.3.10)
100
97
  google-protobuf (~> 3.11)
98
+ googleapis-common-protos-types (>= 1.0.5, < 2.0)
99
+ grpc (~> 1.27)
100
+ googleapis-common-protos-types (1.0.6)
101
+ google-protobuf (~> 3.14)
101
102
  googleauth (0.9.0)
102
103
  faraday (~> 0.12)
103
104
  jwt (>= 1.4, < 3.0)
@@ -115,10 +116,10 @@ GEM
115
116
  jwt (2.2.2)
116
117
  memoist (0.16.2)
117
118
  metaclass (0.0.4)
118
- mini_mime (1.0.2)
119
+ mini_mime (1.1.0)
119
120
  mocha (1.9.0)
120
121
  metaclass (~> 0.0.1)
121
- msgpack (1.3.3)
122
+ msgpack (1.4.2)
122
123
  multi_json (1.15.0)
123
124
  multipart-post (2.1.1)
124
125
  opencensus (0.5.0)
@@ -128,10 +129,10 @@ GEM
128
129
  google-cloud-trace (~> 0.35)
129
130
  opencensus (~> 0.5)
130
131
  os (1.1.1)
131
- parser (2.7.1.5)
132
+ parser (2.7.2.0)
132
133
  ast (~> 2.4.1)
133
- power_assert (1.2.0)
134
- powerpack (0.1.2)
134
+ power_assert (2.0.0)
135
+ powerpack (0.1.3)
135
136
  prometheus-client (0.9.0)
136
137
  quantile (~> 0.2.1)
137
138
  public_suffix (4.0.6)
@@ -144,6 +145,7 @@ GEM
144
145
  declarative-option (< 0.2.0)
145
146
  uber (< 0.2.0)
146
147
  retriable (3.1.2)
148
+ rexml (3.2.5)
147
149
  rly (0.2.3)
148
150
  rubocop (0.39.0)
149
151
  parser (>= 2.3.0.7, < 3.0)
@@ -151,11 +153,11 @@ GEM
151
153
  rainbow (>= 1.99.1, < 3.0)
152
154
  ruby-progressbar (~> 1.7)
153
155
  unicode-display_width (~> 1.0, >= 1.0.1)
154
- ruby-progressbar (1.10.1)
155
- serverengine (2.2.1)
156
+ ruby-progressbar (1.11.0)
157
+ serverengine (2.2.3)
156
158
  sigdump (~> 0.2.2)
157
159
  sigdump (0.2.4)
158
- signet (0.14.0)
160
+ signet (0.15.0)
159
161
  addressable (~> 2.3)
160
162
  faraday (>= 0.17.3, < 2.0)
161
163
  jwt (>= 1.5, < 3.0)
@@ -165,7 +167,7 @@ GEM
165
167
  json (>= 1.8, < 3)
166
168
  simplecov-html (~> 0.10.0)
167
169
  simplecov-html (0.10.2)
168
- stackdriver-core (1.4.0)
170
+ stackdriver-core (1.5.0)
169
171
  google-cloud-core (~> 1.2)
170
172
  strptime (0.2.5)
171
173
  sync (0.5.0)
@@ -173,12 +175,12 @@ GEM
173
175
  tins (~> 1.0)
174
176
  test-unit (3.3.3)
175
177
  power_assert
176
- thor (1.0.1)
177
- tins (1.25.0)
178
+ thor (1.1.0)
179
+ tins (1.28.0)
178
180
  sync
179
- tzinfo (2.0.2)
181
+ tzinfo (2.0.4)
180
182
  concurrent-ruby (~> 1.0)
181
- tzinfo-data (1.2020.1)
183
+ tzinfo-data (1.2021.1)
182
184
  tzinfo (>= 1.0.0)
183
185
  uber (0.1.0)
184
186
  unicode-display_width (1.7.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.3'
13
+ gem.version = '0.10.8'
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')
@@ -20,11 +20,11 @@ eos
20
20
  gem.require_paths = ['lib']
21
21
 
22
22
  gem.add_runtime_dependency 'fluentd', '1.11.2'
23
- gem.add_runtime_dependency 'googleapis-common-protos', '1.3.9'
23
+ gem.add_runtime_dependency 'googleapis-common-protos', '1.3.10'
24
24
  gem.add_runtime_dependency 'googleauth', '0.9.0'
25
25
  gem.add_runtime_dependency 'google-api-client', '0.30.8'
26
26
  gem.add_runtime_dependency 'google-cloud-logging', '1.6.6'
27
- gem.add_runtime_dependency 'google-protobuf', '3.12.2'
27
+ gem.add_runtime_dependency 'google-protobuf', '3.15.8'
28
28
  gem.add_runtime_dependency 'grpc', '1.31.1'
29
29
  gem.add_runtime_dependency 'json', '2.2.0'
30
30
  gem.add_runtime_dependency 'opencensus', '0.5.0'
@@ -15,6 +15,7 @@
15
15
  require 'fileutils'
16
16
  require 'fluent/config'
17
17
  require 'fluent/config/v1_parser'
18
+ require 'fluent/plugin_helper'
18
19
  require 'googleauth'
19
20
  require 'google/apis/logging_v2'
20
21
  require 'open-uri'
@@ -32,6 +33,10 @@ module Fluent
32
33
  include Fluent::Config
33
34
  Fluent::Plugin.register_filter('analyze_config', self)
34
35
 
36
+ # Required for the timer_execute method below
37
+ include PluginHelper::Mixin
38
+ helpers :timer
39
+
35
40
  module Constants
36
41
  # Built-in plugins that are ok to reference in metrics.
37
42
  KNOWN_PLUGINS = {
@@ -212,7 +217,7 @@ module Fluent
212
217
  if File.file?(@google_fluentd_config_path) &&
213
218
  File.file?(@google_fluentd_baseline_config_path)
214
219
  @log.info(
215
- 'google-fluentd configuration file found at' \
220
+ 'analyze_config plugin: google-fluentd configuration file found at' \
216
221
  " #{@google_fluentd_config_path}. " \
217
222
  'google-fluentd baseline configuration file found at' \
218
223
  " #{@google_fluentd_baseline_config_path}. " \
@@ -240,27 +245,49 @@ module Fluent
240
245
  "analyze_config plugin: monitoring_type #{@monitoring_type} is " \
241
246
  'unknown; there will be no metrics.')
242
247
  end
243
- registry = Monitoring::MonitoringRegistryFactory.create(
248
+
249
+ @registry = Monitoring::MonitoringRegistryFactory.create(
244
250
  @monitoring_type, project_id, resource, @gcm_service_address)
251
+ # Export metrics every 60 seconds.
252
+ timer_execute(:export_config_analysis_metrics, 60) { @registry.export }
245
253
 
246
- plugin_usage = registry.counter(
254
+ @log.info('analyze_config plugin: Registering counters.')
255
+ enabled_plugins_counter = @registry.counter(
247
256
  :enabled_plugins,
248
- [:plugin_name, :is_default_plugin, :has_default_config],
257
+ [:plugin_name, :is_default_plugin,
258
+ :has_default_config, :has_ruby_snippet],
249
259
  'Enabled plugins',
250
- 'agent.googleapis.com/agent/internal/logging/config')
251
- config_usage = registry.counter(
260
+ 'agent.googleapis.com/agent/internal/logging/config',
261
+ 'GAUGE')
262
+ @log.info(
263
+ 'analyze_config plugin: registered enable_plugins counter. ' \
264
+ "#{enabled_plugins_counter}")
265
+ plugin_config_counter = @registry.counter(
252
266
  :plugin_config,
253
267
  [:plugin_name, :param, :is_present, :has_default_config],
254
268
  'Configuration parameter usage for plugins relevant to Google Cloud.',
255
- 'agent.googleapis.com/agent/internal/logging/config')
256
- config_bool_values = registry.counter(
269
+ 'agent.googleapis.com/agent/internal/logging/config',
270
+ 'GAUGE')
271
+ @log.info('analyze_config plugin: registered plugin_config counter. ' \
272
+ "#{plugin_config_counter}")
273
+ config_bool_values_counter = @registry.counter(
257
274
  :config_bool_values,
258
275
  [:plugin_name, :param, :value],
259
276
  'Values for bool parameters in Google Cloud plugins',
260
- 'agent.googleapis.com/agent/internal/logging/config')
277
+ 'agent.googleapis.com/agent/internal/logging/config',
278
+ 'GAUGE')
279
+ @log.info('analyze_config plugin: registered config_bool_values ' \
280
+ "counter. #{config_bool_values_counter}")
261
281
 
262
282
  config = parse_config(@google_fluentd_config_path)
283
+ @log.debug(
284
+ 'analyze_config plugin: successfully parsed google-fluentd' \
285
+ " configuration file at #{@google_fluentd_config_path}. #{config}")
263
286
  baseline_config = parse_config(@google_fluentd_baseline_config_path)
287
+ @log.debug(
288
+ 'analyze_config plugin: successfully parsed google-fluentd' \
289
+ ' baseline configuration file at' \
290
+ " #{@google_fluentd_baseline_config_path}: #{baseline_config}")
264
291
 
265
292
  # Create hash of all baseline elements by their plugin names.
266
293
  baseline_elements = Hash[baseline_config.elements.collect do |e|
@@ -290,7 +317,7 @@ module Fluent
290
317
  is_default_plugin = false
291
318
  has_default_config = false
292
319
  end
293
- plugin_usage.increment(
320
+ enabled_plugins_counter.increment(
294
321
  labels: {
295
322
  plugin_name: plugin_name,
296
323
  is_default_plugin: is_default_plugin,
@@ -303,7 +330,7 @@ module Fluent
303
330
  # detect_exceptions).
304
331
  next unless GOOGLE_PLUGIN_PARAMS.key?(e['@type'])
305
332
  GOOGLE_PLUGIN_PARAMS[e['@type']].each do |p|
306
- config_usage.increment(
333
+ plugin_config_counter.increment(
307
334
  labels: {
308
335
  plugin_name: e['@type'],
309
336
  param: p,
@@ -314,7 +341,7 @@ module Fluent
314
341
  },
315
342
  by: 1)
316
343
  next unless e.key?(p) && %w(true false).include?(e[p])
317
- config_bool_values.increment(
344
+ config_bool_values_counter.increment(
318
345
  labels: {
319
346
  plugin_name: e['@type'],
320
347
  param: p,
@@ -323,6 +350,8 @@ module Fluent
323
350
  by: 1)
324
351
  end
325
352
  end
353
+ @log.info(
354
+ 'analyze_config plugin: Successfully finished analyzing config.')
326
355
  else
327
356
  @log.info(
328
357
  'analyze_config plugin: google-fluentd configuration file does not ' \
@@ -341,6 +370,9 @@ module Fluent
341
370
 
342
371
  def shutdown
343
372
  super
373
+ # Export metrics on shutdown. This is a best-effort attempt, and it might
374
+ # fail, for instance if there was a recent write to the same time series.
375
+ @registry.export unless @registry.nil?
344
376
  end
345
377
 
346
378
  # rubocop:disable Lint/UnusedMethodArgument
@@ -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, _prefix)
55
+ def counter(_name, _labels, _docstring, _prefix, _aggregation)
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, _prefix)
78
+ def counter(name, _labels, docstring, _prefix, _aggregation)
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
@@ -102,12 +102,18 @@ module Monitoring
102
102
  @gcm_service_address = gcm_service_address
103
103
  @recorders = {}
104
104
  @exporters = {}
105
+ @log.info(
106
+ 'monitoring module: Successfully initialized Open Census monitoring ' \
107
+ 'registry.')
105
108
  end
106
109
 
107
- def counter(name, labels, docstring, prefix)
110
+ def counter(name, labels, docstring, prefix, aggregation)
108
111
  translator = MetricTranslator.new(name, labels)
109
112
  measure = OpenCensus::Stats::MeasureRegistry.get(translator.name)
110
113
  if measure.nil?
114
+ @log.info(
115
+ 'monitoring module: Registering a new measure registry for ' \
116
+ "#{translator.name}")
111
117
  measure = OpenCensus::Stats.create_measure_int(
112
118
  name: translator.name,
113
119
  unit: OpenCensus::Stats::Measure::UNIT_NONE,
@@ -115,7 +121,10 @@ module Monitoring
115
121
  )
116
122
  end
117
123
  unless @exporters.keys.include?(prefix)
118
- @recorders[prefix] = OpenCensus::Stats.ensure_recorder
124
+ @log.info(
125
+ 'monitoring module: Registering a new exporter for ' \
126
+ "#{prefix}")
127
+ @recorders[prefix] = OpenCensus::Stats::Recorder.new
119
128
  @exporters[prefix] = \
120
129
  OpenCensus::Stats::Exporters::Stackdriver.new(
121
130
  project_id: @project_id,
@@ -124,25 +133,47 @@ module Monitoring
124
133
  resource_labels: @metrics_monitored_resource.labels,
125
134
  gcm_service_address: @gcm_service_address
126
135
  )
136
+ @log.info(
137
+ 'monitoring module: Registered recorders and exporters for ' \
138
+ "#{prefix}.\n#{@exporters[prefix]}")
127
139
  end
128
- OpenCensus::Stats.create_and_register_view(
129
- name: translator.name,
130
- measure: measure,
131
- aggregation: OpenCensus::Stats.create_sum_aggregation,
132
- description: docstring,
133
- columns: translator.view_labels.map(&:to_s)
140
+ if aggregation == 'GAUGE'
141
+ stats_aggregation = OpenCensus::Stats.create_last_value_aggregation
142
+ else
143
+ stats_aggregation = OpenCensus::Stats.create_sum_aggregation
144
+ end
145
+ @recorders[prefix].register_view(
146
+ OpenCensus::Stats::View.new(
147
+ name: translator.name,
148
+ measure: measure,
149
+ aggregation: stats_aggregation,
150
+ description: docstring,
151
+ columns: translator.view_labels.map(&:to_s)
152
+ )
134
153
  )
135
- OpenCensusCounter.new(@recorders[prefix], measure, translator)
154
+ counter = OpenCensusCounter.new(@recorders[prefix], measure, translator)
155
+ @log.info(
156
+ 'monitoring module: Successfully initialized Open Census counter for ' \
157
+ "#{prefix}/#{name}.")
158
+ counter
136
159
  rescue StandardError => e
137
160
  @log.warn "Failed to count metrics for #{name}.", error: e
138
161
  raise e
139
162
  end
140
163
 
141
164
  def export
165
+ @log.debug(
166
+ "monitoring module: Exporting metrics for #{@exporters.keys}.")
142
167
  @exporters.keys.each do |prefix|
168
+ @log.debug(
169
+ "monitoring module: Exporting metrics for #{prefix}. " \
170
+ "#{@recorders[prefix].views_data}")
143
171
  @exporters[prefix].export @recorders[prefix].views_data
144
172
  end
145
173
  rescue StandardError => e
174
+ # TODO(lingshi): Fix the error handling here. Seems like the export is
175
+ # done asynchronously. So any failure happens silently. More details at
176
+ # https://github.com/census-ecosystem/opencensus-ruby-exporter-stackdriver/blob/f8de506204972548ca535eff6010d15f328df6c3/lib/opencensus/stats/exporters/stackdriver.rb#L156
146
177
  @log.warn 'Failed to export some metrics.', error: e
147
178
  raise e
148
179
  end
@@ -564,37 +564,37 @@ module Fluent
564
564
  # we can't change it.
565
565
  @uptime_metric = @registry.counter(
566
566
  :uptime, [:version], 'Uptime of Logging agent',
567
- 'agent.googleapis.com/agent')
567
+ 'agent.googleapis.com/agent', 'CUMULATIVE')
568
568
  update_uptime
569
569
  timer_execute(:update_uptime, 1) { update_uptime }
570
570
  @successful_requests_count = @registry.counter(
571
571
  :stackdriver_successful_requests_count,
572
572
  [:grpc, :code],
573
573
  'A number of successful requests to the Stackdriver Logging API',
574
- 'agent.googleapis.com/agent')
574
+ 'agent.googleapis.com/agent', 'CUMULATIVE')
575
575
  @failed_requests_count = @registry.counter(
576
576
  :stackdriver_failed_requests_count,
577
577
  [:grpc, :code],
578
578
  'A number of failed requests to the Stackdriver Logging '\
579
579
  'API, broken down by the error code',
580
- 'agent.googleapis.com/agent')
580
+ 'agent.googleapis.com/agent', 'CUMULATIVE')
581
581
  @ingested_entries_count = @registry.counter(
582
582
  :stackdriver_ingested_entries_count,
583
583
  [:grpc, :code],
584
584
  'A number of log entries ingested by Stackdriver Logging',
585
- 'agent.googleapis.com/agent')
585
+ 'agent.googleapis.com/agent', 'CUMULATIVE')
586
586
  @dropped_entries_count = @registry.counter(
587
587
  :stackdriver_dropped_entries_count,
588
588
  [:grpc, :code],
589
589
  'A number of log entries dropped by the Stackdriver output plugin',
590
- 'agent.googleapis.com/agent')
590
+ 'agent.googleapis.com/agent', 'CUMULATIVE')
591
591
  @retried_entries_count = @registry.counter(
592
592
  :stackdriver_retried_entries_count,
593
593
  [:grpc, :code],
594
594
  'The number of log entries that failed to be ingested by '\
595
595
  'the Stackdriver output plugin due to a transient error '\
596
596
  'and were retried',
597
- 'agent.googleapis.com/agent')
597
+ 'agent.googleapis.com/agent', 'CUMULATIVE')
598
598
  @ok_code = @use_grpc ? GRPC::Core::StatusCodes::OK : 200
599
599
  end
600
600