fluent-plugin-google-cloud 0.8.7 → 0.9.0

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: 851c496e93becdfb6a735f9c71aceecfdeccfff14519ce8311bb3dd42c7ed382
4
- data.tar.gz: d893b865df5a2b10bac43c65381abe1b95e27333ff77ac45c6cb988c2f446036
3
+ metadata.gz: 2969a92cd254d0b7e3a8fa3fcf891df2ec8cbaa3b94c5d683db3d6c43ee2d11f
4
+ data.tar.gz: 78b2418688ff2ac6a939ebf1d19d81e61a40a1cea7793c35c2044ac6969f44ac
5
5
  SHA512:
6
- metadata.gz: 6f840e9c06e995be5dd4abd0dcd9d04042c6d78507896fc842ab2b1fb8cb82eac4535fdb6259656cc703e99955e074e64c1ec0292c31d77647cbc95d54e7b919
7
- data.tar.gz: c1573f562d3691a83b8b3dd2b8e8a0ed1585edac5f67df6179bc8c62af4a3728ce97b90be8827008718921069806eb6e0d2e81fd5c7f6de4c6603a1c2738774e
6
+ metadata.gz: bd4ccb079e3f1af0d0d9efb8d7165a04dcbfdcb2b21f8471a0b80f5c157b4d4e5a968f63e0c6a7c92f746fd34c2d46319037b883dec6abd301df78771ca201ed
7
+ data.tar.gz: bcf8016d3dbbd7fbfb6c2cc1bc2de490e89c61c1a51fe7c91324034fcca2a96d8b55059d197bbbe2ad3acfabfcb632ff3e917c7f54aa3061d36b6f0c2b9f1959
@@ -1,14 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fluent-plugin-google-cloud (0.8.7)
4
+ fluent-plugin-google-cloud (0.9.0)
5
5
  fluentd (= 1.7.4)
6
6
  google-api-client (= 0.30.8)
7
7
  google-cloud-logging (= 1.6.6)
8
- google-protobuf (= 3.9.0)
8
+ google-protobuf (= 3.12.2)
9
9
  googleapis-common-protos (= 1.3.9)
10
10
  googleauth (= 0.9.0)
11
- grpc (= 1.22.0)
11
+ grpc (= 1.30.1)
12
12
  json (= 2.2.0)
13
13
  opencensus (= 0.5.0)
14
14
  opencensus-stackdriver (= 0.3.2)
@@ -29,7 +29,7 @@ GEM
29
29
  tins (~> 1.6)
30
30
  crack (0.4.3)
31
31
  safe_yaml (~> 1.0.0)
32
- declarative (0.0.10)
32
+ declarative (0.0.20)
33
33
  declarative-option (0.1.0)
34
34
  dig_rb (1.0.1)
35
35
  docile (1.3.2)
@@ -57,7 +57,7 @@ GEM
57
57
  google-cloud-core (1.5.0)
58
58
  google-cloud-env (~> 1.0)
59
59
  google-cloud-errors (~> 1.0)
60
- google-cloud-env (1.3.2)
60
+ google-cloud-env (1.3.3)
61
61
  faraday (>= 0.17.3, < 2.0)
62
62
  google-cloud-errors (1.0.1)
63
63
  google-cloud-logging (1.6.6)
@@ -66,27 +66,30 @@ GEM
66
66
  google-gax (~> 1.7)
67
67
  googleapis-common-protos-types (>= 1.0.2)
68
68
  stackdriver-core (~> 1.3)
69
- google-cloud-monitoring (0.32.0)
70
- google-gax (~> 1.7)
71
- googleapis-common-protos-types (>= 1.0.2)
72
- google-cloud-trace (0.35.0)
69
+ google-cloud-monitoring (0.38.0)
70
+ google-gax (~> 1.8)
71
+ googleapis-common-protos (>= 1.3.9, < 2.0)
72
+ googleapis-common-protos-types (>= 1.0.4, < 2.0)
73
+ google-cloud-trace (0.39.0)
73
74
  concurrent-ruby (~> 1.1)
74
75
  google-cloud-core (~> 1.2)
75
- google-gax (~> 1.7)
76
+ google-gax (~> 1.8)
77
+ googleapis-common-protos (>= 1.3.9, < 2.0)
78
+ googleapis-common-protos-types (>= 1.0.4, < 2.0)
76
79
  stackdriver-core (~> 1.3)
77
- google-gax (1.7.1)
78
- google-protobuf (~> 3.2)
79
- googleapis-common-protos (>= 1.3.5, < 2.0)
80
- googleauth (>= 0.6.2, < 0.10.0)
81
- grpc (>= 1.7.2, < 2.0)
80
+ google-gax (1.8.1)
81
+ google-protobuf (~> 3.9)
82
+ googleapis-common-protos (>= 1.3.9, < 2.0)
83
+ googleauth (~> 0.9)
84
+ grpc (~> 1.24)
82
85
  rly (~> 0.2.3)
83
- google-protobuf (3.9.0)
86
+ google-protobuf (3.12.2)
84
87
  googleapis-common-protos (1.3.9)
85
88
  google-protobuf (~> 3.0)
86
89
  googleapis-common-protos-types (~> 1.0)
87
90
  grpc (~> 1.0)
88
- googleapis-common-protos-types (1.0.4)
89
- google-protobuf (~> 3.0)
91
+ googleapis-common-protos-types (1.0.5)
92
+ google-protobuf (~> 3.11)
90
93
  googleauth (0.9.0)
91
94
  faraday (~> 0.12)
92
95
  jwt (>= 1.4, < 3.0)
@@ -94,8 +97,8 @@ GEM
94
97
  multi_json (~> 1.11)
95
98
  os (>= 0.9, < 2.0)
96
99
  signet (~> 0.7)
97
- grpc (1.22.0)
98
- google-protobuf (~> 3.8)
100
+ grpc (1.30.1)
101
+ google-protobuf (~> 3.12)
99
102
  googleapis-common-protos-types (~> 1.0)
100
103
  hashdiff (1.0.1)
101
104
  http_parser.rb (0.6.0)
@@ -108,7 +111,7 @@ GEM
108
111
  mocha (1.9.0)
109
112
  metaclass (~> 0.0.1)
110
113
  msgpack (1.3.3)
111
- multi_json (1.14.1)
114
+ multi_json (1.15.0)
112
115
  multipart-post (2.1.1)
113
116
  opencensus (0.5.0)
114
117
  opencensus-stackdriver (0.3.2)
@@ -117,8 +120,8 @@ GEM
117
120
  google-cloud-trace (~> 0.35)
118
121
  opencensus (~> 0.5)
119
122
  os (1.1.0)
