fluent-plugin-google-cloud 0.6.18.pre.1 → 0.6.18.pre.2

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: 96a5943e560b95ee0e8427efb2eef06d17218f75
4
- data.tar.gz: 944c1f9d6391f286a00024ad69a433725b82bdd5
3
+ metadata.gz: 22363c75dc8601301e8ce3e6a759b7f83eb02c45
4
+ data.tar.gz: db92ec8ea70313b48bbf654aea9a5cc88998b8f2
5
5
  SHA512:
6
- metadata.gz: 75e217bea7703bddf67cba284afb6cab2c16b70e18ae1f7e87e6e8e0e7a8fdfd434c1a6dd8be91f299f5e6dac9643ebb9d2c240ca6369f744b9837bd13d9ec59
7
- data.tar.gz: b3f7a0aa1b2df536bff44bdcb1272a4d8a70b7ce4c8737ad79f28b1615945b698a9683b7d291c22566a22f9ffa98d382a82a518c3238a28cdce5c7b6bd605f8f
6
+ metadata.gz: faca80ef319660243f9ffb4607e19a60b1400f12eb4efce959b80de5e77e8c519530403869fc1725f9cd53afb54fe230739f57d02f2bcf950d7f83855c642084
7
+ data.tar.gz: 77e7f853e24625b14eb18a55a7459d35a2135873b200d58ae537beefef937bb352552d76adbdc21ae92a8dd9a0e18f3cccb6d2a52b0a60d5a14d5d9d5ae3996f
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fluent-plugin-google-cloud (0.6.17)
4
+ fluent-plugin-google-cloud (0.6.18.pre.2)
5
5
  fluentd (~> 0.10)
6
6
  google-api-client (~> 0.17)
7
7
  google-cloud-logging (~> 1.3, >= 1.3.2)
@@ -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.18.pre.1'
13
+ gem.version = '0.6.18.pre.2'
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')
@@ -226,7 +226,7 @@ module Fluent
226
226
  Fluent::Plugin.register_output('google_cloud', self)
227
227
 
228
228
  PLUGIN_NAME = 'Fluentd Google Cloud Logging plugin'.freeze
229
- PLUGIN_VERSION = '0.6.18.pre.1'.freeze
229
+ PLUGIN_VERSION = '0.6.18.pre.2'.freeze
230
230
 
231
231
  # Name of the the Google cloud logging write scope.
232
232
  LOGGING_SCOPE = 'https://www.googleapis.com/auth/logging.write'.freeze
@@ -980,16 +980,6 @@ module Fluent
980
980
 
981
981
  @compiled_http_latency_regexp =
982
982
  /^\s*(?<seconds>\d+)(?<decimal>\.\d+)?\s*s\s*$/
983
-
984
- # TODO(qingling128): Temporary fallback for metadata agent restarts.
985
- @compiled_k8s_container_local_resource_id_regexp = /^
986
- (?<resource_type>k8s_container)
987
- \.(?<namespace_name>[0-9a-z-]+)
988
- \.(?<pod_name>[0-9a-z-.]+)
989
- \.(?<container_name>[0-9a-z-]+)$/x
990
- @compiled_k8s_node_local_resource_id_regexp = /^
991
- (?<resource_type>k8s_node)
992
- \.(?<node_name>[0-9a-z-]+)$/x
993
983
  end
994
984
 
995
985
  # Set required variables like @project_id, @vm_id, @vm_name and @zone.
@@ -1257,10 +1247,8 @@ module Fluent
1257
1247
  else
1258
1248
  # TODO(qingling128): This entire else clause is temporary before we
1259
1249
  # implement buffering and caching.
1260
- @log.warn('Failing to retrieve monitored resource from Metadata' \
1261
- " Agent with local_resource_id #{local_resource_id}." \
1262
- ' Trying to construct resource locally if it is a k8s' \
1263
- ' resource.')
1250
+ @log.warn('Failed to retrieve monitored resource from Metadata' \
1251
+ " Agent with local_resource_id #{local_resource_id}.")
1264
1252
  constructed_k8s_resource = construct_k8s_resource_locally(
1265
1253
  local_resource_id)
1266
1254
  resource = constructed_k8s_resource if constructed_k8s_resource
