fluent-plugin-google-cloud 0.10.4 → 0.10.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
  SHA256:
3
- metadata.gz: a1e4077eb78db81677fa78de507e0aa13acd11a5a07a94004a4df57b3b3ee09a
4
- data.tar.gz: 03602f3a4196b0527a164954c1015e595b7364728513843304c098f7ce440d20
3
+ metadata.gz: fe8bae5aaf1c56046d8456696abbe28e42deda67ea58033790983bfa1f41c6b8
4
+ data.tar.gz: 5af589942475e72506274487ec0e5e932431d1fef023043d80cf97adc3054bf1
5
5
  SHA512:
6
- metadata.gz: 93388ca7c2229d29dd42e6f9d35972841a4024d9e16fc5403993289c6e48f8911d7a12ff8944b73812b15b0fc2311dbf1919e11581343c90e0dfde599ad6c8a3
7
- data.tar.gz: c04221d3ac69bfaa0a5831830a8138352a3956a3ad9adb9b99df027b1788252b8e1085e58b7ff180d574511f91cf2b408b0405c5310e3fd11982ad9f36f6d1c1
6
+ metadata.gz: '004228fe99d339dcdf71503d9bf503bbbdb1c03ac53067bd8423120fbdbe6f25af4679fcb61e04e1d9d4886e00a1761d90db7af3dea53f7d7e3fdfadde0015a8'
7
+ data.tar.gz: c09da939db031ae5baec55f7e0930f84b7e39ad3d0e36d467d3e7496e9a4c8b5db0080d196d99589971930b2fee6c37818a2f6d959c4e7f4e9f54928a30ed56b
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fluent-plugin-google-cloud (0.10.4)
4
+ fluent-plugin-google-cloud (0.10.5)
5
5
  fluentd (= 1.11.2)
6
6
  google-api-client (= 0.30.8)
7
7
  google-cloud-logging (= 1.6.6)
@@ -27,10 +27,11 @@ GEM
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
+ docile (1.3.4)
34
35
  faraday (0.17.3)
35
36
  multipart-post (>= 1.2, < 3)
36
37
  fluentd (1.11.2)
@@ -131,7 +132,7 @@ GEM
131
132
  parser (2.7.2.0)
132
133
  ast (~> 2.4.1)
133
134
  power_assert (1.2.0)
134
- powerpack (0.1.2)
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.4)
147
149
  rly (0.2.3)
148
150
  rubocop (0.39.0)
149
151
  parser (>= 2.3.0.7, < 3.0)
@@ -151,8 +153,8 @@ 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.2)
156
158
  sigdump (~> 0.2.2)
157
159
  sigdump (0.2.4)
158
160
  signet (0.14.0)
@@ -176,9 +178,9 @@ GEM
176
178
  thor (1.0.1)
177
179
  tins (1.26.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.4)
183
+ tzinfo-data (1.2020.6)
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.4'
13
+ gem.version = '0.10.5'
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,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
 
@@ -37,7 +37,10 @@ module Asserts
37
37
  assert_in_delta expected_ts.tv_nsec, ts_nanos, 600, entry
38
38
  end
39
39
 
40
- def assert_prometheus_metric_value(metric_name, expected_value, labels = {})
40
+ # rubocop:disable Metrics/ParameterLists
41
+ def assert_prometheus_metric_value(metric_name, expected_value, _prefix,
42
+ _aggregation, _test_driver, labels = {})
43
+ # rubocop:enable Metrics/ParameterLists
41
44
  metric = Prometheus::Client.registry.get(metric_name)
42
45
  assert_not_nil(metric)
43
46
  metric_value = if labels == :aggregate
@@ -49,7 +52,10 @@ module Asserts
49
52
  assert_equal(expected_value, metric_value)
50
53
  end
51
54
 
52
- def assert_opencensus_metric_value(metric_name, expected_value, labels = {})
55
+ # rubocop:disable Metrics/ParameterLists
56
+ def assert_opencensus_metric_value(metric_name, expected_value, prefix,
57
+ aggregation, test_driver, labels = {})
58
+ # rubocop:enable Metrics/ParameterLists
53
59
  translator = Monitoring::MetricTranslator.new(metric_name, labels)
54
60
  metric_name = translator.name
55
61
  labels = translator.translate_labels(labels)
@@ -60,18 +66,22 @@ module Asserts
60
66
  # label that never changes during runtime.
61
67
  labels.select! { |k, _| translator.view_labels.include? k }
62
68
  labels = labels.map { |k, v| [k.to_s, v.to_s] }.to_h
63
- stats_recorder = OpenCensus::Stats.ensure_recorder
64
- view_data = stats_recorder.view_data metric_name
65
- assert_not_nil(view_data)
69
+
70
+ registry = test_driver.instance.instance_variable_get(:@registry)
71
+ recorder = registry.instance_variable_get(:@recorders)[prefix]
72
+ view_data = recorder.measure_views_data[metric_name][0].data
73
+ view = recorder.instance_variable_get(:@views)[metric_name]
74
+
75
+ # Assert values in the view.
76
+ assert_kind_of(aggregation, view.aggregation)
77
+ assert_equal(labels.keys, view.columns)
78
+ assert_equal(metric_name, view.measure.name)
79
+ assert_equal('INT64', view.measure.type)
80
+
66
81
  # For now assume all metrics are counters.
