fluent-plugin-google-cloud 0.6.15 → 0.6.16

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
  SHA1:
3
- metadata.gz: 5a893e6f22835b55a791d1c530286733d22d49a0
4
- data.tar.gz: ecd9cf870e72ff2c7b2961cfc5f135df8911c941
3
+ metadata.gz: dc441330446e0c25bc08501530b66b7d6564dc37
4
+ data.tar.gz: 55a4592b58913b49b23cab5ddfc469a97afd5c4f
5
5
  SHA512:
6
- metadata.gz: 9156624b572bbe99385777b01a6f331920f19387aa2631dedbf14e9b2c1395519932f4ae7bcfde2d8098403e302dbebe0b99ee135fc5dcd30bea67af198a3342
7
- data.tar.gz: dc2d3c73e3917020de5da358f5bf731068b1b9bc6e7f20e50130e0e2d6ccb2fe506b561ab17f27581ed72032519aec2d5f1223e2be69907f401e45db2525546e
6
+ metadata.gz: 55d494d4e51e821a800b06a3cf936fdbb0fa01305d4e04531f5c0f34001188be0da9b90ea8b84111a6d5f77abd9745f91cf3ec4465939c7af5d2ff11edd55b9f
7
+ data.tar.gz: 55566646fd0f2656df5fc9d8373d17fc6ddb364b527b74ae6a1be24173e7d0aaec141ea8e90c2bf0a4f7c66d7f471e8a85b9ecc4ef65d1985d164fb86b51126f
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fluent-plugin-google-cloud (0.6.15)
4
+ fluent-plugin-google-cloud (0.6.16)
5
5
  fluentd (~> 0.10)
6
6
  google-api-client (~> 0.17)
7
7
  google-cloud-logging (~> 1.3, >= 1.3.2)
@@ -34,21 +34,21 @@ GEM
34
34
  tzinfo (~> 1.0)
35
35
  tzinfo-data (~> 1.0)
36
36
  yajl-ruby (~> 1.0)
37
- google-api-client (0.19.5)
37
+ google-api-client (0.19.8)
38
38
  addressable (~> 2.5, >= 2.5.1)
39
39
  googleauth (>= 0.5, < 0.7.0)
40
40
  httpclient (>= 2.8.1, < 3.0)
41
41
  mime-types (~> 3.0)
42
42
  representable (~> 3.0)
43
43
  retriable (>= 2.0, < 4.0)
44
- google-cloud-core (1.1.0)
44
+ google-cloud-core (1.2.0)
45
45
  google-cloud-env (~> 1.0)
46
46
  google-cloud-env (1.0.1)
47
47
  faraday (~> 0.11)
48
- google-cloud-logging (1.4.0)
49
- google-cloud-core (~> 1.1)
48
+ google-cloud-logging (1.5.0)
49
+ google-cloud-core (~> 1.2)
50
50
  google-gax (~> 1.0)
51
- stackdriver-core (~> 1.2)
51
+ stackdriver-core (~> 1.3)
52
52
  google-gax (1.0.1)
53
53
  google-protobuf (~> 3.2)
54
54
  googleapis-common-protos (>= 1.3.5, < 2.0)
@@ -70,7 +70,7 @@ GEM
70
70
  multi_json (~> 1.11)
71
71
  os (~> 0.9)
72
72
  signet (~> 0.7)
73
- grpc (1.8.3)
73
+ grpc (1.9.1)
74
74
  google-protobuf (~> 3.1)
75
75
  googleapis-common-protos-types (~> 1.0.0)
76
76
  googleauth (>= 0.5.1, < 0.7)
@@ -94,13 +94,13 @@ GEM
94
94
  multi_json (1.13.1)
95
95
  multipart-post (2.0.0)
96
96
  os (0.9.6)
97
- parser (2.4.0.2)
98
- ast (~> 2.3)
97
+ parser (2.5.0.2)
98
+ ast (~> 2.4.0)
99
99
  power_assert (1.1.1)