@@ -1314,12 +1302,15 @@ module Fluent
1314
1302
  # Docker container.
1315
1303
  # TODO(qingling128): Remove this logic once the resource is retrieved at a
1316
1304
  # proper time (b/65175256).
1317
- when DOCKER_CONSTANTS[:resource_type],
1318
- # TODO(qingling128): Temporary fallback for metadata agent restarts.
1319
- K8S_CONTAINER_CONSTANTS[:resource_type],
1320
- K8S_NODE_CONSTANTS[:resource_type]
1305
+ when DOCKER_CONSTANTS[:resource_type]
1306
+ common_labels.delete("#{COMPUTE_CONSTANTS[:service]}/resource_name")
1321
1307
 
1308
+ # TODO(qingling128): Temporary fallback for metadata agent restarts.
1309
+ # K8s resources.
1310
+ when K8S_CONTAINER_CONSTANTS[:resource_type],
1311
+ K8S_NODE_CONSTANTS[:resource_type]
1322
1312
  common_labels.delete("#{COMPUTE_CONSTANTS[:service]}/resource_name")
1313
+
1323
1314
  end
1324
1315
 
1325
1316
  # Cloud Dataflow and Cloud ML.
@@ -2177,85 +2168,55 @@ module Fluent
2177
2168
 
2178
2169
  # Construct monitored resource locally for k8s resources.
2179
2170
  def construct_k8s_resource_locally(local_resource_id)
2180
- matched_regexp_group = nil
2181
- # Regex match the local_resource_id to make sure we only do
2182
- # this for 'k8s_container' and 'k8s_node'.
2183
- [@compiled_k8s_node_local_resource_id_regexp,
2184
- @compiled_k8s_container_local_resource_id_regexp].each do |id_regexp|
2185
- matched_regexp_group ||= id_regexp.match(local_resource_id)
2186
- end
2187
- return unless matched_regexp_group
2188
- case matched_regexp_group['resource_type']
2189
- when 'k8s_container'
2190
- @log.debug('Detected local_resource_id in k8s_container format.' \
2191
- "Constructing resource locally with #{local_resource_id}.")
2192
- return construct_k8s_container_resource(matched_regexp_group)
2193
- when 'k8s_node'
2194
- @log.debug('Detected local_resource_id in k8s_node format.' \
2195
- "Constructing resource locally with #{local_resource_id}.")
2196
- return construct_k8s_node_resource(matched_regexp_group)
2197
- end
2198
- end
2171
+ return unless
2172
+ /^
2173
+ (?<resource_type>k8s_container)
2174
+ \.(?<namespace_name>[0-9a-z-]+)
2175
+ \.(?<pod_name>[.0-9a-z-]+)
2176
+ \.(?<container_name>[0-9a-z-]+)$/x =~ local_resource_id ||
2177
+ /^
2178
+ (?<resource_type>k8s_node)
2179
+ \.(?<node_name>[0-9a-z-]+)$/x =~ local_resource_id
2199
2180
 