67
- assert_kind_of(OpenCensus::Stats::Aggregation::Sum,
68
- view_data.view.aggregation)
69
- assert_true(view_data.view.measure.int64?)
70
- tag_values = view_data.view.columns.map { |column| labels[column] }
82
+ tag_values = view.columns.map { |column| labels[column] }
71
83
  metric_value = 0
72
- if view_data.data.key? tag_values
73
- metric_value = view_data.data[tag_values].value
74
- end
84
+ metric_value = view_data[tag_values].value if view_data.key? tag_values
75
85
  assert_equal(expected_value, metric_value)
76
86
  end
77
87
  end
@@ -943,22 +943,30 @@ module BaseTest
943
943
  d.emit("tag#{i}", 'message' => log_entry(i))
944
944
  end
945
945
  d.run
946
+ @logs_sent.zip(request_log_names).each do |request, log_name|
947
+ assert_equal log_name, request['logName']
948
+ end
949
+ verify_log_entries(log_entry_count, COMPUTE_PARAMS_NO_LOG_NAME,
950
+ 'textPayload') do |entry, entry_index|
951
+ verify_default_log_entry_text(entry['textPayload'], entry_index,
952
+ entry)
953
+ assert_equal entry_log_names[entry_index], entry['logName']
954
+ end
955
+ # Verify the number of requests is different based on whether the
956
+ # 'split_logs_by_tag' flag is enabled.
957
+ assert_prometheus_metric_value(
958
+ :stackdriver_successful_requests_count,
959
+ request_count,
960
+ 'agent.googleapis.com/agent',
961
+ OpenCensus::Stats::Aggregation::Sum, d,
962
+ :aggregate)
963
+ assert_prometheus_metric_value(
964
+ :stackdriver_ingested_entries_count,
965
+ log_entry_count,
966
+ 'agent.googleapis.com/agent',
967
+ OpenCensus::Stats::Aggregation::Sum, d,
968
+ :aggregate)
946
969
  end
947
- @logs_sent.zip(request_log_names).each do |request, log_name|
948
- assert_equal log_name, request['logName']
949
- end
950
- verify_log_entries(log_entry_count, COMPUTE_PARAMS_NO_LOG_NAME,
951
- 'textPayload') do |entry, entry_index|
952
- verify_default_log_entry_text(entry['textPayload'], entry_index,
953
- entry)
954
- assert_equal entry_log_names[entry_index], entry['logName']
955
- end
956
- # Verify the number of requests is different based on whether the
957
- # 'split_logs_by_tag' flag is enabled.
958
- assert_prometheus_metric_value(:stackdriver_successful_requests_count,
959
- request_count, :aggregate)
960
- assert_prometheus_metric_value(:stackdriver_ingested_entries_count,
961
- log_entry_count, :aggregate)
962
970
  end
963
971
  end
964
972
 
@@ -1968,7 +1976,9 @@ module BaseTest
1968
1976
  expected = Time.now.to_i - start_time
1969
1977
  d.instance.update_uptime
1970
1978
  assert_metric_value.call(
1971
- :uptime, expected, version: Fluent::GoogleCloudOutput.version_string)
1979
+ :uptime, expected, 'agent.googleapis.com/agent',
1980
+ OpenCensus::Stats::Aggregation::Sum, d,
1981
+ version: Fluent::GoogleCloudOutput.version_string)
1972
1982
  rescue Test::Unit::AssertionFailedError
1973
1983
  retry if (retries += 1) < 3
1974
1984
  end
@@ -1976,6 +1986,102 @@ module BaseTest
1976
1986
  end
1977
1987
  end
1978
1988
 
