fluent-plugin-google-cloud 0.5.6 → 0.6.0.v2.alpha.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -28,18 +28,18 @@ class GoogleCloudOutputTest < Test::Unit::TestCase
28
28
  setup_gce_metadata_stubs
29
29
  # The API Client should not retry this and the plugin should consume
30
30
  # the exception.
31
- stub_request(:post, uri_for_log(COMPUTE_PARAMS))
31
+ stub_request(:post, WRITE_LOG_ENTRIES_URI)
32
32
  .to_return(status: 400, body: 'Bad Request')
33
33
  d = create_driver
34
34
  d.emit('message' => log_entry(0))
35
35
  d.run
36
- assert_requested(:post, uri_for_log(COMPUTE_PARAMS), times: 1)
36
+ assert_requested(:post, WRITE_LOG_ENTRIES_URI, times: 1)
37
37
  end
38
38
 
39
39
  # All credentials errors resolve to a 401.
40
40
  def test_client_401
41
41
  setup_gce_metadata_stubs
42
- stub_request(:post, uri_for_log(COMPUTE_PARAMS))
42
+ stub_request(:post, WRITE_LOG_ENTRIES_URI)
43
43
  .to_return(status: 401, body: 'Unauthorized')
44
44
  d = create_driver
45
45
  d.emit('message' => log_entry(0))
@@ -48,14 +48,14 @@ class GoogleCloudOutputTest < Test::Unit::TestCase
48
48
  rescue Google::Apis::AuthorizationError => error
49
49
  assert_equal 'Unauthorized', error.message
50
50
  end
51
- assert_requested(:post, uri_for_log(COMPUTE_PARAMS), times: 2)
51
+ assert_requested(:post, WRITE_LOG_ENTRIES_URI, times: 2)
52
52
  end
53
53
 
54
54
  def test_server_error
55
55
  setup_gce_metadata_stubs
56
56
  # The API client should retry this once, then throw an exception which
57
57
  # gets propagated through the plugin.
58
- stub_request(:post, uri_for_log(COMPUTE_PARAMS))
58
+ stub_request(:post, WRITE_LOG_ENTRIES_URI)
59
59
  .to_return(status: 500, body: 'Server Error')
60
60
  d = create_driver
61
61
  d.emit('message' => log_entry(0))
@@ -66,7 +66,7 @@ class GoogleCloudOutputTest < Test::Unit::TestCase
66
66
  assert_equal 'Server error', error.message
67
67
  exception_count += 1
68
68
  end
69
- assert_requested(:post, uri_for_log(COMPUTE_PARAMS), times: 1)
69
+ assert_requested(:post, WRITE_LOG_ENTRIES_URI, times: 1)
70
70
  assert_equal 1, exception_count
71
71
  end
72
72
 
@@ -84,7 +84,7 @@ class GoogleCloudOutputTest < Test::Unit::TestCase
84
84
  # the proto.
85
85
  assert_equal http_request_message_with_nil_referer,
86
86
  entry['httpRequest'], entry
87
- assert_nil get_fields(entry['structPayload'])['httpRequest'], entry
87
+ assert_nil get_fields(entry['jsonPayload'])['httpRequest'], entry
88
88
  end
89
89
  end
90
90
 
@@ -113,7 +113,7 @@ class GoogleCloudOutputTest < Test::Unit::TestCase
113
113
  verify_index = 0
114
114
  verify_log_entries(emit_index, COMPUTE_PARAMS) do |entry|
115
115
  assert_equal expected_severity[verify_index],
116
- entry['metadata']['severity'], entry
116
+ entry['severity'], entry
117
117
  verify_index += 1
118
118
  end
119
119
  end
@@ -181,7 +181,6 @@ class GoogleCloudOutputTest < Test::Unit::TestCase
181
181
  assert_equal('ERROR', test_obj.parse_severity('ERROR '))