100
100
  powerpack (0.1.1)
101
101
  prometheus-client (0.7.1)
102
102
  quantile (~> 0.2.0)
103
- public_suffix (3.0.1)
103
+ public_suffix (3.0.2)
104
104
  quantile (0.2.0)
105
105
  rainbow (2.2.2)
106
106
  rake
@@ -128,12 +128,13 @@ GEM
128
128
  faraday (~> 0.9)
129
129
  jwt (>= 1.5, < 3.0)
130
130
  multi_json (~> 1.10)
131
- stackdriver-core (1.2.0)
131
+ stackdriver-core (1.3.0)
132
+ google-cloud-core (~> 1.2)
132
133
  strptime (0.1.9)
133
134
  test-unit (3.2.7)
134
135
  power_assert
135
136
  thread_safe (0.3.6)
136
- tzinfo (1.2.4)
137
+ tzinfo (1.2.5)
137
138
  thread_safe (~> 0.1)
138
139
  tzinfo-data (1.2018.3)
139
140
  tzinfo (>= 1.0.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.6.15'
13
+ gem.version = '0.6.16'
14
14
  gem.authors = ['Todd Derr', 'Alex Robinson']
15
15
  gem.email = ['salty@google.com']
16
16
  gem.required_ruby_version = Gem::Requirement.new('>= 2.0')
@@ -124,6 +124,7 @@ module Fluent
124
124
 
125
125
  DEFAULT_METADATA_AGENT_URL =
126
126
  'http://local-metadata-agent.stackdriver.com:8000'.freeze
127
+ METADATA_AGENT_URL_ENV_VAR = 'STACKDRIVER_METADATA_AGENT_URL'.freeze
127
128
  end
128
129
 
129
130
  # Internal constants.
@@ -198,7 +199,7 @@ module Fluent
198
199
  Fluent::Plugin.register_output('google_cloud', self)
199
200
 
200
201
  PLUGIN_NAME = 'Fluentd Google Cloud Logging plugin'.freeze
201
- PLUGIN_VERSION = '0.6.15'.freeze
202
+ PLUGIN_VERSION = '0.6.16'.freeze
202
203
 
203
204
  # Name of the the Google cloud logging write scope.
204
205
  LOGGING_SCOPE = 'https://www.googleapis.com/auth/logging.write'.freeze
@@ -350,8 +351,13 @@ module Fluent
350
351
 
351
352
  # Whether to call metadata agent to retrieve monitored resource.
352
353
  config_param :enable_metadata_agent, :bool, :default => false
353
- config_param :metadata_agent_url, :string,
354
- :default => DEFAULT_METADATA_AGENT_URL
354
+
355
+ # The URL of the Metadata Agent.
356
+ # If this option is set, its value is used to contact the Metadata Agent.
357
+ # Otherwise, the value of the STACKDRIVER_METADATA_AGENT_URL environment
358
+ # variable is used. If that is also unset, this defaults to
359
+ # 'http://local-metadata-agent.stackdriver.com:8000'.
360
+ config_param :metadata_agent_url, :string, :default => nil
355
361
 
356
362
  # Whether to split log entries with different log tags into different
357
363
  # requests when talking to Stackdriver Logging API.
@@ -387,6 +393,20 @@ module Fluent
387
393
  ' ignored.'
388
394
  end
389
395
 
396
+ # 1. If @metadata_agent_url is customized (aka not nil), use that.
397
+ # 2. Otherwise check the presence of the environment variable
398
+ # STACKDRIVER_METADATA_AGENT_URL and use that if set.
399
+ # 3. Fall back to the default if neither is set.
400
+ if @enable_metadata_agent
401
+ # Convert to string to capture empty string.
402
+ @metadata_agent_url ||=
403
+ if ENV[METADATA_AGENT_URL_ENV_VAR].to_s.empty?
404
+ DEFAULT_METADATA_AGENT_URL
405
+ else
406
+ ENV[METADATA_AGENT_URL_ENV_VAR]
407
+ end
408
+ end
409
+
390
410
  # If monitoring is enabled, register metrics in the default registry
391
411
  # and store metric objects for future use.
392
412
  if @enable_monitoring
@@ -1181,11 +1201,9 @@ module Fluent
1181
1201
  # inferred from the tag) if failed to get a monitored resource from
1182
1202
  # Metadata Agent with this key.
1183
1203
  #
1184
- # Docker container:
1185
- # "container.<container_id>"
1186
- # "containerName.<container_name>"
1187
- # GKE container:
1188
- # "gke_containerName.<namespace_id>.<pod_name>.<container_name>"
1204
+ # Examples:
1205
+ # "container.<container_id>" // Docker container.
1206
+ # "k8s_pod.<namespace_name>.<pod_name>" // GKE pod.
1189
1207
  if @enable_metadata_agent && local_resource_id
1190
1208
  @log.debug 'Calling metadata agent with local_resource_id: ' \
1191
1209
  "#{local_resource_id}."
@@ -1384,7 +1402,7 @@ module Fluent
1384
1402
  return parsed_hash
1385
1403
  end
1386
1404
  rescue StandardError => e
1387
- @log.error 'Error calling Metadata Agent.', error: e
1405
+ @log.error "Error calling Metadata Agent at #{url}.", error: e
1388
1406
  end
1389
1407
 
1390
1408
  # TODO: This functionality should eventually be available in another
@@ -116,6 +116,30 @@ module BaseTest
116
116
  end
117
117
  end
118
118
 
119
+ def test_metadata_agent_url_customization
120
+ [
121
+ # If @metadata_agent_url is set, use that even if the environment
122
+ # variable is set.
123
+ [CUSTOM_METADATA_AGENT_URL_CONFIG, true, CUSTOM_METADATA_AGENT_URL],
124
+ # If @metadata_agent_url is set and the environment variable is
125
+ # not set, use @metadata_agent_url.
126
+ [CUSTOM_METADATA_AGENT_URL_CONFIG, false, CUSTOM_METADATA_AGENT_URL],
127
+ # If @metadata_agent_url is not set and the environment variable is set,
128
+ # use the env.
129
+ [APPLICATION_DEFAULT_CONFIG, true, METADATA_AGENT_URL_FROM_ENV],
130
+ # If @metadata_agent_url is not set and the environment variable is
131
+ # not set, fall back to the default.
132
+ [APPLICATION_DEFAULT_CONFIG, false, DEFAULT_METADATA_AGENT_URL]
133
+ ].each do |(config, url_from_env, expected_url)|
134
+ ENV[METADATA_AGENT_URL_ENV_VAR] = METADATA_AGENT_URL_FROM_ENV if
135
+ url_from_env
136
+ setup_gce_metadata_stubs
137
+ d = create_driver(ENABLE_METADATA_AGENT_CONFIG + config)
138
+ assert_equal expected_url, d.instance.metadata_agent_url
139
+ ENV.delete(METADATA_AGENT_URL_ENV_VAR)
140
+ end
141
+ end
142
+
119
143
  def test_metadata_loading
120
144
  setup_gce_metadata_stubs
121
145
  d = create_driver
@@ -1260,7 +1284,7 @@ module BaseTest
1260
1284
 
1261
1285
  # Test logs from applications running in Docker containers. These logs have
1262
1286
  # the label "logging.googleapis.com/local_resource_id" set in the format of
1263
- # "containerName.<container_name>".
1287
+ # "container.<container_name>".
1264
1288
  def test_docker_container_application_logs
1265
1289
  new_stub_context do
1266
1290
  setup_gce_metadata_stubs
@@ -1274,7 +1298,7 @@ module BaseTest
1274
1298
  end
1275
1299
  verify_log_entries(1, DOCKER_CONTAINER_PARAMS_NO_STREAM)
1276
1300
  assert_requested_metadata_agent_stub(
1277
- "containerName.#{DOCKER_CONTAINER_NAME}")
1301
+ "#{DOCKER_CONTAINER_LOCAL_RESOURCE_ID_PREFIX}.#{DOCKER_CONTAINER_NAME}")
1278
1302
  end