1989
+ def test_metrics
1990
+ setup_gce_metadata_stubs
1991
+ [
1992
+ [ENABLE_PROMETHEUS_CONFIG, method(:assert_prometheus_metric_value)],
1993
+ [ENABLE_OPENCENSUS_CONFIG, method(:assert_opencensus_metric_value)]
1994
+ ].each do |config, assert_metric_value|
1995
+ [
1996
+ # Single successful request.
1997
+ [ok_status_code, 1, 1, [0, 0, 0]],
1998
+ # Several successful requests.
1999
+ [ok_status_code, 2, 1, [0, 0, 0]],
2000
+ # Single successful request with several entries.
2001
+ [ok_status_code, 1, 2, [0, 0, 0]],
2002
+ # Single failed request that causes logs to be dropped.
2003
+ [client_error_status_code, 1, 1, [1, 1, 0]],
2004
+ # Single failed request that escalates without logs being dropped with
2005
+ # several entries.
2006
+ [server_error_status_code, 1, 2, [0, 0, 2]]
2007
+ ].each do |code, request_count, entry_count, metric_values|
2008
+ clear_metrics
2009
+ setup_logging_stubs(nil, code, 'SomeMessage') do
2010
+ (1..request_count).each do |request_index|
2011
+ d = create_driver(config)
2012
+ (1..entry_count).each do |entry_index|
2013
+ d.emit('message' => log_entry(entry_index.to_s))
2014
+ end
2015
+ # rubocop:disable Lint/HandleExceptions
2016
+ begin
2017
+ d.run
2018
+ rescue mock_error_type
2019
+ end
2020
+ # rubocop:enable Lint/HandleExceptions
2021
+ failed_requests_count, dropped_entries_count,
2022
+ retried_entries_count = metric_values
2023
+
2024
+ successful_requests_count = \
2025
+ if code != ok_status_code
2026
+ 0
2027
+ elsif config == ENABLE_OPENCENSUS_CONFIG
2028
+ # TODO(b/173215689) Improve the Open Census side of testing.
2029
+ # The test driver instance variables can not survive between
2030
+ # test driver runs. So the open cencensus side counter gets
2031
+ # reset as expected.
2032
+ 1
2033
+ else
2034
+ request_index
2035
+ end
2036
+
2037
+ ingested_entries_count = \
2038
+ if code != ok_status_code
2039
+ 0
2040
+ elsif config == ENABLE_OPENCENSUS_CONFIG
2041
+ # TODO(b/173215689) Improve the Open Census side of testing.
2042
+ # The test driver instance variables can not survive between
2043
+ # test driver runs. So the open cencensus side counter gets
2044
+ # reset as expected.
2045
+ entry_count
2046
+ else
2047
+ request_index * entry_count
2048
+ end
2049
+
2050
+ assert_metric_value.call(:stackdriver_successful_requests_count,
2051
+ successful_requests_count,
2052
+ 'agent.googleapis.com/agent',
2053
+ OpenCensus::Stats::Aggregation::Sum, d,
2054
+ grpc: use_grpc, code: ok_status_code)
2055
+ assert_metric_value.call(:stackdriver_ingested_entries_count,
2056
+ ingested_entries_count,
2057
+ 'agent.googleapis.com/agent',
2058
+ OpenCensus::Stats::Aggregation::Sum, d,
2059
+ grpc: use_grpc, code: ok_status_code)
2060
+ assert_metric_value.call(:stackdriver_retried_entries_count,
2061
+ retried_entries_count,
2062
+ 'agent.googleapis.com/agent',
2063
+ OpenCensus::Stats::Aggregation::Sum, d,
2064
+ grpc: use_grpc, code: code)
2065
+ # Skip failure assertions when code indicates success, because the
2066
+ # assertion will fail in the case when a single metric contains time
2067
+ # series with success and failure events.
2068
+ next if code == ok_status_code
2069
+ assert_metric_value.call(:stackdriver_failed_requests_count,
2070
+ failed_requests_count,
2071
+ 'agent.googleapis.com/agent',
2072
+ OpenCensus::Stats::Aggregation::Sum, d,
2073
+ grpc: use_grpc, code: code)
2074
+ assert_metric_value.call(:stackdriver_dropped_entries_count,
2075
+ dropped_entries_count,
2076
+ 'agent.googleapis.com/agent',
2077
+ OpenCensus::Stats::Aggregation::Sum, d,
2078
+ grpc: use_grpc, code: code)
2079
+ end
2080
+ end
2081
+ end
2082
+ end
2083
+ end
2084
+
1979
2085
  private
1980
2086
 
1981
2087
  # Provide a stub context that initializes @logs_sent, executes the block and
@@ -2456,7 +2562,32 @@ module BaseTest
2456
2562
  end
2457
2563
 
2458
2564
  # Set up http or grpc stubs to mock the external calls.
2459
- def setup_logging_stubs
2565
+ def setup_logging_stubs(_error = nil, _code = nil, _message = nil)
2566
+ _undefined
2567
+ end
2568
+
2569
+ # Whether this is the grpc path
2570
+ def use_grpc
2571
+ _undefined
2572
+ end
2573
+
2574
+ # The OK status code.
2575
+ def ok_status_code
2576
+ _undefined
2577
+ end
2578
+
2579
+ # A client side error status code.
2580
+ def client_error_status_code
2581
+ _undefined
2582
+ end
2583
+
2584
+ # A server side error status code.
2585
+ def server_error_status_code
2586
+ _undefined
2587
+ end
2588
+
2589
+ # The parent error type to expect in the mock
2590
+ def mock_error_type
2460
2591
  _undefined
2461
2592
  end
2462
2593
 
@@ -51,12 +51,15 @@ class FilterAnalyzeConfigTest < Test::Unit::TestCase
51
51
  method(:assert_opencensus_metric_value)]
52
52
  ].each do |config, assert_metric_value|
53
53
  clear_metrics
54
- create_driver(config)
54
+ d = create_driver(config)
55
55
 
56
56
  # Default plugins, with default config.