182
182
  assert_equal('ERROR', test_obj.parse_severity(' ERROR '))
183
183
  assert_equal('ERROR', test_obj.parse_severity("\t ERROR "))
184
-
185
184
  # space in the middle should not be stripped.
186
185
  assert_equal('DEFAULT', test_obj.parse_severity('ER ROR'))
187
186
 
@@ -208,9 +207,8 @@ class GoogleCloudOutputTest < Test::Unit::TestCase
208
207
  d.run
209
208
  end
210
209
  verify_log_entries(1, COMPUTE_PARAMS) do |entry|
211
- assert_equal timestamp, entry['metadata']['timestamp'],
212
- "Test with timestamp '#{timestamp}' failed for " \
213
- "entry: '#{entry}'."
210
+ assert_equal timestamp, entry['timestamp'], 'Test with timestamp ' \
211
+ "'#{timestamp}' failed for entry: '#{entry}'."
214
212
  end
215
213
  end
216
214
  end
@@ -221,25 +219,11 @@ class GoogleCloudOutputTest < Test::Unit::TestCase
221
219
  hash.merge(new_key => hash[old_key]).reject { |k, _| k == old_key }
222
220
  end
223
221
 
224
- # The REST path uses old bindings that were generated prior to the field
225
- # rename, and has to use the old name, which is 'validatedWithOriginServer'.
226
- def http_request_message
227
- rename_key(super, 'cacheValidatedWithOriginServer',
228
- 'validatedWithOriginServer')
229
- end
230
-
231
222
  # Set up http stubs to mock the external calls.
232
- def setup_logging_stubs(override_stub_params = nil)
233
- stub_params = override_stub_params || \
234
- [COMPUTE_PARAMS, VMENGINE_PARAMS, CONTAINER_FROM_TAG_PARAMS,
235
- CONTAINER_FROM_METADATA_PARAMS, CLOUDFUNCTIONS_PARAMS,
236
- CUSTOM_PARAMS, EC2_PARAMS]
237
- stub_params.each do |params|
238
- stub_request(:post, uri_for_log(params)).to_return do |request|
239
- log_name = "projects/#{params[:project_id]}/logs/#{params[:log_name]}"
240
- @logs_sent << JSON.parse(request.body).merge('logName' => log_name)
241
- { body: '' }
242
- end
223
+ def setup_logging_stubs
224
+ stub_request(:post, WRITE_LOG_ENTRIES_URI).to_return do |request|
225
+ @logs_sent << JSON.parse(request.body)
226
+ { body: '' }
243
227
  end
244
228
  yield
245
229
  end
@@ -270,9 +254,9 @@ class GoogleCloudOutputTest < Test::Unit::TestCase
270
254
  end
271
255
  end
272
256
 
273
- # Get the fields of the struct payload.
274
- def get_fields(struct_payload)
275
- struct_payload
257
+ # Get the fields of the payload.
258
+ def get_fields(payload)
259
+ payload
276
260
  end
277
261
 
278
262
  # Get the value of a struct field.
@@ -31,7 +31,7 @@ class GoogleCloudOutputGRPCTest < Test::Unit::TestCase
31
31
  { 8 => 'ResourceExhausted',
32
32
  12 => 'Unimplemented',
33
33
  16 => 'Unauthenticated' }.each_with_index do |(code, message), index|
34
- setup_logging_stubs(nil, true, code, message) do
34
+ setup_logging_stubs(true, code, message) do
35
35
  d = create_driver(USE_GRPC_CONFIG, 'test',
36
36
  GRPCLoggingMockFailingService.rpc_stub_class)
37
37
  # The API Client should not retry this and the plugin should consume the
@@ -51,7 +51,7 @@ class GoogleCloudOutputGRPCTest < Test::Unit::TestCase
51
51
  13 => 'Internal',
52
52
  14 => 'Unavailable' }.each_with_index do |(code, message), index|
53
53
  exception_count = 0
54
- setup_logging_stubs(nil, true, code, message) do
54
+ setup_logging_stubs(true, code, message) do
55
55
  d = create_driver(USE_GRPC_CONFIG, 'test',
56
56
  GRPCLoggingMockFailingService.rpc_stub_class)
57
57
  # The API client should retry this once, then throw an exception which
@@ -82,7 +82,7 @@ class GoogleCloudOutputGRPCTest < Test::Unit::TestCase
82
82
  verify_log_entries(1, COMPUTE_PARAMS, 'httpRequest') do |entry|
83
83
  assert_equal http_request_message_with_absent_referer,
84
84
  entry['httpRequest'], entry
85
- assert_nil get_fields(entry['structPayload'])['httpRequest'], entry
85
+ assert_nil get_fields(entry['jsonPayload'])['httpRequest'], entry
86
86
  end
87
87
  end
88
88
 
@@ -96,7 +96,7 @@ class GoogleCloudOutputGRPCTest < Test::Unit::TestCase
96
96
  verify_log_entries(1, COMPUTE_PARAMS, 'httpRequest') do |entry|
97
97
  assert_equal http_request_message_with_absent_referer,
98
98
  entry['httpRequest'], entry
99
- assert_nil get_fields(entry['structPayload'])['httpRequest'], entry
99
+ assert_nil get_fields(entry['jsonPayload'])['httpRequest'], entry
100
100
  end
101
101
  end
102
102
 
@@ -124,7 +124,7 @@ class GoogleCloudOutputGRPCTest < Test::Unit::TestCase
124
124
  end
125
125
  verify_index = 0
126
126
  verify_log_entries(emit_index, COMPUTE_PARAMS) do |entry|
127
- assert_equal_with_default(entry['metadata']['severity'],
127
+ assert_equal_with_default(entry['severity'],
128
128
  expected_severity[verify_index],
129
129
  'DEFAULT', entry)
130
130
  verify_index += 1
@@ -143,8 +143,8 @@ class GoogleCloudOutputGRPCTest < Test::Unit::TestCase
143
143
  'null_field' => nil)
144
144
  d.run
145
145
  end
146
- verify_log_entries(1, COMPUTE_PARAMS, 'structPayload') do |entry|
147
- fields = get_fields(entry['structPayload'])
146
+ verify_log_entries(1, COMPUTE_PARAMS, 'jsonPayload') do |entry|
147
+ fields = get_fields(entry['jsonPayload'])
148
148
  assert_equal 5, fields.size, entry
149
149
  assert_equal 'test log entry 0', get_string(fields['msg']), entry
150
150
  assert_equal 'test non utf8', get_string(fields['normal_key']), entry
@@ -174,9 +174,8 @@ class GoogleCloudOutputGRPCTest < Test::Unit::TestCase
174
174
  d.run
175
175
  end
176
176
  verify_log_entries(1, COMPUTE_PARAMS) do |entry|
177
- assert_equal expected, entry['metadata']['timestamp'],
178
- "Test with timestamp '#{input}' failed for " \
179
- "entry: '#{entry}'."
177
+ assert_equal expected, entry['timestamp'], 'Test with timestamp ' \
178
+ "'#{input}' failed for entry: '#{entry}'."
180
179
  end
181
180
  end
182
181
  end
@@ -185,8 +184,8 @@ class GoogleCloudOutputGRPCTest < Test::Unit::TestCase
185
184
 
186
185
  GRPC_MOCK_HOST = 'localhost:56789'
187
186
 
188
- WriteLogEntriesRequest = Google::Logging::V1::WriteLogEntriesRequest
189
- WriteLogEntriesResponse = Google::Logging::V1::WriteLogEntriesResponse
187
+ WriteLogEntriesRequest = Google::Logging::V2::WriteLogEntriesRequest
188
+ WriteLogEntriesResponse = Google::Logging::V2::WriteLogEntriesResponse
190
189
 
191
190
  USE_GRPC_CONFIG = %(
192
191
  use_grpc true
@@ -223,18 +222,13 @@ class GoogleCloudOutputGRPCTest < Test::Unit::TestCase
223
222
  end
224
223
 
225
224
  # GRPC logging mock that successfully logs the records.
226
- class GRPCLoggingMockService < Google::Logging::V1::LoggingService::Service
227
- def initialize(stub_params, requests_received)
225
+ class GRPCLoggingMockService < Google::Logging::V2::LoggingServiceV2::Service
226
+ def initialize(requests_received)
228
227
  super()
229
228
  @requests_received = requests_received
230
- @expected_log_names = stub_params.map do |param|
231
- "projects/#{param[:project_id]}/logs/#{param[:log_name]}"
232
- end
233
229
  end
234
230
 
235
231
  def write_log_entries(request, _call)
236
- fail GRPC::BadStatus.new(99, "Unexpected request: #{request.inspect}") \
237
- unless @expected_log_names.include?(request.log_name)
238
232
  @requests_received << request
239
233
  WriteLogEntriesResponse.new
240
234
  end
@@ -248,15 +242,17 @@ class GoogleCloudOutputGRPCTest < Test::Unit::TestCase
248
242
  end
249
243
 
250
244
  alias_method :list_logs, :_undefined
245
+ alias_method :list_log_entries, :_undefined
251
246
  alias_method :list_log_services, :_undefined
252
247
  alias_method :list_log_service_indexes, :_undefined
248
+ alias_method :list_monitored_resource_descriptors, :_undefined
253
249
  alias_method :delete_log, :_undefined
254
250
  undef_method :_undefined
255
251
  end
256
252
 
257
253
  # GRPC logging mock that fails and returns server side or client side errors.
258
254
  class GRPCLoggingMockFailingService <
259
- Google::Logging::V1::LoggingService::Service
255
+ Google::Logging::V2::LoggingServiceV2::Service
260
256
  # 'code_sent' and 'message_sent' are references of external variables. We
261
257
  # will assert the values of them later. 'code_value' and 'message_value'
262
258
  # are actual error code and message we expect this mock to return.
@@ -281,26 +277,23 @@ class GoogleCloudOutputGRPCTest < Test::Unit::TestCase
281
277
  end
282
278
 
283
279
  alias_method :list_logs, :_undefined
280
+ alias_method :list_log_entries, :_undefined
284
281
  alias_method :list_log_services, :_undefined
285
282
  alias_method :list_log_service_indexes, :_undefined
283
+ alias_method :list_monitored_resource_descriptors, :_undefined
286
284
  alias_method :delete_log, :_undefined
287
285
  undef_method :_undefined
288
286
  end
289
287
 
290
288
  # Set up grpc stubs to mock the external calls.
291
- def setup_logging_stubs(override_stub_params = nil, should_fail = false,
292
- code = 0, message = 'Ok')
293
- stub_params = override_stub_params || \
294
- [COMPUTE_PARAMS, VMENGINE_PARAMS, CONTAINER_FROM_TAG_PARAMS,
295
- CONTAINER_FROM_METADATA_PARAMS, CLOUDFUNCTIONS_PARAMS,
296
- CUSTOM_PARAMS, EC2_PARAMS]
289
+ def setup_logging_stubs(should_fail = false, code = 0, message = 'Ok')
297
290
  srv = GRPC::RpcServer.new
298
291
  @failed_attempts = []
299
292
  @requests_sent = []
300
293
  if should_fail
301
294
  grpc = GRPCLoggingMockFailingService.new(code, message, @failed_attempts)
302
295
  else
303
- grpc = GRPCLoggingMockService.new(stub_params, @requests_sent)
296
+ grpc = GRPCLoggingMockService.new(@requests_sent)
304
297
  end
305
298
  srv.handle(grpc)
306
299
  srv.add_http2_port(GRPC_MOCK_HOST, :this_port_is_insecure)
@@ -320,8 +313,8 @@ class GoogleCloudOutputGRPCTest < Test::Unit::TestCase
320
313
  # Verify the number and the content of the log entries match the expectation.
321
314
  # The caller can optionally provide a block which is called for each entry.
322
315
  def verify_log_entries(n, params, payload_type = 'textPayload', &block)
323
- @requests_sent.each do |batch|
324
- @logs_sent << JSON.parse(batch.to_json)
316
+ @requests_sent.each do |request|
317
+ @logs_sent << JSON.parse(request.to_json)
325
318
  end
326
319
  verify_json_log_entries(n, params, payload_type, &block)
327
320
  end
@@ -349,14 +342,14 @@ class GoogleCloudOutputGRPCTest < Test::Unit::TestCase
349
342
 
350
343
  # Unset the 'referer' field.
351
344
  def http_request_message_with_absent_referer
352
- http_request_message.reject do |k, _|
345
+ HTTP_REQUEST_MESSAGE.reject do |k, _|
353
346
  k == 'referer'
354
347
  end
355
348
  end
356
349
 
357
- # Get the fields of the struct payload.
358
- def get_fields(struct_payload)
359
- struct_payload['fields']
350
+ # Get the fields of the payload.
351
+ def get_fields(payload)
352
+ payload['fields']
360
353
  end
361
354
 
362
355
  # Get the value of a struct field.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-google-cloud
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.6
4
+ version: 0.6.0.v2.alpha.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Todd Derr
@@ -53,6 +53,20 @@ dependencies:
53
53
  - - "~>"
54
54
  - !ruby/object:Gem::Version
55
55
  version: 0.9.0
56
+ - !ruby/object:Gem::Dependency
57
+ name: google-cloud-logging
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: 0.23.2
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: 0.23.2
56
70
  - !ruby/object:Gem::Dependency
57
71
  name: googleauth
58
72
  requirement: !ruby/object:Gem::Requirement
@@ -184,11 +198,6 @@ files:
184
198
  - Rakefile
185
199
  - fluent-plugin-google-cloud.gemspec
186
200
  - lib/fluent/plugin/out_google_cloud.rb
187
- - lib/google/logging/type/http_request_pb.rb
188
- - lib/google/logging/type/log_severity_pb.rb
189
- - lib/google/logging/v1/log_entry_pb.rb
190
- - lib/google/logging/v1/logging_pb.rb
191
- - lib/google/logging/v1/logging_services_pb.rb
192
201
  - test/helper.rb
193
202
  - test/plugin/base_test.rb
194
203
  - test/plugin/data/c31e573fd7f62ed495c9ca3821a5a85cb036dee1-privatekey.p12
@@ -212,12 +221,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
212
221
  version: '2.0'
213
222
  required_rubygems_version: !ruby/object:Gem::Requirement
214
223
  requirements:
215
- - - ">="
224
+ - - ">"
216
225
  - !ruby/object:Gem::Version
217
- version: '0'
226
+ version: 1.3.1
218
227
  requirements: []
219
228
  rubyforge_project:
220
- rubygems_version: 2.4.8
229
+ rubygems_version: 2.6.10
221
230
  signing_key:
222
231
  specification_version: 4
223
232
  summary: fluentd output plugin for the Stackdriver Logging API
@@ -1,30 +0,0 @@
1
- # Generated by the protocol buffer compiler. DO NOT EDIT!
2
- # source: google/logging/type/http_request.proto
3
-
4
- require 'google/protobuf'
5
-
6
- Google::Protobuf::DescriptorPool.generated_pool.build do
7
- add_message "google.logging.type.HttpRequest" do
8
- optional :request_method, :string, 1
9
- optional :request_url, :string, 2
10
- optional :request_size, :int64, 3
11
- optional :status, :int32, 4
12
- optional :response_size, :int64, 5
13
- optional :user_agent, :string, 6
14
- optional :remote_ip, :string, 7
15
- optional :server_ip, :string, 13
16
- optional :referer, :string, 8
17
- optional :cache_lookup, :bool, 11
18
- optional :cache_hit, :bool, 9
19
- optional :cache_validated_with_origin_server, :bool, 10
20
- optional :cache_fill_bytes, :int64, 12
21
- end
22
- end
23
-
24
- module Google
25
- module Logging
26
- module Type
27
- HttpRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.logging.type.HttpRequest").msgclass
28
- end
29
- end
30
- end
@@ -1,26 +0,0 @@
1
- # Generated by the protocol buffer compiler. DO NOT EDIT!
2
- # source: google/logging/type/log_severity.proto
3
-
4
- require 'google/protobuf'
5
-
6
- Google::Protobuf::DescriptorPool.generated_pool.build do
7
- add_enum "google.logging.type.LogSeverity" do
8
- value :DEFAULT, 0
9
- value :DEBUG, 100
10
- value :INFO, 200
11
- value :NOTICE, 300
12
- value :WARNING, 400
13
- value :ERROR, 500
14
- value :CRITICAL, 600
15
- value :ALERT, 700
16
- value :EMERGENCY, 800
17
- end
18
- end
19
-
20
- module Google
21
- module Logging
22
- module Type
23
- LogSeverity = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.logging.type.LogSeverity").enummodule
24
- end
25
- end
26
- end
@@ -1,52 +0,0 @@
1
- # Generated by the protocol buffer compiler. DO NOT EDIT!
2
- # source: google/logging/v1/log_entry.proto
3
-
4
- require 'google/protobuf'
5
-
6
- require 'google/logging/type/http_request_pb'
7
- require 'google/logging/type/log_severity_pb'
8
- require 'google/protobuf/any_pb'
9
- require 'google/protobuf/struct_pb'
10
- require 'google/protobuf/timestamp_pb'
11
- Google::Protobuf::DescriptorPool.generated_pool.build do
12
- add_message "google.logging.v1.LogEntry" do
13
- optional :metadata, :message, 1, "google.logging.v1.LogEntryMetadata"
14
- optional :insert_id, :string, 4
15
- optional :log, :string, 5
16
- optional :http_request, :message, 7, "google.logging.type.HttpRequest"
17
- optional :operation, :message, 8, "google.logging.v1.LogEntryOperation"
18
- optional :writer_email_address, :string, 9
19
- oneof :payload do
20
- optional :proto_payload, :message, 2, "google.protobuf.Any"
21
- optional :text_payload, :string, 3
22
- optional :struct_payload, :message, 6, "google.protobuf.Struct"
23
- end
24
- end
25
- add_message "google.logging.v1.LogEntryMetadata" do
26
- optional :timestamp, :message, 9, "google.protobuf.Timestamp"
27
- optional :severity, :enum, 2, "google.logging.type.LogSeverity"
28
- optional :project_id, :string, 3
29
- optional :project_number, :int64, 10
30
- optional :service_name, :string, 4
31
- optional :region, :string, 5
32
- optional :zone, :string, 6
33
- optional :user_id, :string, 7
34
- map :labels, :string, :string, 8
35
- end
36
- add_message "google.logging.v1.LogEntryOperation" do
37
- optional :id, :string, 1
38
- optional :producer, :string, 2
39
- optional :first, :bool, 3
40
- optional :last, :bool, 4
41
- end
42
- end
43
-
44
- module Google
45
- module Logging
46
- module V1
47
- LogEntry = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.logging.v1.LogEntry").msgclass
48
- LogEntryMetadata = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.logging.v1.LogEntryMetadata").msgclass
49
- LogEntryOperation = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.logging.v1.LogEntryOperation").msgclass
50
- end
51
- end
52
- end