1279
1303
  end
1280
1304
 
@@ -1298,7 +1322,7 @@ module BaseTest
1298
1322
  entry['timestamp']['nanos'], entry
1299
1323
  end
1300
1324
  assert_requested_metadata_agent_stub(
1301
- "containerName.#{DOCKER_CONTAINER_NAME}")
1325
+ "#{DOCKER_CONTAINER_LOCAL_RESOURCE_ID_PREFIX}.#{DOCKER_CONTAINER_NAME}")
1302
1326
  end
1303
1327
  end
1304
1328
 
@@ -1333,7 +1357,7 @@ module BaseTest
1333
1357
 
1334
1358
  # Test GKE container logs. These logs have the label
1335
1359
  # "logging.googleapis.com/local_resource_id" set in the format of
1336
- # "gke_containerName.<namespace_id>.<pod_name>.<container_name>".
1360
+ # "gke_container.<namespace_id>.<pod_name>.<container_name>".
1337
1361
  def test_gke_container_logs
1338
1362
  [1, 2, 3, 5, 11, 50].each do |n|
1339
1363
  new_stub_context do
@@ -1349,8 +1373,8 @@ module BaseTest
1349
1373
  end
1350
1374
  verify_log_entries(n, CONTAINER_FROM_APPLICATION_PARAMS)