57
57
  assert_metric_value.call(
58
58
  :enabled_plugins,
59
59
  1,
60
+ 'agent.googleapis.com/agent/internal/logging/config',
61
+ OpenCensus::Stats::Aggregation::LastValue,
62
+ d,
60
63
  plugin_name: 'source/syslog/tcp',
61
64
  is_default_plugin: true,
62
65
  has_default_config: true,
@@ -64,6 +67,9 @@ class FilterAnalyzeConfigTest < Test::Unit::TestCase
64
67
  assert_metric_value.call(
65
68
  :enabled_plugins,
66
69
  1,
70
+ 'agent.googleapis.com/agent/internal/logging/config',
71
+ OpenCensus::Stats::Aggregation::LastValue,
72
+ d,
67
73
  plugin_name: 'source/tail/apache-access',
68
74
  is_default_plugin: true,
69
75
  has_default_config: true,
@@ -71,6 +77,9 @@ class FilterAnalyzeConfigTest < Test::Unit::TestCase
71
77
  assert_metric_value.call(
72
78
  :enabled_plugins,
73
79
  1,
80
+ 'agent.googleapis.com/agent/internal/logging/config',
81
+ OpenCensus::Stats::Aggregation::LastValue,
82
+ d,
74
83
  plugin_name: 'filter/add_insert_ids',
75
84
  is_default_plugin: true,
76
85
  has_default_config: true,
@@ -80,6 +89,9 @@ class FilterAnalyzeConfigTest < Test::Unit::TestCase
80
89
  assert_metric_value.call(
81
90
  :enabled_plugins,
82
91
  1,
92
+ 'agent.googleapis.com/agent/internal/logging/config',
93
+ OpenCensus::Stats::Aggregation::LastValue,
94
+ d,
83
95
  plugin_name: 'match/google_cloud',
84
96
  is_default_plugin: true,
85
97
  has_default_config: false,
@@ -89,6 +101,9 @@ class FilterAnalyzeConfigTest < Test::Unit::TestCase
89
101
  assert_metric_value.call(
90
102
  :enabled_plugins,
91
103
  1,
104
+ 'agent.googleapis.com/agent/internal/logging/config',
105
+ OpenCensus::Stats::Aggregation::LastValue,
106
+ d,
92
107
  plugin_name: 'filter',
93
108
  is_default_plugin: false,
94
109
  has_default_config: false,
@@ -96,6 +111,9 @@ class FilterAnalyzeConfigTest < Test::Unit::TestCase
96
111
  assert_metric_value.call(
97
112
  :enabled_plugins,
98
113
  1,
114
+ 'agent.googleapis.com/agent/internal/logging/config',
115
+ OpenCensus::Stats::Aggregation::LastValue,
116
+ d,
99
117
  plugin_name: 'filter/record_transformer',
100
118
  is_default_plugin: false,
101
119
  has_default_config: false,
@@ -103,6 +121,9 @@ class FilterAnalyzeConfigTest < Test::Unit::TestCase
103
121
  assert_metric_value.call(
104
122
  :enabled_plugins,
105
123
  1,
124
+ 'agent.googleapis.com/agent/internal/logging/config',
125
+ OpenCensus::Stats::Aggregation::LastValue,
126
+ d,
106
127
  plugin_name: 'match/stdout',
107
128
  is_default_plugin: false,
108
129
  has_default_config: false,
@@ -112,6 +133,9 @@ class FilterAnalyzeConfigTest < Test::Unit::TestCase
112
133
  assert_metric_value.call(
113
134
  :plugin_config,
114
135
  1,
136
+ 'agent.googleapis.com/agent/internal/logging/config',
137
+ OpenCensus::Stats::Aggregation::LastValue,
138
+ d,
115
139
  plugin_name: 'google_cloud',
116
140
  param: 'adjust_invalid_timestamps',
117
141
  is_present: true,
@@ -119,6 +143,9 @@ class FilterAnalyzeConfigTest < Test::Unit::TestCase
119
143
  assert_metric_value.call(
120
144
  :plugin_config,
121
145
  1,
146
+ 'agent.googleapis.com/agent/internal/logging/config',
147
+ OpenCensus::Stats::Aggregation::LastValue,
148
+ d,
122
149
  plugin_name: 'google_cloud',
123
150
  param: 'autoformat_stackdriver_trace',
124
151
  is_present: true,
@@ -126,6 +153,9 @@ class FilterAnalyzeConfigTest < Test::Unit::TestCase
126
153
  assert_metric_value.call(
127
154
  :plugin_config,
128
155
  1,
156
+ 'agent.googleapis.com/agent/internal/logging/config',
157
+ OpenCensus::Stats::Aggregation::LastValue,
158
+ d,
129
159
  plugin_name: 'google_cloud',
130
160
  param: 'coerce_to_utf8',
131
161
  is_present: true,
@@ -165,6 +195,9 @@ class FilterAnalyzeConfigTest < Test::Unit::TestCase
165
195
  assert_metric_value.call(
166
196
  :plugin_config,
167
197
  1,
198
+ 'agent.googleapis.com/agent/internal/logging/config',
199
+ OpenCensus::Stats::Aggregation::LastValue,
200
+ d,
168
201
  plugin_name: 'google_cloud',
169
202
  param: p,
170
203
  is_present: false,
@@ -175,18 +208,27 @@ class FilterAnalyzeConfigTest < Test::Unit::TestCase
175
208
  assert_metric_value.call(
176
209
  :config_bool_values,
177
210
  1,
211
+ 'agent.googleapis.com/agent/internal/logging/config',
212
+ OpenCensus::Stats::Aggregation::LastValue,
213
+ d,
178
214
  plugin_name: 'google_cloud',
179
215
  param: 'adjust_invalid_timestamps',
180
216
  value: true)
181
217
  assert_metric_value.call(
182
218
  :config_bool_values,
183
219
  1,
220
+ 'agent.googleapis.com/agent/internal/logging/config',
221
+ OpenCensus::Stats::Aggregation::LastValue,
222
+ d,
184
223
  plugin_name: 'google_cloud',
185
224
  param: 'autoformat_stackdriver_trace',
186
225
  value: false)
187
226
  assert_metric_value.call(
188
227
  :config_bool_values,
189
228
  1,
229
+ 'agent.googleapis.com/agent/internal/logging/config',
230
+ OpenCensus::Stats::Aggregation::LastValue,
231
+ d,
190
232
  plugin_name: 'google_cloud',
191
233
  param: 'coerce_to_utf8',
192
234
  value: true)
@@ -86,13 +86,21 @@ class GoogleCloudOutputTest < Test::Unit::TestCase
86
86
  end
87
87
  d.run
88
88
  assert_prometheus_metric_value(
89
- :stackdriver_successful_requests_count, 1, grpc: false, code: 200)
89
+ :stackdriver_successful_requests_count, 1,
90
+ 'agent.googleapis.com/agent', OpenCensus::Stats::Aggregation::Sum, d,
91
+ grpc: false, code: 200)
90
92
  assert_prometheus_metric_value(
91
- :stackdriver_ingested_entries_count, 1, grpc: false, code: 200)
93
+ :stackdriver_ingested_entries_count, 1,
94
+ 'agent.googleapis.com/agent', OpenCensus::Stats::Aggregation::Sum, d,
95
+ grpc: false, code: 200)
92
96
  assert_prometheus_metric_value(
93
- :stackdriver_dropped_entries_count, 2, grpc: false, code: 3)
97
+ :stackdriver_dropped_entries_count, 2,
98
+ 'agent.googleapis.com/agent', OpenCensus::Stats::Aggregation::Sum, d,
99
+ grpc: false, code: 3)
94
100
  assert_prometheus_metric_value(
95
- :stackdriver_dropped_entries_count, 1, grpc: false, code: 7)
101
+ :stackdriver_dropped_entries_count, 1,
102
+ 'agent.googleapis.com/agent', OpenCensus::Stats::Aggregation::Sum, d,
103
+ grpc: false, code: 7)
96
104
  assert_requested(:post, WRITE_LOG_ENTRIES_URI, times: 1)
97
105
  end
98
106
 
@@ -109,13 +117,21 @@ class GoogleCloudOutputTest < Test::Unit::TestCase
109
117
  d.emit('message' => log_entry(0))
110
118
  d.run
111
119
  assert_prometheus_metric_value(
112
- :stackdriver_successful_requests_count, 0, grpc: false, code: 200)
120
+ :stackdriver_successful_requests_count, 0,
121
+ 'agent.googleapis.com/agent', OpenCensus::Stats::Aggregation::Sum, d,
122
+ grpc: false, code: 200)
113
123
  assert_prometheus_metric_value(
114
- :stackdriver_failed_requests_count, 1, grpc: false, code: 400)
124
+ :stackdriver_failed_requests_count, 1,
125
+ 'agent.googleapis.com/agent', OpenCensus::Stats::Aggregation::Sum, d,
126
+ grpc: false, code: 400)
115
127
  assert_prometheus_metric_value(
116
- :stackdriver_ingested_entries_count, 0, grpc: false, code: 200)
128
+ :stackdriver_ingested_entries_count, 0,
129
+ 'agent.googleapis.com/agent', OpenCensus::Stats::Aggregation::Sum, d,
130
+ grpc: false, code: 200)
117
131
  assert_prometheus_metric_value(
118
- :stackdriver_dropped_entries_count, 1, grpc: false, code: 400)
132
+ :stackdriver_dropped_entries_count, 1,
133
+ 'agent.googleapis.com/agent', OpenCensus::Stats::Aggregation::Sum, d,
134
+ grpc: false, code: 400)
119
135
  assert_requested(:post, WRITE_LOG_ENTRIES_URI, times: 1)
120
136
  end
121
137
 
@@ -138,71 +154,6 @@ class GoogleCloudOutputTest < Test::Unit::TestCase
138
154
  assert_equal 1, exception_count
139
155
  end
140
156
 
141
- # TODO: The code in the non-gRPC and gRPC tests is nearly identical.
142
- # Refactor and remove duplication.
143
- # TODO: Use status codes instead of int literals.
144
- def test_metrics
145
- setup_gce_metadata_stubs
146
- [
147
- [ENABLE_PROMETHEUS_CONFIG, method(:assert_prometheus_metric_value)],
148
- [ENABLE_OPENCENSUS_CONFIG, method(:assert_opencensus_metric_value)]
149
- ].each do |config, assert_metric_value|
150
- [
151
- # Single successful request.
152
- [200, 1, 1, [1, 0, 1, 0, 0]],
153
- # Several successful requests.
154
- [200, 2, 1, [2, 0, 2, 0, 0]],
155
- # Single successful request with several entries.
156
- [200, 1, 2, [1, 0, 2, 0, 0]],
157
- # Single failed request that causes logs to be dropped.
158
- [401, 1, 1, [0, 1, 0, 1, 0]],
159
- # Single failed request that escalates without logs being dropped with
160
- # several entries.
161
- [500, 1, 2, [0, 0, 0, 0, 2]]
162
- ].each do |code, request_count, entry_count, metric_values|
163
- clear_metrics
164
- # TODO: Do this as part of setup_logging_stubs.
165
- stub_request(:post, WRITE_LOG_ENTRIES_URI)
166
- .to_return(status: code, body: 'Some Message')
167
- (1..request_count).each do
168
- d = create_driver(config)
169
- (1..entry_count).each do |i|
170
- d.emit('message' => log_entry(i.to_s))
171
- end
172
- # rubocop:disable Lint/HandleExceptions
173
- begin
174
- d.run
175
- rescue Google::Apis::AuthorizationError
176
- rescue Google::Apis::ServerError
177
- end
178
- # rubocop:enable Lint/HandleExceptions
179
- end
180
- successful_requests_count, failed_requests_count,
181
- ingested_entries_count, dropped_entries_count,
182
- retried_entries_count = metric_values
183
- assert_metric_value.call(:stackdriver_successful_requests_count,
184
- successful_requests_count,
185
- grpc: false, code: 200)
186
- assert_metric_value.call(:stackdriver_ingested_entries_count,
187
- ingested_entries_count,
188
- grpc: false, code: 200)
189
- assert_metric_value.call(:stackdriver_retried_entries_count,
190
- retried_entries_count,
191
- grpc: false, code: code)
192
- # Skip failure assertions when code indicates success, because the
193
- # assertion will fail in the case when a single metric contains time
194
- # series with success and failure events.
195
- next if code == 200
196
- assert_metric_value.call(:stackdriver_failed_requests_count,
197
- failed_requests_count,
198
- grpc: false, code: code)
199
- assert_metric_value.call(:stackdriver_dropped_entries_count,
200
- dropped_entries_count,
201
- grpc: false, code: code)
202
- end
203
- end
204
- end
205
-
206
157
  # This test looks similar between the grpc and non-grpc paths except that when
207
158
  # parsing "105", the grpc path responds with "DEBUG", while the non-grpc path
208
159
  # responds with "100".
@@ -400,14 +351,39 @@ class GoogleCloudOutputTest < Test::Unit::TestCase
400
351
  end
401
352
 
402
353
  # Set up http stubs to mock the external calls.
403
- def setup_logging_stubs
354
+ def setup_logging_stubs(_error = nil, code = nil, message = 'some message')
404
355
  stub_request(:post, WRITE_LOG_ENTRIES_URI).to_return do |request|
405
356
  @logs_sent << JSON.parse(request.body)
406
- { body: '' }
357
+ { status: code, body: message }
407
358
  end
408
359
  yield
409
360
  end
410
361
 
362
+ # Whether this is the grpc path
363
+ def use_grpc
364
+ false
365
+ end
366
+
367
+ # The OK status code for the grpc path.
368
+ def ok_status_code
369
+ 200
370
+ end
371
+
372
+ # A client side error status code for the grpc path.
373
+ def client_error_status_code
374
+ 401
375
+ end
376
+
377
+ # A server side error status code for the grpc path.
378
+ def server_error_status_code
379
+ 500
380
+ end
381
+
382
+ # The parent error type to expect in the mock
383
+ def mock_error_type
384
+ Google::Apis::Error
385
+ end
386
+
411
387
  # The conversions from user input to output.
412
388
  def latency_conversion
413
389
  {
@@ -60,8 +60,7 @@ class GoogleCloudOutputGRPCTest < Test::Unit::TestCase
60
60
  GRPC::Core::StatusCodes::ABORTED => 'Aborted',
61
61
  GRPC::Core::StatusCodes::UNAUTHENTICATED => 'Unauthenticated'
62
62
  }.each_with_index do |(code, message), index|
63
- setup_logging_stubs(
64
- GRPC::BadStatus.new_status_exception(code, message)) do
63
+ setup_logging_stubs(nil, code, message) do
65
64
  d = create_driver(USE_GRPC_CONFIG, 'test')
66
65
  # The API Client should not retry this and the plugin should consume the
67
66
  # exception.
@@ -99,19 +98,24 @@ class GoogleCloudOutputGRPCTest < Test::Unit::TestCase
99
98
  d.run
100
99
  assert_prometheus_metric_value(
101
100
  :stackdriver_successful_requests_count, 1,
102
- grpc: true, code: GRPC::Core::StatusCodes::OK)
101
+ 'agent.googleapis.com/agent', OpenCensus::Stats::Aggregation::Sum, d,
102
+ grpc: use_grpc, code: GRPC::Core::StatusCodes::OK)
103
103
  assert_prometheus_metric_value(
104
104
  :stackdriver_failed_requests_count, 0,
105
- grpc: true, code: GRPC::Core::StatusCodes::PERMISSION_DENIED)
105
+ 'agent.googleapis.com/agent', OpenCensus::Stats::Aggregation::Sum, d,
106
+ grpc: use_grpc, code: GRPC::Core::StatusCodes::PERMISSION_DENIED)
106
107
  assert_prometheus_metric_value(
107
108
  :stackdriver_ingested_entries_count, 1,
108
- grpc: true, code: GRPC::Core::StatusCodes::OK)
109
+ 'agent.googleapis.com/agent', OpenCensus::Stats::Aggregation::Sum, d,
110
+ grpc: use_grpc, code: GRPC::Core::StatusCodes::OK)
109
111
  assert_prometheus_metric_value(
110
112
  :stackdriver_dropped_entries_count, 2,
111
- grpc: true, code: GRPC::Core::StatusCodes::INVALID_ARGUMENT)
113
+ 'agent.googleapis.com/agent', OpenCensus::Stats::Aggregation::Sum, d,
114
+ grpc: use_grpc, code: GRPC::Core::StatusCodes::INVALID_ARGUMENT)
112
115
  assert_prometheus_metric_value(
113
116
  :stackdriver_dropped_entries_count, 1,
114
- grpc: true, code: GRPC::Core::StatusCodes::PERMISSION_DENIED)
117
+ 'agent.googleapis.com/agent', OpenCensus::Stats::Aggregation::Sum, d,
118
+ grpc: use_grpc, code: GRPC::Core::StatusCodes::PERMISSION_DENIED)
115
119
  end