120
- parser (2.7.1.3)
121
- ast (~> 2.4.0)
123
+ parser (2.7.1.4)
124
+ ast (~> 2.4.1)
122
125
  power_assert (1.2.0)
123
126
  powerpack (0.1.2)
124
127
  prometheus-client (0.9.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.8.7'
13
+ gem.version = '0.9.0'
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')
@@ -24,8 +24,8 @@ eos
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.9.0'
28
- gem.add_runtime_dependency 'grpc', '1.22.0'
27
+ gem.add_runtime_dependency 'google-protobuf', '3.12.2'
28
+ gem.add_runtime_dependency 'grpc', '1.30.1'
29
29
  gem.add_runtime_dependency 'json', '2.2.0'
30
30
  gem.add_runtime_dependency 'opencensus', '0.5.0'
31
31
  gem.add_runtime_dependency 'opencensus-stackdriver', '0.3.2'
@@ -219,6 +219,12 @@ module Common
219
219
  @log.error 'Failed to obtain location: ', error: e
220
220
  end
221
221
 
222
+ # Create a monitored resource from type and labels.
223
+ def create_monitored_resource(type, labels)
224
+ Google::Apis::LoggingV2::MonitoredResource.new(
225
+ type: type, labels: labels.to_h)
226
+ end
227
+
222
228
  # Retrieve monitored resource via the legacy way.
223
229
  #
224
230
  # Note: This is just a failover plan if we fail to get metadata from
@@ -226,13 +232,12 @@ module Common
226
232
  # returns.
227
233
  def determine_agent_level_monitored_resource_via_legacy(
228
234
  platform, subservice_name, detect_subservice, vm_id, zone)
229
- resource = Google::Apis::LoggingV2::MonitoredResource.new(
230
- labels: {})
231
- resource.type = determine_agent_level_monitored_resource_type(
235
+ resource_type = determine_agent_level_monitored_resource_type(
232
236
  platform, subservice_name, detect_subservice)
233
- resource.labels = determine_agent_level_monitored_resource_labels(
234
- platform, resource.type, vm_id, zone)
235
- resource
237
+ create_monitored_resource(
238
+ resource_type,
239
+ determine_agent_level_monitored_resource_labels(
240
+ platform, resource_type, vm_id, zone))
236
241
  end
237
242
 
238
243
  # Determine agent level monitored resource type.
@@ -17,6 +17,7 @@ require 'fluent/config'
17
17
  require 'fluent/config/v1_parser'
18
18
  require 'set'
19
19
 
20
+ require_relative 'common'
20
21
  require_relative 'monitoring'
21
22
 
22
23
  module Fluent
@@ -122,16 +123,33 @@ module Fluent
122
123
 
123
124
  include self::Constants
124
125
 
126
+ # Disable this warning to conform to fluentd config_param conventions.
127
+ # rubocop:disable Style/HashSyntax
128
+
125
129
  # The root configuration file of google-fluentd package.
126
130
  # This only applies to Linux.
127
131
  config_param :google_fluentd_config_path,
128
132
  :string,
129
- default: '/etc/google-fluentd/google-fluentd.conf'
133
+ :default => '/etc/google-fluentd/google-fluentd.conf'
130
134
  # Baseline configuration for comparing with local
131
135
  # customizations.
132
136
  config_param :google_fluentd_baseline_config_path,
133
137
  :string,
134
- default: '/etc/google-fluentd/baseline/google-fluentd.conf'
138
+ :default => '/etc/google-fluentd/baseline/google-fluentd.conf'
139
+
140
+ # What system to use when collecting metrics. Possible values are:
141
+ # - 'prometheus', in this case default registry in the Prometheus
142
+ # client library is used, without actually exposing the endpoint
143
+ # to serve metrics in the Prometheus format.
144
+ # - any other value will result in the absence of metrics.
145
+ config_param :monitoring_type, :string,
146
+ :default => Monitoring::PrometheusMonitoringRegistry.name
147
+
148
+ # Override for the Google Cloud Monitoring service hostname, or
149
+ # `nil` to leave as the default.
150
+ config_param :gcm_service_address, :string, :default => nil
151
+
152
+ # rubocop:enable Style/HashSyntax
135
153
 
136
154
  def start
137
155
  super
@@ -196,9 +214,29 @@ module Fluent
196
214
  " #{@google_fluentd_baseline_config_path}. " \
197
215
  'google-fluentd Analyzing configuration.')
198
216
 
199
- # TODO: Add OpenCensus support.
217
+ utils = Common::Utils.new(@log)
218
+ platform = utils.detect_platform(true)
219
+ project_id = utils.get_project_id(platform, nil)
220
+ vm_id = utils.get_vm_id(platform, nil)
221
+ zone = utils.get_location(platform, nil, true)
222
+
223
+ # All metadata parameters must now be set.
224
+ utils.check_required_metadata_variables(
225
+ platform, project_id, zone, vm_id)
226
+
227
+ # Retrieve monitored resource.
228
+ # Fail over to retrieve monitored resource via the legacy path if we
229
+ # fail to get it from Metadata Agent.
230
+ resource = utils.determine_agent_level_monitored_resource_via_legacy(
231
+ platform, nil, false, vm_id, zone)
232
+
233
+ unless Monitoring::MonitoringRegistryFactory.supports_monitoring_type(
234
+ @monitoring_type)
235
+ @log.warn "monitoring_type '#{@monitoring_type}' is unknown; "\
236
+ 'there will be no metrics'
237
+ end
200
238
  registry = Monitoring::MonitoringRegistryFactory.create(
201
- Monitoring::PrometheusMonitoringRegistry.name, nil, nil, nil)
239
+ @monitoring_type, project_id, resource, @gcm_service_address)
202
240
 