2200
- # Construct the k8s_container monitored resource locally. In case of any
2201
- # exception, return nil.
2202
- def construct_k8s_container_resource(matched_regexp_group)
2203
- constructed_resource = Google::Apis::LoggingV2::MonitoredResource.new(
2204
- type: 'k8s_container',
2205
- labels: {
2206
- 'namespace_name' => matched_regexp_group['namespace_name'],
2207
- 'pod_name' => matched_regexp_group['pod_name'],
2208
- 'container_name' => matched_regexp_group['container_name'],
2209
- 'cluster_name' => retrieve_k8s_cluster_name,
2210
- 'location' => retrieve_k8s_location
2181
+ begin
2182
+ @k8s_cluster_name ||= fetch_gce_metadata(
2183
+ 'instance/attributes/cluster-name')
2184
+ @k8s_location ||= fetch_gce_metadata(
2185
+ 'instance/attributes/cluster-location')
2186
+ rescue StandardError => e
2187
+ @log.error 'Failed to retrieve k8s cluster name and location.', \
2188
+ error: e
2189
+ end
2190
+ case resource_type
2191
+ when K8S_CONTAINER_CONSTANTS[:resource_type]
2192
+ labels = {
2193
+ 'namespace_name' => namespace_name,
2194
+ 'pod_name' => pod_name,
2195
+ 'container_name' => container_name,
2196
+ 'cluster_name' => @k8s_cluster_name,
2197
+ 'location' => @k8s_location
2211
2198
  }
2212
- )
2213
- @log.debug('Constructed k8s_container resource locally:\n' \
2214
- "#{constructed_resource.inspect}")
2215
- constructed_resource
2216
- rescue StandardError => e
2217
- @log.error 'Failed to construct "k8s_container" resource locally.' \
2218
- ' Falling back to writing logs against instance resource.',
2219
- error: e
2220
- # Fall back to legacy gke resource or default instance resource.
2221
- return
2222
- end
2223
-
2224
- # Construct the k8s_node monitored resource locally. In case of any
2225
- # exception, return nil.
2226
- def construct_k8s_node_resource(matched_regexp_group)
2227
- constructed_resource = Google::Apis::LoggingV2::MonitoredResource.new(
2228
- type: 'k8s_node',
2229
- labels: {
2230
- 'node_name' => matched_regexp_group['node_name'],
2231
- 'cluster_name' => retrieve_k8s_cluster_name,
2232
- 'location' => retrieve_k8s_location
2199
+ fallback_resource = GKE_CONSTANTS[:resource_type]
2200
+ when K8S_NODE_CONSTANTS[:resource_type]
2201
+ labels = {
2202
+ 'node_name' => node_name,
2203
+ 'cluster_name' => @k8s_cluster_name,
2204
+ 'location' => @k8s_location
2233
2205
  }
2234
- )
2235
- @log.debug('Constructed k8s_node resource locally:\n' \
2236
- "#{constructed_resource.inspect}")
2206
+ fallback_resource = COMPUTE_CONSTANTS[:resource_type]
2207
+ end
2208
+ unless @k8s_cluster_name && @k8s_location
2209
+ @log.error "Failed to construct #{resource_type} resource locally." \
2210
+ ' Falling back to writing logs against' \
2211
+ " #{fallback_resource} resource.", error: e
2212
+ return
2213
+ end
2214
+ constructed_resource = Google::Apis::LoggingV2::MonitoredResource.new(
2215
+ type: resource_type,
2216
+ labels: labels)
2217
+ @log.debug("Constructed #{resource_type} resource locally:\n" \
2218
+ "#{constructed_resource.inspect}")
2237
2219
  constructed_resource
2238
- rescue StandardError => e
2239
- @log.error 'Failed to construct "k8s_node" resource locally. Falling' \
2240
- ' back to writing logs against instance resource.', error: e
2241
- # Fall back to default instance resource.
2242
- return
2243
- end
2244
-
2245
- # Only retrieve cluster name once since it's not changing for this
2246
- # agent instance's life time.
2247
- # Throw an error if failed to retrieve the cluster name.
2248
- def retrieve_k8s_cluster_name
2249
- @k8s_cluster_name ||= fetch_gce_metadata(
2250
- 'instance/attributes/cluster-name')
2251
- end
2252
-
2253
- # Only retrieve location once since it is the location of K8s Master which
2254
- # is not changing for this agent instance's life time.
2255
- # Throw an error if neither endpoint is available.
2256
- def retrieve_k8s_location
2257
- @k8s_location ||= fetch_gce_metadata(
2258
- 'instance/attributes/cluster-location')
2259
2220
  end
2260
2221
 
2261
2222
  def ensure_array(value)
@@ -1311,113 +1311,115 @@ module BaseTest
1311
1311
  # When enable_metadata_agent is false.
1312
1312
  {
1313
1313
  enable_metadata_agent: false,
1314
- set_up_metadata_agent_stub: false,
1315
- set_up_k8s_stub: false,
1314
+ setup_metadata_agent_stub: false,
1315
+ setup_k8s_stub: false,
1316
1316
  log_entry: k8s_container_log_entry(log_entry(0)),
1317
1317
  expected_params: COMPUTE_PARAMS
1318
1318
  },
1319
1319
  {
1320
1320
  enable_metadata_agent: false,
1321
- set_up_metadata_agent_stub: true,
1322
- set_up_k8s_stub: false,
1321
+ setup_metadata_agent_stub: true,
1322
+ setup_k8s_stub: false,
1323
1323
  log_entry: k8s_container_log_entry(log_entry(0)),
1324
1324
  expected_params: COMPUTE_PARAMS
1325
1325
  },
1326
1326
  {
1327
1327
  enable_metadata_agent: false,
1328
- set_up_metadata_agent_stub: true,
1329
- set_up_k8s_stub: true,
1328
+ setup_metadata_agent_stub: true,
1329
+ setup_k8s_stub: true,
1330
1330
  log_entry: k8s_container_log_entry(log_entry(0)),
1331
1331
  expected_params: COMPUTE_PARAMS
1332
1332
  },
1333
1333
  {
1334
1334
  enable_metadata_agent: false,
1335
- set_up_metadata_agent_stub: false,
1336
- set_up_k8s_stub: true,
1335
+ setup_metadata_agent_stub: false,
1336
+ setup_k8s_stub: true,
1337
1337
  log_entry: k8s_container_log_entry(log_entry(0)),
1338
1338
  expected_params: COMPUTE_PARAMS
1339
1339
  },
1340
1340
  # When enable_metadata_agent is true.
1341
1341
  {
1342
1342
  enable_metadata_agent: true,
1343
- set_up_metadata_agent_stub: false,
1344
- set_up_k8s_stub: false,
1343
+ setup_metadata_agent_stub: false,
1344
+ setup_k8s_stub: false,
1345
1345
  log_entry: k8s_container_log_entry(log_entry(0)),
1346
1346
  expected_params: COMPUTE_PARAMS
1347
1347
  },
1348
1348
  {
1349
1349
  enable_metadata_agent: true,
1350
- set_up_metadata_agent_stub: false,
1351
- set_up_k8s_stub: true,
1350
+ setup_metadata_agent_stub: false,
1351
+ setup_k8s_stub: true,
1352
1352
  log_entry: k8s_container_log_entry(log_entry(0)),
1353
1353
  expected_params: K8S_CONTAINER_PARAMS_FROM_LOCAL
1354
1354
  },
1355
1355
  {
1356
1356
  enable_metadata_agent: true,
1357
- set_up_metadata_agent_stub: true,
1358
- set_up_k8s_stub: false,
1357
+ setup_metadata_agent_stub: true,
1358
+ setup_k8s_stub: false,
1359
1359
  log_entry: k8s_container_log_entry(log_entry(0)),
1360
1360
  expected_params: K8S_CONTAINER_PARAMS
1361
1361
  },
1362
1362
  {
1363
1363
  enable_metadata_agent: true,
1364
- set_up_metadata_agent_stub: true,
1365
- set_up_k8s_stub: true,
1364
+ setup_metadata_agent_stub: true,
1365
+ setup_k8s_stub: true,
1366
1366
  log_entry: k8s_container_log_entry(log_entry(0)),
1367
1367
  expected_params: K8S_CONTAINER_PARAMS
1368
1368
  },
1369
1369
  # When local_resource_id is not present or does not match k8s regexes.
1370
1370
  {
1371
1371
  enable_metadata_agent: true,
1372
- set_up_metadata_agent_stub: true,
1373
- set_up_k8s_stub: true,
1372
+ setup_metadata_agent_stub: true,
1373
+ setup_k8s_stub: true,
1374
1374
  log_entry: k8s_container_log_entry(
1375
1375
  log_entry(0)).reject { |k, _| k == LOCAL_RESOURCE_ID_KEY },
1376
1376
  expected_params: COMPUTE_PARAMS
1377
1377
  },
1378
1378
  {
1379
1379
  enable_metadata_agent: true,
1380
- set_up_metadata_agent_stub: true,
1381
- set_up_k8s_stub: true,
1380
+ setup_metadata_agent_stub: true,
1381
+ setup_k8s_stub: true,
1382
1382
  log_entry: k8s_container_log_entry(
1383
1383
  log_entry(0),
1384
1384
  local_resource_id: RANDOM_LOCAL_RESOURCE_ID),
1385
+ # When 'kube-env' is present, "compute.googleapis.com/resource_name" is
1386
+ # not added.
1385
1387
  expected_params: COMPUTE_PARAMS
1386
1388
  },
1387
1389
  # Specific cases for k8s_node.
1388
1390
  {
1389
1391
  enable_metadata_agent: false,
1390
- set_up_metadata_agent_stub: true,
1391
- set_up_k8s_stub: true,
1392
+ setup_metadata_agent_stub: true,
1393
+ setup_k8s_stub: true,
1392
1394
  log_entry: k8s_node_log_entry(log_entry(0)),
1393
1395
  expected_params: COMPUTE_PARAMS
1394
1396
  },
1395
1397
  {
1396
1398
  enable_metadata_agent: true,
1397
- set_up_metadata_agent_stub: true,
1398
- set_up_k8s_stub: true,
1399
+ setup_metadata_agent_stub: true,
1400
+ setup_k8s_stub: true,
1399
1401
  log_entry: k8s_node_log_entry(log_entry(0)),
1400
1402
  expected_params: K8S_NODE_PARAMS
1401
1403
  },
1402
1404
  {
1403
1405
  enable_metadata_agent: true,
1404
- set_up_metadata_agent_stub: true,
1405
- set_up_k8s_stub: true,
1406
+ setup_metadata_agent_stub: true,
1407
+ setup_k8s_stub: true,
1406
1408
  log_entry: k8s_node_log_entry(log_entry(0)),
1407
1409
  expected_params: K8S_NODE_PARAMS
1408
1410
  }
1409
1411
  ].each do |test_params|
1410
1412
  new_stub_context do
1411
1413
  setup_gce_metadata_stubs
1412
- if test_params[:set_up_metadata_agent_stub]
1414
+ if test_params[:setup_metadata_agent_stub]
1413
1415
  setup_metadata_agent_stubs
1414
1416
  else
1415
1417
  setup_no_metadata_agent_stubs
1416
1418
  end
1417
- if test_params[:set_up_k8s_stub]
1418
- set_up_k8s_metadata_stubs
1419
+ if test_params[:setup_k8s_stub]
1420
+ setup_k8s_metadata_stubs
1419
1421
  else
1420
- set_up_no_k8s_metadata_stubs
1422
+ setup_no_k8s_metadata_stubs
1421
1423
  end
1422
1424
  setup_logging_stubs do
1423
1425
  config = if test_params[:enable_metadata_agent]
@@ -1603,7 +1605,7 @@ module BaseTest
1603
1605
  'KUBE_BEARER_TOKEN: AoQiMuwkNP2BMT0S')
1604
1606
  end
1605
1607
 
1606
- def set_up_k8s_metadata_stubs
1608
+ def setup_k8s_metadata_stubs
1607
1609
  stub_metadata_request(
1608
1610
  'instance/attributes/',
1609
1611
  "attribute1\ncluster-name\ncluster-location\nlast_attribute")
@@ -1611,12 +1613,14 @@ module BaseTest
1611
1613
  stub_metadata_request('instance/attributes/cluster-name', K8S_CLUSTER_NAME)
1612
1614
  end
1613
1615
 
1614
- def set_up_no_k8s_metadata_stubs
1615
- # Simulate an environment with no new k8s endpoints present.
1616
- stub_request(:get, %r{.*instance/attributes/cluster-location.*})
1617
- .to_raise(Errno::EHOSTUNREACH)
1618
- stub_request(:get, %r{.*instance/attributes/cluster-name.*})
1619
- .to_raise(Errno::EHOSTUNREACH)
1616
+ def setup_no_k8s_metadata_stubs
1617
+ ['cluster-location', 'cluster-name'].each do |metadata_name|
1618
+ stub_request(:get, %r{.*instance/attributes/#{metadata_name}.*})
1619
+ .to_return(status: 404,
1620
+ body: 'The requested URL /computeMetadata/v1/instance/' \
1621
+ "attributes/#{metadata_name} was not found on this" \
1622
+ ' server.')
1623
+ end
1620
1624
  end
1621
1625
 
1622
1626
  def setup_cloudfunctions_metadata_stubs
@@ -1750,6 +1754,7 @@ module BaseTest
1750
1754
  }
1751
1755
  end
1752
1756
 
1757
+ # TODO(qingling128): Temporary fallback for metadata agent restarts.
1753
1758
  # k8s resources.
1754
1759
 
1755
1760
  def k8s_container_log_entry(log,
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.18.pre.1
4
+ version: 0.6.18.pre.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Todd Derr