116
120
  end
117
121
 
@@ -128,16 +132,20 @@ class GoogleCloudOutputGRPCTest < Test::Unit::TestCase
128
132
  d.run
129
133
  assert_prometheus_metric_value(
130
134
  :stackdriver_successful_requests_count, 0,
131
- grpc: true, code: GRPC::Core::StatusCodes::OK)
135
+ 'agent.googleapis.com/agent', OpenCensus::Stats::Aggregation::Sum, d,
136
+ grpc: use_grpc, code: GRPC::Core::StatusCodes::OK)
132
137
  assert_prometheus_metric_value(
133
138
  :stackdriver_failed_requests_count, 1,
134
- grpc: true, code: GRPC::Core::StatusCodes::INVALID_ARGUMENT)
139
+ 'agent.googleapis.com/agent', OpenCensus::Stats::Aggregation::Sum, d,
140
+ grpc: use_grpc, code: GRPC::Core::StatusCodes::INVALID_ARGUMENT)
135
141
  assert_prometheus_metric_value(
136
142
  :stackdriver_ingested_entries_count, 0,
137
- grpc: true, code: GRPC::Core::StatusCodes::OK)
143
+ 'agent.googleapis.com/agent', OpenCensus::Stats::Aggregation::Sum, d,
144
+ grpc: use_grpc, code: GRPC::Core::StatusCodes::OK)
138
145
  assert_prometheus_metric_value(
139
146
  :stackdriver_dropped_entries_count, 1,
140
- grpc: true, code: GRPC::Core::StatusCodes::INVALID_ARGUMENT)
147
+ 'agent.googleapis.com/agent', OpenCensus::Stats::Aggregation::Sum, d,
148
+ grpc: use_grpc, code: GRPC::Core::StatusCodes::INVALID_ARGUMENT)
141
149
  end