203
241
  plugin_usage = registry.counter(
204
242
  :stackdriver_enabled_plugins,
@@ -370,10 +370,20 @@ module Fluent
370
370
  # - 'prometheus', in this case default registry in the Prometheus
371
371
  # client library is used, without actually exposing the endpoint
372
372
  # to serve metrics in the Prometheus format.
373
- # - any other value will result in the absence of metrics.
373
+ # - 'opencensus', in this case the OpenCensus implementation is
374
+ # used to send metrics directly to Google Cloud Monitoring.
375
+ # - any other value will result in the absence of metrics.
374
376
  config_param :monitoring_type, :string,
375
377
  :default => Monitoring::PrometheusMonitoringRegistry.name
376
378
 
379
+ # The monitored resource to use for OpenCensus metrics. Only valid
380
+ # when monitoring_type is set to 'opencensus'. This value is a hash in
381
+ # the form:
382
+ # {"type":"gce_instance","labels":{"instance_id":"aaa","zone":"bbb"} (JSON)
383
+ # or type:gce_instance,labels.instance_id:aaa,labels.zone:bbb (Hash)
384
+ config_param :metrics_resource, :hash,
385
+ :symbolize_keys => true, :default => nil
386
+
377
387
  # Whether to call metadata agent to retrieve monitored resource. This flag
378
388
  # is kept for backwards compatibility, and is no longer used.
379
389
  # TODO: Breaking change. Remove this flag in Logging Agent 2.0.0 release.
@@ -423,6 +433,7 @@ module Fluent
423
433
  attr_reader :vm_id
424
434
  attr_reader :resource
425
435
  attr_reader :common_labels
436
+ attr_reader :monitoring_resource
426
437
 
427
438
  def initialize
428
439
  super
@@ -493,6 +504,43 @@ module Fluent
493
504
  @resource ||= @utils.determine_agent_level_monitored_resource_via_legacy(
494
505
  @platform, @subservice_name, @detect_subservice, @vm_id, @zone)
495
506
 
507
+ if @metrics_resource
508
+ unless @metrics_resource[:type].is_a?(String)
509
+ raise Fluent::ConfigError,
510
+ 'metrics_resource.type must be a string:' \
511
+ " #{@metrics_resource}."
512
+ end
513
+ if @metrics_resource.key?(:labels)
514
+ unless @metrics_resource[:labels].is_a?(Hash)
515
+ raise Fluent::ConfigError,
516
+ 'metrics_resource.labels must be a hash:' \
517
+ " #{@metrics_resource}."
518
+ end
519
+ extra_keys = @metrics_resource.reject do |k, _|
520
+ k == :type || k == :labels
521
+ end
522
+ unless extra_keys.empty?
523
+ raise Fluent::ConfigError,
524
+ "metrics_resource has unrecognized keys: #{extra_keys.keys}."
525
+ end
526
+ else
527
+ extra_keys = @metrics_resource.reject do |k, _|
528
+ k == :type || k.to_s.start_with?('labels.')
529
+ end
530
+ unless extra_keys.empty?
531
+ raise Fluent::ConfigError,
532
+ "metrics_resource has unrecognized keys: #{extra_keys.keys}."
533
+ end
534
+ # Transform the Hash form of the metrics_resource config if necessary.
535
+ resource_type = @metrics_resource[:type]
536
+ resource_labels = @metrics_resource.each_with_object({}) \
537
+ do |(k, v), h|
538
+ h[k.to_s.sub('labels.', '')] = v if k.to_s.start_with? 'labels.'
539
+ end
540
+ @metrics_resource = { type: resource_type, labels: resource_labels }
541
+ end
542
+ end
543
+
496
544
  # If monitoring is enabled, register metrics in the default registry
497
545
  # and store metric objects for future use.
498
546
  if @enable_monitoring
@@ -501,9 +549,15 @@ module Fluent
501
549
  @log.warn "monitoring_type '#{@monitoring_type}' is unknown; "\
502
550
  'there will be no metrics'
503
551
  end
552
+ if @metrics_resource
553
+ @monitoring_resource = @utils.create_monitored_resource(
554
+ @metrics_resource[:type], @metrics_resource[:labels])
555
+ else
556
+ @monitoring_resource = @resource
557
+ end
504
558
  @registry = Monitoring::MonitoringRegistryFactory
505
- .create(@monitoring_type, @project_id, @resource,
506
- @gcm_service_address)
559
+ .create(@monitoring_type, @project_id,
560
+ @monitoring_resource, @gcm_service_address)
507
561
  # Export metrics every 60 seconds.
508
562
  timer_execute(:export_metrics, 60) { @registry.export }
509
563
  # Uptime should be a gauge, but the metric definition is a counter and
@@ -12,6 +12,8 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
+ require 'prometheus/client'
16
+
15
17
  # Additional assert functions.
16
18
  module Asserts
17
19
  # For an optional field with default values, Protobuf omits the field when it
@@ -19,11 +19,12 @@ Coveralls.wear!
19
19
  require 'google/apis'
20
20
  require 'helper'
21
21
  require 'mocha/test_unit'
22
- require 'webmock/test_unit'
23
22
  require 'prometheus/client'
23
+ require 'webmock/test_unit'
24
24
 
25
25
  require_relative 'asserts'
26
26
  require_relative 'constants'
27
+ require_relative 'utils'
27
28
 
28
29
  module Monitoring
29
30
  # Prevent OpenCensus from writing to the network.
@@ -38,21 +39,11 @@ end
38
39
  module BaseTest
39
40
  include Asserts
40
41
  include Constants
42
+ include Utils
41
43
 
42
44
  def setup
43
45
  Fluent::Test.setup
44
- # delete environment variables that googleauth uses to find credentials.
45
- ENV.delete(CREDENTIALS_PATH_ENV_VAR)
46
- # service account env.
47
- ENV.delete(PRIVATE_KEY_VAR)
48
- ENV.delete(CLIENT_EMAIL_VAR)
49
- ENV.delete(PROJECT_ID_VAR)
50
- # authorized_user env.
51
- ENV.delete(CLIENT_ID_VAR)
52
- ENV.delete(CLIENT_SECRET_VAR)
53
- ENV.delete(REFRESH_TOKEN_VAR)
54
- # home var, which is used to find $HOME/.gcloud/...
55
- ENV.delete('HOME')
46
+ delete_env_vars
56
47
 
57
48
  # Unregister Prometheus metrics.
58
49
  registry = Prometheus::Client.registry
@@ -62,7 +53,7 @@ module BaseTest
62
53
  registry.unregister(:stackdriver_dropped_entries_count)
63
54
  registry.unregister(:stackdriver_retried_entries_count)
64
55
 
65
- setup_auth_stubs
56
+ setup_auth_stubs('https://www.googleapis.com/oauth2/v4/token')
66
57
  @logs_sent = []
67
58
  end
68
59
 
@@ -131,8 +122,8 @@ module BaseTest
131
122
 
132
123
  def test_configure_ignores_unknown_monitoring_type
133
124
  # Verify that driver creation succeeds when monitoring type is not
134
- # "prometheus" (in which case, we simply don't record metrics),
135
- # and that the counters are set to nil.
125
+ # "prometheus" or "opencensus" (in which case, we simply don't record
126
+ # metrics), and that the counters are set to nil.
136
127
  setup_gce_metadata_stubs
137
128
  create_driver(CONFIG_UNKNOWN_MONITORING_TYPE)
138
129
  assert_nil(Prometheus::Client.registry.get(
@@ -145,6 +136,67 @@ module BaseTest
145
136
  :stackdriver_dropped_entries_count))
146
137
  assert_nil(Prometheus::Client.registry.get(
147
138
  :stackdriver_retried_entries_count))
139
+ assert_nil(OpenCensus::Stats::MeasureRegistry.get(
140
+ Monitoring::MetricTranslator.new(
141
+ :stackdriver_successful_requests_count, {})))
142
+ assert_nil(OpenCensus::Stats::MeasureRegistry.get(
143
+ Monitoring::MetricTranslator.new(
144
+ :stackdriver_failed_requests_count, {})))
145
+ assert_nil(OpenCensus::Stats::MeasureRegistry.get(
146
+ Monitoring::MetricTranslator.new(
147
+ :stackdriver_ingested_entries_count, {})))
148
+ assert_nil(OpenCensus::Stats::MeasureRegistry.get(
149
+ Monitoring::MetricTranslator.new(
150
+ :stackdriver_dropped_entries_count, {})))
151
+ assert_nil(OpenCensus::Stats::MeasureRegistry.get(
152
+ Monitoring::MetricTranslator.new(
153
+ :stackdriver_retried_entries_count, {})))
154
+ end
155
+
156
+ def test_configure_uses_metrics_resource
157
+ setup_gce_metadata_stubs
158
+ [CONFIG_METRICS_RESOURCE_JSON,
159
+ CONFIG_METRICS_RESOURCE_HASH,
160
+ CONFIG_METRICS_RESOURCE_JSON_HASH
161
+ ].each_with_index do |config, index|
162
+ d = create_driver(config)
163
+ assert_equal 'custom_resource', d.instance.monitoring_resource.type, \
164
+ "Index #{index}"
165
+ assert_equal '123', d.instance.monitoring_resource.labels['label1'], \
166
+ "Index #{index}"
167
+ assert_equal 'abc', d.instance.monitoring_resource.labels['label2'], \
168
+ "Index #{index}"
169
+ assert_true d.instance.instance_variable_get(:@enable_monitoring)
170
+ registry = d.instance.instance_variable_get(:@registry)
171
+ assert_not_nil registry
172
+ exporter = registry.instance_variable_get(:@exporter)
173
+ assert_equal 'custom_resource', exporter.resource_type, "Index #{index}"
174
+ assert_equal({ 'label1' => '123', 'label2' => 'abc' },
175
+ exporter.resource_labels, "Index #{index}")
176
+ end
177
+ end
178
+
179
+ def test_configure_metrics_resource_validation
180
+ setup_gce_metadata_stubs
181
+ {
182
+ CONFIG_METRICS_RESOURCE_JSON_NO_TYPE => /type must be a string/,
183
+ CONFIG_METRICS_RESOURCE_JSON_BAD_LABELS => /labels must be a hash/,
184
+ CONFIG_METRICS_RESOURCE_JSON_BAD_KEYS =>
185
+ /unrecognized keys: \[:random\]/,
186
+ CONFIG_METRICS_RESOURCE_JSON_BAD_KEYS_LABELS =>
187
+ /unrecognized keys: \[:"labels\.random"\]/,
188
+ CONFIG_METRICS_RESOURCE_JSON_BAD_KEYS_NO_LABELS =>
189
+ /unrecognized keys: \[:random\]/
190
+ }.each_with_index do |(config, pattern), index|
191
+ begin
192
+ create_driver(config)
193
+ assert false,
194
+ "Invalid config at index #{index} should have raised an error."
195
+ rescue Fluent::ConfigError => error
196
+ assert error.message.match?(pattern), \
197
+ "Index #{index} failed: got #{error.message}."
198
+ end
199
+ end
148
200
  end
149
201
 
150
202
  def test_metadata_loading
@@ -1925,116 +1977,6 @@ module BaseTest
1925
1977
 
1926
1978
  private
1927
1979
 
1928
- def stub_metadata_request(metadata_path, response_body)
1929
- stub_request(:get, 'http://169.254.169.254/computeMetadata/v1/' +
1930
- metadata_path)
1931
- .to_return(body: response_body, status: 200,
1932
- headers: { 'Content-Length' => response_body.length })
1933
- end
1934
-
1935
- def setup_no_metadata_service_stubs
1936
- # Simulate a machine with no metadata service present
1937
- stub_request(:any, %r{http://169.254.169.254/.*})
1938
- .to_raise(Errno::EHOSTUNREACH)
1939
- end
1940
-
1941
- def setup_gce_metadata_stubs
1942
- # Stub the root, used for platform detection by the plugin and 'googleauth'.
1943
- stub_request(:get, 'http://169.254.169.254')
1944
- .to_return(status: 200, headers: { 'Metadata-Flavor' => 'Google' })
1945
-
1946
- # Create stubs for all the GCE metadata lookups the agent needs to make.
1947
- stub_metadata_request('project/project-id', PROJECT_ID)
1948
- stub_metadata_request('instance/zone', FULLY_QUALIFIED_ZONE)
1949
- stub_metadata_request('instance/id', VM_ID)
1950
- stub_metadata_request('instance/attributes/',
1951
- "attribute1\nattribute2\nattribute3")
1952
-
1953
- # Used by 'googleauth' to fetch the default service account credentials.
1954
- stub_request(:get, 'http://169.254.169.254/computeMetadata/v1/' \
1955
- 'instance/service-accounts/default/token')
1956
- .to_return(body: %({"access_token": "#{FAKE_AUTH_TOKEN}"}),
1957
- status: 200,
1958
- headers: { 'Content-Length' => FAKE_AUTH_TOKEN.length,
1959
- 'Content-Type' => 'application/json' })
1960
- end
1961
-
1962
- def setup_ec2_metadata_stubs
1963
- # Stub the root, used for platform detection.
1964
- stub_request(:get, 'http://169.254.169.254')
1965
- .to_return(status: 200, headers: { 'Server' => 'EC2ws' })
1966
-
1967
- # Stub the identity document lookup made by the agent.
1968
- stub_request(:get, 'http://169.254.169.254/latest/dynamic/' \
1969
- 'instance-identity/document')
1970
- .to_return(body: EC2_IDENTITY_DOCUMENT, status: 200,
1971
- headers: { 'Content-Length' => EC2_IDENTITY_DOCUMENT.length })
1972
- end
1973
-
1974
- def setup_auth_stubs
1975
- # Used when loading credentials from a JSON file.
1976
- stub_request(:post, 'https://www.googleapis.com/oauth2/v4/token')
1977
- .with(body: hash_including(grant_type: AUTH_GRANT_TYPE))
1978
- .to_return(body: %({"access_token": "#{FAKE_AUTH_TOKEN}"}),
1979
- status: 200,
1980
- headers: { 'Content-Length' => FAKE_AUTH_TOKEN.length,
1981
- 'Content-Type' => 'application/json' })
1982
-
1983
- stub_request(:post, 'https://www.googleapis.com/oauth2/v4/token')
1984
- .with(body: hash_including(grant_type: 'refresh_token'))
1985
- .to_return(body: %({"access_token": "#{FAKE_AUTH_TOKEN}"}),
1986
- status: 200,
1987
- headers: { 'Content-Length' => FAKE_AUTH_TOKEN.length,
1988
- 'Content-Type' => 'application/json' })
1989
- end
1990
-
1991
- def setup_managed_vm_metadata_stubs
1992
- stub_metadata_request(
1993
- 'instance/attributes/',
1994
- "attribute1\ngae_backend_name\ngae_backend_version\nlast_attribute")
1995
- stub_metadata_request('instance/attributes/gae_backend_name',
1996
- MANAGED_VM_BACKEND_NAME)
1997
- stub_metadata_request('instance/attributes/gae_backend_version',
1998
- MANAGED_VM_BACKEND_VERSION)
1999
- end
2000
-
2001
- def setup_k8s_metadata_stubs(should_respond = true)
2002
- if should_respond
2003
- stub_metadata_request(
2004
- 'instance/attributes/',
2005
- "attribute1\ncluster-location\ncluster-name\nlast_attribute")
2006
- stub_metadata_request('instance/attributes/cluster-location',
2007
- K8S_LOCATION2)
2008
- stub_metadata_request('instance/attributes/cluster-name',
2009
- K8S_CLUSTER_NAME)
2010
- else
2011
- ['cluster-location', 'cluster-name'].each do |metadata_name|
2012
- stub_request(:get, %r{.*instance/attributes/#{metadata_name}.*})
2013
- .to_return(status: 404,
2014
- body: 'The requested URL /computeMetadata/v1/instance/' \
2015
- "attributes/#{metadata_name} was not found on this" \
2016
- ' server.')
2017
- end
2018
- end
2019
- end
2020
-
2021
- def setup_dataproc_metadata_stubs
2022
- stub_metadata_request(
2023
- 'instance/attributes/',
2024
- "attribute1\ndataproc-cluster-uuid\ndataproc-cluster-name")
2025
- stub_metadata_request('instance/attributes/dataproc-cluster-name',
2026
- DATAPROC_CLUSTER_NAME)
2027
- stub_metadata_request('instance/attributes/dataproc-cluster-uuid',
2028
- DATAPROC_CLUSTER_UUID)
2029
- stub_metadata_request('instance/attributes/dataproc-region',
2030
- DATAPROC_REGION)
2031
- end
2032
-
2033
- def clear_metrics
2034
- Prometheus::Client.registry.instance_variable_set('@metrics', {})
2035
- OpenCensus::Stats.ensure_recorder.clear_stats
2036
- end
2037
-
2038
1980
  # Provide a stub context that initializes @logs_sent, executes the block and
2039
1981
  # resets WebMock at the end.
2040
1982
  def new_stub_context
@@ -433,6 +433,56 @@ module Constants
433
433
  monitoring_type not_prometheus
434
434
  ).freeze
435
435
 
436
+ # rubocop:disable Metrics/LineLength
437
+ CONFIG_METRICS_RESOURCE_JSON = %(
438
+ enable_monitoring true
439
+ monitoring_type opencensus
440
+ metrics_resource {"type":"custom_resource","labels":{"label1":"123","label2":"abc"}}
441
+ ).freeze
442
+
443
+ CONFIG_METRICS_RESOURCE_HASH = %(
444
+ enable_monitoring true
445
+ monitoring_type opencensus
446
+ metrics_resource type:custom_resource, labels.label1:123, labels.label2:abc
447
+ ).freeze
448
+
449
+ CONFIG_METRICS_RESOURCE_JSON_HASH = %(
450
+ enable_monitoring true
451
+ monitoring_type opencensus
452
+ metrics_resource {"type":"custom_resource","labels.label1":"123","labels.label2":"abc"}
453
+ ).freeze
454
+
455
+ CONFIG_METRICS_RESOURCE_JSON_NO_TYPE = %(
456
+ enable_monitoring true
457
+ monitoring_type opencensus
458
+ metrics_resource {"labels":{"label1":"123","label2":"abc"}}
459
+ ).freeze
460
+
461
+ CONFIG_METRICS_RESOURCE_JSON_BAD_LABELS = %(
462
+ enable_monitoring true
463
+ monitoring_type opencensus
464
+ metrics_resource {"type":"custom_resource","labels":"123"}
465
+ ).freeze
466
+
467
+ CONFIG_METRICS_RESOURCE_JSON_BAD_KEYS = %(
468
+ enable_monitoring true
469
+ monitoring_type opencensus
470
+ metrics_resource {"type":"custom_resource","labels":{"label1":"123"},"random":"x"}
471
+ ).freeze
472
+
473
+ CONFIG_METRICS_RESOURCE_JSON_BAD_KEYS_LABELS = %(
474
+ enable_monitoring true
475
+ monitoring_type opencensus
476
+ metrics_resource {"type":"custom_resource","labels":{"label1":"123"},"labels.random":"x"}
477
+ ).freeze
478
+
479
+ CONFIG_METRICS_RESOURCE_JSON_BAD_KEYS_NO_LABELS = %(
480
+ enable_monitoring true
481
+ monitoring_type opencensus
482
+ metrics_resource {"type":"custom_resource","labels.label1":"123","random":"x"}
483
+ ).freeze
484
+ # rubocop:enable Metrics/LineLength
485
+
436
486
  # For statusz.
437
487
  CONFIG_STATUSZ = %(
438
488
  statusz_port 5678
@@ -472,11 +522,19 @@ module Constants
472
522
  ).freeze
473
523
 
474
524
  # For analyze_config.
475
- CONFIG_ANALYZE_CONFIG = %(
525
+ CONFIG_ANALYZE_CONFIG_PROMETHEUS = %(
526
+ google_fluentd_config_path \
527
+ test/plugin/data/google-fluentd-custom.conf
528
+ google_fluentd_baseline_config_path \
529
+ test/plugin/data/google-fluentd-baseline.conf
530
+ monitoring_type prometheus
531
+ ).freeze
532
+ CONFIG_ANALYZE_CONFIG_OPENCENSUS = %(
476
533
  google_fluentd_config_path \
477
534
  test/plugin/data/google-fluentd-custom.conf
478
535
  google_fluentd_baseline_config_path \
479
536
  test/plugin/data/google-fluentd-baseline.conf
537
+ monitoring_type opencensus
480
538
  ).freeze
481
539
 
482
540
  # Service configurations for various services.
@@ -16,19 +16,6 @@ require 'fluent/engine'
16
16
  require 'fluent/event'
17
17
  require 'fluent/test/input_test'
18
18
 
19
- module Fluent
20
- module Test
21
- # rubocop:disable Style/ClassVars
22
- class BufferedOutputTestDriver < InputTestDriver
23
- @@run_method = BufferedOutputTestDriver.instance_method(:run)
24
- def run(num_waits = 0)
25
- @@run_method.bind(self).call(num_waits)
26
- end
27
- end
28
- # rubocop:enable Style/ClassVars
29
- end
30
- end
31
-
32
19
  module Fluent
33
20
  module Test
34
21
  # Similar to the standard BufferedOutputTestDriver, but allows multiple tags
@@ -46,7 +33,7 @@ module Fluent
46
33
  self
47
34
  end
48
35
 
49
- def run(num_waits = 0)
36
+ def run(num_waits = 10)
50
37
  result = nil
51
38
  super(num_waits) do
52
39
  chunk = @instance.buffer.generate_chunk(
@@ -15,6 +15,7 @@
15
15
  require_relative '../helper'
16
16
  require_relative 'asserts'
17
17
  require_relative 'constants'
18
+ require_relative 'utils'
18
19
 
19
20
  require 'fluent/test/driver/filter'
20
21
  require 'fluent/plugin/filter_analyze_config'
@@ -24,11 +25,13 @@ class FilterAnalyzeConfigTest < Test::Unit::TestCase
24
25
  include Asserts
25
26
  include Constants
26
27
  include Fluent::AnalyzeConfigFilter::Constants
28
+ include Utils
27
29
 
28
30
  APPLICATION_DEFAULT_CONFIG = ''.freeze
29
31
 
30
32
  def setup
31
33
  Fluent::Test.setup
34
+ delete_env_vars
32
35
  end
33
36
 
34
37
  def test_config_file_does_not_exist
@@ -39,145 +42,155 @@ class FilterAnalyzeConfigTest < Test::Unit::TestCase
39
42
  end
40
43
 
41
44
  def test_analyze_config
42
- create_driver(CONFIG_ANALYZE_CONFIG)
45
+ setup_auth_stubs('https://oauth2.googleapis.com/token')
46
+ setup_gce_metadata_stubs
47
+ [
48
+ [CONFIG_ANALYZE_CONFIG_PROMETHEUS,
49
+ method(:assert_prometheus_metric_value)],
50
+ [CONFIG_ANALYZE_CONFIG_OPENCENSUS,
51
+ method(:assert_opencensus_metric_value)]
52
+ ].each do |config, assert_metric_value|
53
+ clear_metrics
54
+ create_driver(config)
43
55
 
44
- # Default plugins, with default config.
45
- assert_prometheus_metric_value(
46
- :stackdriver_enabled_plugins,
47
- 1,
48
- plugin_name: 'source/syslog/tcp',
49
- is_default_plugin: true,
50
- has_default_value: true,
51
- has_ruby_snippet: false)
52
- assert_prometheus_metric_value(
53
- :stackdriver_enabled_plugins,
54
- 1,
55
- plugin_name: 'source/tail/apache-access',
56
- is_default_plugin: true,
57
- has_default_value: true,
58
- has_ruby_snippet: false)
59
- assert_prometheus_metric_value(
60
- :stackdriver_enabled_plugins,
61
- 1,
62
- plugin_name: 'filter/add_insert_ids',
63
- is_default_plugin: true,
64
- has_default_value: true,
65
- has_ruby_snippet: false)
56
+ # Default plugins, with default config.
57
+ assert_metric_value.call(
58
+ :stackdriver_enabled_plugins,
59
+ 1,
60
+ plugin_name: 'source/syslog/tcp',
61
+ is_default_plugin: true,
62
+ has_default_value: true,
63
+ has_ruby_snippet: false)
64
+ assert_metric_value.call(
65
+ :stackdriver_enabled_plugins,
66
+ 1,
67
+ plugin_name: 'source/tail/apache-access',
68
+ is_default_plugin: true,
69
+ has_default_value: true,
70
+ has_ruby_snippet: false)
71
+ assert_metric_value.call(
72
+ :stackdriver_enabled_plugins,
73
+ 1,
74
+ plugin_name: 'filter/add_insert_ids',
75
+ is_default_plugin: true,
76
+ has_default_value: true,
77
+ has_ruby_snippet: false)
66
78
 
67
- # Default plugins, with custom config.
68
- assert_prometheus_metric_value(
69
- :stackdriver_enabled_plugins,
70
- 1,
71
- plugin_name: 'match/google_cloud',
72
- is_default_plugin: true,
73
- has_default_value: false,
74
- has_ruby_snippet: false)
79
+ # Default plugins, with custom config.
80
+ assert_metric_value.call(
81
+ :stackdriver_enabled_plugins,
82
+ 1,
83
+ plugin_name: 'match/google_cloud',
84
+ is_default_plugin: true,
85
+ has_default_value: false,
86
+ has_ruby_snippet: false)
75
87
 
76
- # Custom plugins, some with embedded Ruby.
77
- assert_prometheus_metric_value(
78
- :stackdriver_enabled_plugins,
79
- 1,
80
- plugin_name: 'filter',
81
- is_default_plugin: false,
82
- has_default_value: false,
83
- has_ruby_snippet: false)
84
- assert_prometheus_metric_value(
85
- :stackdriver_enabled_plugins,
86
- 1,
87
- plugin_name: 'filter/record_transformer',
88
- is_default_plugin: false,
89
- has_default_value: false,
90
- has_ruby_snippet: true)
91
- assert_prometheus_metric_value(
92
- :stackdriver_enabled_plugins,
93
- 1,
94
- plugin_name: 'match/stdout',
95
- is_default_plugin: false,
96
- has_default_value: false,
97
- has_ruby_snippet: true)
88
+ # Custom plugins, some with embedded Ruby.
89
+ assert_metric_value.call(
90
+ :stackdriver_enabled_plugins,
91
+ 1,
92
+ plugin_name: 'filter',
93
+ is_default_plugin: false,
94
+ has_default_value: false,
95
+ has_ruby_snippet: false)
96
+ assert_metric_value.call(
97
+ :stackdriver_enabled_plugins,
98
+ 1,
99
+ plugin_name: 'filter/record_transformer',
100
+ is_default_plugin: false,
101
+ has_default_value: false,
102
+ has_ruby_snippet: true)
103
+ assert_metric_value.call(
104
+ :stackdriver_enabled_plugins,
105
+ 1,
106
+ plugin_name: 'match/stdout',
107
+ is_default_plugin: false,
108
+ has_default_value: false,
109
+ has_ruby_snippet: true)
98
110
 
99
- # For out_google_cloud, 3 params are present.
100
- assert_prometheus_metric_value(
101
- :stackdriver_config_usage,
102
- 1,
103
- plugin_name: 'google_cloud',
104
- param: 'adjust_invalid_timestamps',
105
- is_present: true,
106
- has_default_value: true)
107
- assert_prometheus_metric_value(
108
- :stackdriver_config_usage,
109
- 1,
110
- plugin_name: 'google_cloud',
111
- param: 'autoformat_stackdriver_trace',
112
- is_present: true,
113
- has_default_value: false)
114
- assert_prometheus_metric_value(
115
- :stackdriver_config_usage,
116
- 1,
117
- plugin_name: 'google_cloud',
118
- param: 'coerce_to_utf8',
119
- is_present: true,
120
- has_default_value: false)
121
- # The remaining "google_cloud" params are not present.
122
- # The are no params for "detect_exceptions".
123
- %w(
124
- auth_method
125
- detect_json
126
- enable_monitoring
127
- gcm_service_address
128
- grpc_compression_algorithm
129
- http_request_key
130
- insert_id_key
131
- label_map
132
- labels
133
- labels_key
134
- logging_api_url
135
- monitoring_type
136
- non_utf8_replacement_string
137
- operation_key
138
- private_key_email
139
- private_key_passphrase
140
- private_key_path
141
- project_id
142
- source_location_key
143
- span_id_key
144
- statusz_port
145
- trace_key
146
- trace_sampled_key
147
- use_grpc
148
- use_metadata_service
149
- vm_id
150
- vm_name
151
- zone
152
- ).each do |p|
153
- assert_prometheus_metric_value(
111
+ # For out_google_cloud, 3 params are present.
112
+ assert_metric_value.call(
154
113
  :stackdriver_config_usage,
155
114
  1,
156
115
  plugin_name: 'google_cloud',
157
- param: p,
158
- is_present: false,
116
+ param: 'adjust_invalid_timestamps',
117
+ is_present: true,
118
+ has_default_value: true)
119
+ assert_metric_value.call(
120
+ :stackdriver_config_usage,
121
+ 1,
122
+ plugin_name: 'google_cloud',
123
+ param: 'autoformat_stackdriver_trace',
124
+ is_present: true,
159
125
  has_default_value: false)
160
- end
126
+ assert_metric_value.call(
127
+ :stackdriver_config_usage,
128
+ 1,
129
+ plugin_name: 'google_cloud',
130
+ param: 'coerce_to_utf8',
131
+ is_present: true,
132
+ has_default_value: false)
133
+ # The remaining "google_cloud" params are not present.
134
+ # The are no params for "detect_exceptions".
135
+ %w(
136
+ auth_method
137
+ detect_json
138
+ enable_monitoring
139
+ gcm_service_address
140
+ grpc_compression_algorithm
141
+ http_request_key
142
+ insert_id_key
143
+ label_map
144
+ labels
145
+ labels_key
146
+ logging_api_url
147
+ monitoring_type
148
+ non_utf8_replacement_string
149
+ operation_key
150
+ private_key_email
151
+ private_key_passphrase
152
+ private_key_path
153
+ project_id
154
+ source_location_key
155
+ span_id_key
156
+ statusz_port
157
+ trace_key
158
+ trace_sampled_key
159
+ use_grpc
160
+ use_metadata_service
161
+ vm_id
162
+ vm_name
163
+ zone
164
+ ).each do |p|
165
+ assert_metric_value.call(
166
+ :stackdriver_config_usage,
167
+ 1,
168
+ plugin_name: 'google_cloud',
169
+ param: p,
170
+ is_present: false,
171
+ has_default_value: false)
172
+ end
161
173
 
162
- # We also export values for the bools.
163
- assert_prometheus_metric_value(
164
- :stackdriver_config_bool_values,
165
- 1,
166
- plugin_name: 'google_cloud',
167
- param: 'adjust_invalid_timestamps',
168
- value: true)
169
- assert_prometheus_metric_value(
170
- :stackdriver_config_bool_values,
171
- 1,
172
- plugin_name: 'google_cloud',
173
- param: 'autoformat_stackdriver_trace',
174
- value: false)
175
- assert_prometheus_metric_value(
176
- :stackdriver_config_bool_values,
177
- 1,
178
- plugin_name: 'google_cloud',
179
- param: 'coerce_to_utf8',
180
- value: true)
174
+ # We also export values for the bools.
175
+ assert_metric_value.call(
176
+ :stackdriver_config_bool_values,
177
+ 1,
178
+ plugin_name: 'google_cloud',
179
+ param: 'adjust_invalid_timestamps',
180
+ value: true)
181
+ assert_metric_value.call(
182
+ :stackdriver_config_bool_values,
183
+ 1,
184
+ plugin_name: 'google_cloud',
185
+ param: 'autoformat_stackdriver_trace',
186
+ value: false)
187
+ assert_metric_value.call(
188
+ :stackdriver_config_bool_values,
189
+ 1,
190
+ plugin_name: 'google_cloud',
191
+ param: 'coerce_to_utf8',
192
+ value: true)
193
+ end
181
194
  end
182
195
 
183
196
  def create_driver(conf = APPLICATION_DEFAULT_CONFIG)
@@ -0,0 +1,147 @@
1
+ # Copyright 2020 Google Inc. All rights reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require_relative 'constants'
16
+
17
+ require 'prometheus/client'
18
+ require 'webmock/test_unit'
19
+
20
+ module Utils
21
+ include Constants
22
+
23
+ def delete_env_vars
24
+ # delete environment variables that googleauth uses to find credentials.
25
+ ENV.delete(CREDENTIALS_PATH_ENV_VAR)
26
+ # service account env.
27
+ ENV.delete(PRIVATE_KEY_VAR)
28
+ ENV.delete(CLIENT_EMAIL_VAR)
29
+ ENV.delete(PROJECT_ID_VAR)
30
+ # authorized_user env.
31
+ ENV.delete(CLIENT_ID_VAR)
32
+ ENV.delete(CLIENT_SECRET_VAR)
33
+ ENV.delete(REFRESH_TOKEN_VAR)
34
+ # home var, which is used to find $HOME/.gcloud/...
35
+ ENV.delete('HOME')
36
+ end
37
+
38
+ def stub_metadata_request(metadata_path, response_body)
39
+ stub_request(:get, 'http://169.254.169.254/computeMetadata/v1/' +
40
+ metadata_path)
41
+ .to_return(body: response_body, status: 200,
42
+ headers: { 'Content-Length' => response_body.length })
43
+ end
44
+
45
+ def setup_no_metadata_service_stubs
46
+ # Simulate a machine with no metadata service present
47
+ stub_request(:any, %r{http://169.254.169.254/.*})
48
+ .to_raise(Errno::EHOSTUNREACH)
49
+ end
50
+
51
+ def setup_gce_metadata_stubs
52
+ # Stub the root, used for platform detection by the plugin and 'googleauth'.
53
+ stub_request(:get, 'http://169.254.169.254')
54
+ .to_return(status: 200, headers: { 'Metadata-Flavor' => 'Google' })
55
+
56
+ # Create stubs for all the GCE metadata lookups the agent needs to make.
57
+ stub_metadata_request('project/project-id', PROJECT_ID)
58
+ stub_metadata_request('instance/zone', FULLY_QUALIFIED_ZONE)
59
+ stub_metadata_request('instance/id', VM_ID)
60
+ stub_metadata_request('instance/attributes/',
61
+ "attribute1\nattribute2\nattribute3")
62
+
63
+ # Used by 'googleauth' to fetch the default service account credentials.
64
+ stub_request(:get, 'http://169.254.169.254/computeMetadata/v1/' \
65
+ 'instance/service-accounts/default/token')
66
+ .to_return(body: %({"access_token": "#{FAKE_AUTH_TOKEN}"}),
67
+ status: 200,
68
+ headers: { 'Content-Length' => FAKE_AUTH_TOKEN.length,
69
+ 'Content-Type' => 'application/json' })
70
+ end
71
+
72
+ def setup_ec2_metadata_stubs
73
+ # Stub the root, used for platform detection.
74
+ stub_request(:get, 'http://169.254.169.254')
75
+ .to_return(status: 200, headers: { 'Server' => 'EC2ws' })
76
+
77
+ # Stub the identity document lookup made by the agent.
78
+ stub_request(:get, 'http://169.254.169.254/latest/dynamic/' \
79
+ 'instance-identity/document')
80
+ .to_return(body: EC2_IDENTITY_DOCUMENT, status: 200,
81
+ headers: { 'Content-Length' => EC2_IDENTITY_DOCUMENT.length })
82
+ end
83
+
84
+ def setup_auth_stubs(base_url)
85
+ # Used when loading credentials from a JSON file.
86
+ stub_request(:post, base_url)
87
+ .with(body: hash_including(grant_type: AUTH_GRANT_TYPE))
88
+ .to_return(body: %({"access_token": "#{FAKE_AUTH_TOKEN}"}),
89
+ status: 200,
90
+ headers: { 'Content-Length' => FAKE_AUTH_TOKEN.length,
91
+ 'Content-Type' => 'application/json' })
92
+
93
+ stub_request(:post, base_url)
94
+ .with(body: hash_including(grant_type: 'refresh_token'))
95
+ .to_return(body: %({"access_token": "#{FAKE_AUTH_TOKEN}"}),
96
+ status: 200,
97
+ headers: { 'Content-Length' => FAKE_AUTH_TOKEN.length,
98
+ 'Content-Type' => 'application/json' })
99
+ end
100
+
101
+ def setup_managed_vm_metadata_stubs
102
+ stub_metadata_request(
103
+ 'instance/attributes/',
104
+ "attribute1\ngae_backend_name\ngae_backend_version\nlast_attribute")
105
+ stub_metadata_request('instance/attributes/gae_backend_name',
106
+ MANAGED_VM_BACKEND_NAME)
107
+ stub_metadata_request('instance/attributes/gae_backend_version',
108
+ MANAGED_VM_BACKEND_VERSION)
109
+ end
110
+
111
+ def setup_k8s_metadata_stubs(should_respond = true)
112
+ if should_respond
113
+ stub_metadata_request(
114
+ 'instance/attributes/',
115
+ "attribute1\ncluster-location\ncluster-name\nlast_attribute")
116
+ stub_metadata_request('instance/attributes/cluster-location',
117
+ K8S_LOCATION2)
118
+ stub_metadata_request('instance/attributes/cluster-name',
119
+ K8S_CLUSTER_NAME)
120
+ else
121
+ ['cluster-location', 'cluster-name'].each do |metadata_name|
122
+ stub_request(:get, %r{.*instance/attributes/#{metadata_name}.*})
123
+ .to_return(status: 404,
124
+ body: 'The requested URL /computeMetadata/v1/instance/' \
125
+ "attributes/#{metadata_name} was not found on this" \
126
+ ' server.')
127
+ end
128
+ end
129
+ end
130
+
131
+ def setup_dataproc_metadata_stubs
132
+ stub_metadata_request(
133
+ 'instance/attributes/',
134
+ "attribute1\ndataproc-cluster-uuid\ndataproc-cluster-name")
135
+ stub_metadata_request('instance/attributes/dataproc-cluster-name',
136
+ DATAPROC_CLUSTER_NAME)
137
+ stub_metadata_request('instance/attributes/dataproc-cluster-uuid',
138
+ DATAPROC_CLUSTER_UUID)
139
+ stub_metadata_request('instance/attributes/dataproc-region',
140
+ DATAPROC_REGION)
141
+ end
142
+
143
+ def clear_metrics
144
+ Prometheus::Client.registry.instance_variable_set('@metrics', {})
145
+ OpenCensus::Stats.ensure_recorder.clear_stats
146
+ end
147
+ end
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.8.7
4
+ version: 0.9.0
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-06-11 00:00:00.000000000 Z
11
+ date: 2020-07-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd
@@ -86,28 +86,28 @@ dependencies:
86
86
  requirements:
87
87
  - - '='
88
88
  - !ruby/object:Gem::Version
89
- version: 3.9.0
89
+ version: 3.12.2
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - '='
95
95
  - !ruby/object:Gem::Version
96
- version: 3.9.0
96
+ version: 3.12.2
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: grpc
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - '='
102
102
  - !ruby/object:Gem::Version
103
- version: 1.22.0
103
+ version: 1.30.1
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - '='
109
109
  - !ruby/object:Gem::Version
110
- version: 1.22.0
110
+ version: 1.30.1
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: json
113
113
  requirement: !ruby/object:Gem::Requirement
@@ -289,6 +289,7 @@ files:
289
289
  - test/plugin/test_filter_analyze_config.rb
290
290
  - test/plugin/test_out_google_cloud.rb
291
291
  - test/plugin/test_out_google_cloud_grpc.rb
292
+ - test/plugin/utils.rb
292
293
  homepage: https://github.com/GoogleCloudPlatform/fluent-plugin-google-cloud
293
294
  licenses:
294
295
  - Apache-2.0
@@ -329,3 +330,4 @@ test_files:
329
330
  - test/plugin/test_filter_analyze_config.rb
330
331
  - test/plugin/test_out_google_cloud.rb
331
332
  - test/plugin/test_out_google_cloud_grpc.rb
333
+ - test/plugin/utils.rb