fluent-plugin-google-cloud 0.6.25.1 → 0.7.0.pre.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bb53a82f49086e32adb57a617f0ad53812493815
4
- data.tar.gz: 6964a23f146726e01f71a74378c0fa4327c5b582
3
+ metadata.gz: 20379f9f088d04bfb6b446d03347d5574ed78e03
4
+ data.tar.gz: c873feb14beedffe40b75714de0de47e0e117ec7
5
5
  SHA512:
6
- metadata.gz: a9074434a1978f326a44fc4651d692a1e0f524c6c8ddeebda4efe89968059df9289749f21d85983a5308ee8629a208fb3963974ac234e8462a85a5c48aab94cb
7
- data.tar.gz: 57e333f19ca5a7e5a9dbd2bd4b4bb65e461222bde2036b9a98a0e99ed2d95159d690c718b2b6bf95fe208dbbea2c7d5c1147a68b7d2dc39ff7f7dbfed1909664
6
+ metadata.gz: 07bba814b28cd239cd8150fbf5d8bb0a5d26a8d8acc42ed1f2905232e7e387d394ef74cb5a18125b585e02b79de3c0c0443e1b91ff0face222f07541769cb6f0
7
+ data.tar.gz: 286f822a8d7d4ea719326c7a8181ad6c666860bb351b8d724ee65ea1d508c9b3f1e0bfa2d5020b05218b1a2719f3bb77b1027cd084a04dbba65dc00312b2f7e0
@@ -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.6.25.1'
13
+ gem.version = '0.7.0.pre.4'
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')
@@ -19,13 +19,13 @@ eos
19
19
  gem.test_files = gem.files.grep(/^(test)/)
20
20
  gem.require_paths = ['lib']
21
21
 
22
- gem.add_runtime_dependency 'fluentd', '~> 0.10'
22
+ gem.add_runtime_dependency 'fluentd', '~> 1.2', '>= 1.2.5'
23
23
  gem.add_runtime_dependency 'googleapis-common-protos', '~> 1.3'
24
24
  gem.add_runtime_dependency 'google-api-client', '~> 0.17'
25
25
  gem.add_runtime_dependency 'google-cloud-logging', '~> 1.3', '>= 1.3.2'
26
26
  gem.add_runtime_dependency 'googleauth', '~> 0.6'
27
27
  gem.add_runtime_dependency 'grpc', '~> 1.0'
28
- gem.add_runtime_dependency 'json', '~> 2.1'
28
+ gem.add_runtime_dependency 'json', '~> 1.8'
29
29
  gem.add_runtime_dependency 'google-protobuf', '~> 3.6', '>= 3.6.1'
30
30
 
31
31
  gem.add_development_dependency 'mocha', '~> 1.1'
@@ -165,6 +165,11 @@ module Fluent
165
165
  # monitored resource from Stackdriver Metadata agent.
166
166
  LOCAL_RESOURCE_ID_KEY = 'logging.googleapis.com/local_resource_id'.freeze
167
167
 
168
+ # The regexp matches stackdriver trace id format: 32-byte hex string.
169
+ # The format is documented in
170
+ # https://cloud.google.com/trace/docs/reference/v2/rpc/google.devtools.cloudtrace.v1#trace
171
+ STACKDRIVER_TRACE_ID_REGEXP = Regexp.new('^\h{32}$').freeze
172
+
168
173
  # Map from each field name under LogEntry to corresponding variables
169
174
  # required to perform field value extraction from the log record.
170
175
  LOG_ENTRY_FIELDS_MAP = {
@@ -410,6 +415,12 @@ module Fluent
410
415
  # Whether to attempt adjusting invalid log entry timestamps.
411
416
  config_param :adjust_invalid_timestamps, :bool, :default => true
412
417
 
418
+ # Whether to autoformat value of "logging.googleapis.com/trace" to
419
+ # comply with Stackdriver Trace format
420
+ # "projects/[PROJECT-ID]/traces/[TRACE-ID]" when setting
421
+ # LogEntry.trace.
422
+ config_param :autoformat_stackdriver_trace, :bool, :default => true
423
+
413
424
  # rubocop:enable Style/HashSyntax
414
425
 
415
426
  # TODO: Add a log_name config option rather than just using the tag?
@@ -627,7 +638,8 @@ module Fluent
627
638
  ts_nanos)
628
639
 
629
640
  trace = record.delete(@trace_key)
630
- entry.trace = trace if trace
641
+ entry.trace = compute_trace(trace) if trace
642
+
631
643
  span_id = record.delete(@span_id_key)
632
644
  entry.span_id = span_id if span_id
633
645
  insert_id = record.delete(@insert_id_key)
@@ -676,6 +688,12 @@ module Fluent
676
688
 
677
689
  private
678
690
 