142
150
  end
143
151
 
@@ -150,8 +158,7 @@ class GoogleCloudOutputGRPCTest < Test::Unit::TestCase
150
158
  GRPC::Core::StatusCodes::UNAVAILABLE => 'Unavailable'
151
159
  }.each_with_index do |(code, message), index|
152
160
  exception_count = 0
153
- setup_logging_stubs(
154
- GRPC::BadStatus.new_status_exception(code, message)) do
161
+ setup_logging_stubs(nil, code, message) do
155
162
  d = create_driver(USE_GRPC_CONFIG, 'test')
156
163
  # The API client should retry this once, then throw an exception which
157
164
  # gets propagated through the plugin
@@ -168,72 +175,6 @@ class GoogleCloudOutputGRPCTest < Test::Unit::TestCase
168
175
  end
169
176
  end
170
177
 
171
- # TODO: The code in the non-gRPC and gRPC tests is nearly identical.
172
- # Refactor and remove duplication.
173
- # TODO: Use status codes instead of int literals.
174
- def test_metrics
175
- setup_gce_metadata_stubs
176
- [
177
- [ENABLE_PROMETHEUS_CONFIG, method(:assert_prometheus_metric_value)],
178
- [ENABLE_OPENCENSUS_CONFIG, method(:assert_opencensus_metric_value)]
179
- ].each do |config, assert_metric_value|
180
- [
181
- # Single successful request.
182
- [false, 0, 1, 1, [1, 0, 1, 0, 0]],
183
- # Several successful requests.
184
- [false, 0, 2, 1, [2, 0, 2, 0, 0]],
185
- # Single successful request with several entries.
186
- [false, 0, 1, 2, [1, 0, 2, 0, 0]],
187
- # Single failed request that causes logs to be dropped.
188
- [true, 16, 1, 1, [0, 1, 0, 1, 0]],
189
- # Single failed request that escalates without logs being dropped with
190
- # several entries.
191
- [true, 13, 1, 2, [0, 0, 0, 0, 2]]
192
- ].each do |should_fail, code, request_count, entry_count, metric_values|
193
- clear_metrics
194
- (1..request_count).each do
195
- setup_logging_stubs(
196
- if should_fail
197
- GRPC::BadStatus.new_status_exception(code, 'SomeMessage')
198
- end) do
199
- d = create_driver(USE_GRPC_CONFIG + config, 'test')
200
- (1..entry_count).each do |i|
201
- d.emit('message' => log_entry(i.to_s))
202
- end
203
- # rubocop:disable Lint/HandleExceptions
204
- begin
205
- d.run
206
- rescue GRPC::BadStatus
207
- end
208
- # rubocop:enable Lint/HandleExceptions
209
- end
210
- end
211
- successful_requests_count, failed_requests_count,
212
- ingested_entries_count, dropped_entries_count,
213
- retried_entries_count = metric_values
214
- assert_metric_value.call(:stackdriver_successful_requests_count,
215
- successful_requests_count,
216
- grpc: true, code: 0)
217
- assert_metric_value.call(:stackdriver_ingested_entries_count,
218
- ingested_entries_count,
219
- grpc: true, code: 0)
220
- assert_metric_value.call(:stackdriver_retried_entries_count,
221
- retried_entries_count,
222
- grpc: true, code: code)
223
- # Skip failure assertions when code indicates success, because the
224
- # assertion will fail in the case when a single metric contains time
225
- # series with success and failure events.
226
- next if code == 0
227
- assert_metric_value.call(:stackdriver_failed_requests_count,
228
- failed_requests_count,
229
- grpc: true, code: code)
230
- assert_metric_value.call(:stackdriver_dropped_entries_count,
231
- dropped_entries_count,
232
- grpc: true, code: code)
233
- end
234
- end
235
- end
236
-
237
178
  # This test looks similar between the grpc and non-grpc paths except that when