1351
1375
  assert_requested_metadata_agent_stub(
1352
- "gke_containerName.#{CONTAINER_NAMESPACE_ID}.#{CONTAINER_POD_NAME}." \
1353
- "#{CONTAINER_CONTAINER_NAME}")
1376
+ "#{CONTAINER_LOCAL_RESOURCE_ID_PREFIX}.#{CONTAINER_NAMESPACE_ID}" \
1377
+ ".#{CONTAINER_POD_NAME}.#{CONTAINER_CONTAINER_NAME}")
1354
1378
  end
1355
1379
  end
1356
1380
  end
@@ -1533,7 +1557,7 @@ module BaseTest
1533
1557
  {
1534
1558
  log: log,
1535
1559
  LOCAL_RESOURCE_ID_KEY =>
1536
- "gke_containerName.#{CONTAINER_NAMESPACE_ID}" \
1560
+ "#{CONTAINER_LOCAL_RESOURCE_ID_PREFIX}.#{CONTAINER_NAMESPACE_ID}" \
1537
1561
  ".#{CONTAINER_POD_NAME}.#{CONTAINER_CONTAINER_NAME}"
1538
1562
  }
1539
1563
  end
@@ -1559,7 +1583,8 @@ module BaseTest
1559
1583
  {
1560
1584
  log: log,
1561
1585
  time: DOCKER_CONTAINER_TIMESTAMP,
1562
- LOCAL_RESOURCE_ID_KEY => "containerName.#{DOCKER_CONTAINER_NAME}"
1586
+ LOCAL_RESOURCE_ID_KEY => "#{DOCKER_CONTAINER_LOCAL_RESOURCE_ID_PREFIX}." \
1587
+ "#{DOCKER_CONTAINER_NAME}"
1563
1588
  }
1564
1589
  end
1565
1590
 
@@ -21,6 +21,8 @@ module Constants
21
21
  # Generic attributes.
22
22
  HOSTNAME = Socket.gethostname
23
23
  CUSTOM_LOGGING_API_URL = 'http://localhost:52000'.freeze
24
+ CUSTOM_METADATA_AGENT_URL = 'http://localhost:12345'.freeze
25
+ METADATA_AGENT_URL_FROM_ENV = 'http://localhost:54321'.freeze
24
26
 
25
27
  # TODO(qingling128) Separate constants into different submodules.
26
28
  # Attributes used for the GCE metadata service.
@@ -71,6 +73,7 @@ module Constants
71
73
  DOCKER_CONTAINER_TIMESTAMP = '2009-02-13T23:31:30.987654321Z'.freeze
72
74
  DOCKER_CONTAINER_SECONDS_EPOCH = 1_234_567_890
73
75
  DOCKER_CONTAINER_NANOS = 987_654_321
76
+ DOCKER_CONTAINER_LOCAL_RESOURCE_ID_PREFIX = 'container'.freeze
74
77
 
75
78
  # Container Engine / Kubernetes specific labels.
76
79
  CONTAINER_CLUSTER_NAME = 'cluster-1'.freeze
@@ -87,6 +90,7 @@ module Constants
87
90
  CONTAINER_TIMESTAMP = '2009-02-13T23:31:30.987654321Z'.freeze
88
91
  CONTAINER_SECONDS_EPOCH = 1_234_567_890
89
92
  CONTAINER_NANOS = 987_654_321
93
+ CONTAINER_LOCAL_RESOURCE_ID_PREFIX = 'gke_container'.freeze
90
94
 
91
95
  # Cloud Functions specific labels.
92
96
  CLOUDFUNCTIONS_FUNCTION_NAME = '$My_Function.Name-@1'.freeze
@@ -146,6 +150,10 @@ module Constants
146
150
  logging_api_url #{CUSTOM_LOGGING_API_URL}
147
151
  ).freeze
148
152
 
153
+ CUSTOM_METADATA_AGENT_URL_CONFIG = %(
154
+ metadata_agent_url #{CUSTOM_METADATA_AGENT_URL}
155
+ ).freeze
156
+
149
157
  DETECT_JSON_CONFIG = %(
150
158
  detect_json true
151
159
  ).freeze
@@ -605,7 +613,7 @@ module Constants
605
613
  # Map from the local_resource_id to the retrieved monitored resource.
606
614
  MONITORED_RESOURCE_STUBS = {
607
615
  # Docker container stderr / stdout logs.
608
- "container.#{DOCKER_CONTAINER_ID}" =>
616
+ "#{DOCKER_CONTAINER_LOCAL_RESOURCE_ID_PREFIX}.#{DOCKER_CONTAINER_ID}" =>
609
617
  {
610
618
  'type' => DOCKER_CONSTANTS[:resource_type],
611
619
  'labels' => {
@@ -614,7 +622,7 @@ module Constants
614
622
  }
615
623
  }.to_json,
616
624
  # Docker container application logs.
617
- "containerName.#{DOCKER_CONTAINER_NAME}" =>
625
+ "#{DOCKER_CONTAINER_LOCAL_RESOURCE_ID_PREFIX}.#{DOCKER_CONTAINER_NAME}" =>
618
626
  {
619
627
  'type' => DOCKER_CONSTANTS[:resource_type],
620
628
  'labels' => {
@@ -623,8 +631,8 @@ module Constants
623
631
  }
624
632
  }.to_json,
625
633
  # GKE container logs.
626
- "gke_containerName.#{CONTAINER_NAMESPACE_ID}.#{CONTAINER_POD_NAME}." \
627
- "#{CONTAINER_CONTAINER_NAME}" =>
634
+ "#{CONTAINER_LOCAL_RESOURCE_ID_PREFIX}.#{CONTAINER_NAMESPACE_ID}" \
635
+ ".#{CONTAINER_POD_NAME}.#{CONTAINER_CONTAINER_NAME}" =>
628
636
  {
629
637
  'type' => GKE_CONSTANTS[:resource_type],
630
638
  'labels' => {
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.6.15
4
+ version: 0.6.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Todd Derr
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-01-31 00:00:00.000000000 Z
12
+ date: 2018-03-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fluentd
@@ -249,7 +249,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
249
249
  version: '0'
250
250
  requirements: []
251
251
  rubyforge_project:
252
- rubygems_version: 2.6.8
252
+ rubygems_version: 2.6.14
253
253
  signing_key:
254
254
  specification_version: 4
255
255
  summary: fluentd output plugin for the Stackdriver Logging API