691
+ def compute_trace(trace)
692
+ return trace unless @autoformat_stackdriver_trace &&
693
+ STACKDRIVER_TRACE_ID_REGEXP.match(trace)
694
+ "projects/#{@project_id}/traces/#{trace}"
695
+ end
696
+
679
697
  def construct_log_entry_in_grpc_format(labels,
680
698
  resource,
681
699
  severity,
@@ -338,6 +338,98 @@ module BaseTest
338
338
  end
339
339
  end
340
340
 
341
+ def test_autoformat_enabled_with_stackdriver_trace_id_as_trace
342
+ [
343
+ APPLICATION_DEFAULT_CONFIG,
344
+ ENABLE_AUTOFORMAT_STACKDRIVER_TRACE_CONFIG
345
+ ].each do |config|
346
+ new_stub_context do
347
+ setup_gce_metadata_stubs
348
+ setup_logging_stubs do
349
+ d = create_driver(config)
350
+ d.emit(DEFAULT_TRACE_KEY => STACKDRIVER_TRACE_ID)
351
+ d.run
352
+ verify_log_entries(1, COMPUTE_PARAMS, 'jsonPayload') do |entry|
353
+ assert_equal FULL_STACKDRIVER_TRACE, entry['trace'],
354
+ 'stackdriver trace id should be autoformatted ' \
355
+ 'when autoformat_stackdriver_trace is enabled.'
356
+ end
357
+ end
358
+ end
359
+ end
360
+ end
361
+
362
+ def test_autoformat_disabled_with_stackdriver_trace_id_as_trace
363
+ setup_gce_metadata_stubs
364
+ setup_logging_stubs do
365
+ d = create_driver(DISABLE_AUTOFORMAT_STACKDRIVER_TRACE_CONFIG)
366
+ d.emit(DEFAULT_TRACE_KEY => STACKDRIVER_TRACE_ID)
367
+ d.run
368
+ verify_log_entries(1, COMPUTE_PARAMS, 'jsonPayload') do |entry|
369
+ assert_equal STACKDRIVER_TRACE_ID, entry['trace'],
370
+ 'trace as stackdriver trace id should not be ' \
371
+ 'autoformatted with config ' \
372
+ "#{DISABLE_AUTOFORMAT_STACKDRIVER_TRACE_CONFIG}."
373
+ end
374
+ end
375
+ end
376
+
377
+ def test_no_trace_when_trace_key_not_exists_with_any_autoformat_config
378
+ [
379
+ APPLICATION_DEFAULT_CONFIG,
380
+ ENABLE_AUTOFORMAT_STACKDRIVER_TRACE_CONFIG,
381
+ DISABLE_AUTOFORMAT_STACKDRIVER_TRACE_CONFIG
382
+ ].each do |config|
383
+ new_stub_context do
384
+ setup_gce_metadata_stubs
385
+ setup_logging_stubs do
386
+ d = create_driver(config)
387
+ d.emit('msg' => log_entry(0))
388
+ d.run
389
+ verify_log_entries(1, COMPUTE_PARAMS, 'jsonPayload') do |entry|
390
+ assert_nil entry['trace']
391
+ end
392
+ end
393
+ end
394
+ end
395
+ end
396
+
397
+ def test_non_stackdriver_trace_id_compliant_trace_with_any_autoformat_config
398
+ configs = [
399
+ APPLICATION_DEFAULT_CONFIG,
400
+ ENABLE_AUTOFORMAT_STACKDRIVER_TRACE_CONFIG,
401
+ DISABLE_AUTOFORMAT_STACKDRIVER_TRACE_CONFIG
402
+ ]
403
+ traces = [
404
+ TRACE, # Full trace won't be modified.
405
+ EMPTY_STRING,
406
+ INVALID_SHORT_STACKDRIVER_TRACE_ID,
407
+ INVALID_LONG_STACKDRIVER_TRACE_ID,
408
+ INVALID_NON_HEX_STACKDRIVER_TRACE_ID,
409
+ INVALID_TRACE_NO_TRACE_ID,
410
+ INVALID_TRACE_NO_PROJECT_ID,
411
+ INVALID_TRACE_WITH_SHORT_TRACE_ID,
412
+ INVALID_TRACE_WITH_LONG_TRACE_ID,
413
+ INVALID_TRACE_WITH_NON_HEX_TRACE_ID
414
+ ]
415
+ configs.product(traces).each do |config, trace|
416
+ new_stub_context do
417
+ setup_gce_metadata_stubs
418
+ setup_logging_stubs do
419
+ d = create_driver(config)
420
+ d.emit(DEFAULT_TRACE_KEY => trace)
421
+ d.run
422
+ verify_log_entries(1, COMPUTE_PARAMS, 'jsonPayload') do |entry|
423
+ assert_equal_with_default \
424
+ entry['trace'], trace, '',
425
+ 'trace as non stackdriver trace id should not be ' \
426
+ "autoformatted with config #{config}."
427
+ end
428
+ end
429
+ end
430
+ end
431
+ end
432
+
341
433
  def test_structured_payload_malformatted_log
342
434
  setup_gce_metadata_stubs
343
435
  message = 'test message'
@@ -106,6 +106,30 @@ module Constants
106
106
  INSERT_ID = 'fah7yr7iw64tg857y'.freeze
107
107
  INSERT_ID2 = 'fah7yr7iw64tgaeuf'.freeze
108
108
 
109
+ STACKDRIVER_TRACE_ID = '1234567890abcdef1234567890abcdef'.freeze
110
+ FULL_STACKDRIVER_TRACE = \
111
+ "projects/#{PROJECT_ID}/traces/#{STACKDRIVER_TRACE_ID}".freeze
112
+
113
+ # Invalid trace id for stackdriver.
114
+ EMPTY_STRING = ''.freeze
115
+ INVALID_SHORT_STACKDRIVER_TRACE_ID = '1234567890abcdef'.freeze
116
+ INVALID_LONG_STACKDRIVER_TRACE_ID = \
117
+ '1234567890abcdef1234567890abcdef123'.freeze
118
+ INVALID_NON_HEX_STACKDRIVER_TRACE_ID = \
119
+ '1234567890abcdef1234567890abcdeZ'.freeze
120
+
121
+ # Invalid full format of stackdriver trace.
122
+ INVALID_TRACE_NO_TRACE_ID = "projects/#{PROJECT_ID}/traces/".freeze
123
+ INVALID_TRACE_NO_PROJECT_ID = \
124
+ "projects//traces/#{STACKDRIVER_TRACE_ID}".freeze
125
+ INVALID_TRACE_WITH_SHORT_TRACE_ID = \
126
+ "projects/#{PROJECT_ID}/traces/#{INVALID_SHORT_STACKDRIVER_TRACE_ID}".freeze
127
+ INVALID_TRACE_WITH_LONG_TRACE_ID = \
128
+ "projects/#{PROJECT_ID}/traces/#{INVALID_LONG_STACKDRIVER_TRACE_ID}".freeze
129
+ INVALID_TRACE_WITH_NON_HEX_TRACE_ID = \
130
+ "projects/#{PROJECT_ID}/" \
131
+ "traces/#{INVALID_NON_HEX_STACKDRIVER_TRACE_ID}".freeze
132
+
109
133
  # Docker Container labels.
110
134
  DOCKER_CONTAINER_ID =
111
135
  '0d0f03ff8d3c42688692536d1af77a28cd135c0a5c531f25a31'.freeze
@@ -265,6 +289,14 @@ module Constants
265
289
  enable_metadata_agent false
266
290
  ).freeze
267
291
 
292
+ ENABLE_AUTOFORMAT_STACKDRIVER_TRACE_CONFIG = %(
293
+ autoformat_stackdriver_trace true
294
+ ).freeze
295
+
296
+ DISABLE_AUTOFORMAT_STACKDRIVER_TRACE_CONFIG = %(
297
+ autoformat_stackdriver_trace false
298
+ ).freeze
299
+
268
300
  DOCKER_CONTAINER_CONFIG = %(
269
301
  enable_metadata_agent true
270
302
  label_map { "source": "#{DOCKER_CONSTANTS[:service]}/stream" }
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.6.25.1
4
+ version: 0.7.0.pre.4
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: 2018-09-13 00:00:00.000000000 Z
11
+ date: 2018-10-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd
@@ -16,14 +16,20 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.10'
19
+ version: '1.2'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.2.5
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
27
  - - "~>"
25
28
  - !ruby/object:Gem::Version
26
- version: '0.10'
29
+ version: '1.2'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 1.2.5
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: googleapis-common-protos
29
35
  requirement: !ruby/object:Gem::Requirement
@@ -106,14 +112,14 @@ dependencies:
106
112
  requirements:
107
113
  - - "~>"
108
114
  - !ruby/object:Gem::Version
109
- version: '2.1'
115
+ version: '1.8'
110
116
  type: :runtime
111
117
  prerelease: false
112
118
  version_requirements: !ruby/object:Gem::Requirement
113
119
  requirements:
114
120
  - - "~>"
115
121
  - !ruby/object:Gem::Version
116
- version: '2.1'
122
+ version: '1.8'
117
123
  - !ruby/object:Gem::Dependency
118
124
  name: google-protobuf
119
125
  requirement: !ruby/object:Gem::Requirement
@@ -234,6 +240,7 @@ files:
234
240
  - LICENSE
235
241
  - README.rdoc
236
242
  - Rakefile
243
+ - fluent-plugin-google-cloud-0.7.0.gem
237
244
  - fluent-plugin-google-cloud.gemspec
238
245
  - lib/fluent/plugin/filter_add_insert_ids.rb
239
246
  - lib/fluent/plugin/monitoring.rb
@@ -265,9 +272,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
265
272
  version: '2.2'
266
273
  required_rubygems_version: !ruby/object:Gem::Requirement
267
274
  requirements:
268
- - - ">="
275
+ - - ">"
269
276
  - !ruby/object:Gem::Version
270
- version: '0'
277
+ version: 1.3.1
271
278
  requirements: []
272
279
  rubyforge_project:
273
280
  rubygems_version: 2.6.14