238
179
  # parsing "105", the grpc path responds with "DEBUG", while the non-grpc path
239
180
  # responds with "100".
@@ -428,17 +369,45 @@ class GoogleCloudOutputGRPCTest < Test::Unit::TestCase
428
369
  end
429
370
 
430
371
  # Set up grpc stubs to mock the external calls.
431
- def setup_logging_stubs(error = nil)
432
- if error.nil?
372
+ def setup_logging_stubs(error = nil, code = nil, message = 'some message')
373
+ if error.nil? && (code.nil? || code == 0)
433
374
  @requests_sent = []
434
375
  @grpc_stub = GRPCLoggingMockService.new(@requests_sent)
435
376
  else
436
377
  @failed_attempts = []
378
+ # Only fall back to constructing an error with code and message if no
379
+ # error is passed in.
380
+ error ||= GRPC::BadStatus.new_status_exception(code, message)
437
381
  @grpc_stub = GRPCLoggingMockFailingService.new(error, @failed_attempts)
438
382
  end
439
383
  yield
440
384
  end
441
385
 
386
+ # Whether this is the grpc path
387
+ def use_grpc
388
+ true
389
+ end
390
+
391
+ # The OK status code for the grpc path.
392
+ def ok_status_code
393
+ 0
394
+ end
395
+
396
+ # A client side error status code for the grpc path.
397
+ def client_error_status_code
398
+ 16
399
+ end
400
+
401
+ # A server side error status code for the grpc path.
402
+ def server_error_status_code
403
+ 13
404
+ end
405
+
406
+ # The parent error type to expect in the mock
407
+ def mock_error_type
408
+ GRPC::BadStatus
409
+ end
410
+
442
411
  # Verify the number and the content of the log entries match the expectation.
443
412
  # The caller can optionally provide a block which is called for each entry.
444
413
  def verify_log_entries(n, params, payload_type = 'textPayload',
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.4
4
+ version: 0.10.5
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-10-29 00:00:00.000000000 Z
11
+ date: 2021-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd