Method: Common::Utils#determine_agent_level_monitored_resource_labels

Defined in:
lib/fluent/plugin/common.rb

#determine_agent_level_monitored_resource_labels(platform, type, vm_id, zone) ⇒ Object

Determine agent level monitored resource labels based on the resource type. Each resource type has its own labels that need to be filled in.

[View source]

278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
# File 'lib/fluent/plugin/common.rb', line 278

def determine_agent_level_monitored_resource_labels(
      platform, type, vm_id, zone)
  case type
  # GAE app.
  when APPENGINE_CONSTANTS[:resource_type]
    return {
      'module_id' =>
        (platform,
                           'instance/attributes/gae_backend_name'),
      'version_id' =>
        (platform,
                           'instance/attributes/gae_backend_version')
    }

  # GCE.
  when COMPUTE_CONSTANTS[:resource_type]
    raise "Cannot construct a #{type} resource without vm_id and zone" \
      unless vm_id && zone
    return {
      'instance_id' => vm_id,
      'zone' => zone
    }

  # GKE container.
  when GKE_CONSTANTS[:resource_type]
    raise "Cannot construct a #{type} resource without vm_id and zone" \
      unless vm_id && zone
    return {
      'instance_id' => vm_id,
      'zone' => zone,
      'cluster_name' =>
        (platform, 'instance/attributes/cluster-name')
    }

  # Cloud Dataproc.
  when DATAPROC_CONSTANTS[:resource_type]
    return {
      'cluster_uuid' =>
        (platform,
                           'instance/attributes/dataproc-cluster-uuid'),
      'cluster_name' =>
        (platform,
                           'instance/attributes/dataproc-cluster-name'),
      'region' =>
        (platform,
                           'instance/attributes/dataproc-region')
    }

  # EC2.
  when EC2_CONSTANTS[:resource_type]
    raise "Cannot construct a #{type} resource without vm_id and zone" \
      unless vm_id && zone
    labels = {
      'instance_id' => vm_id,
      'region' => zone
    }
    labels['aws_account'] = (platform)['accountId'] if
      (platform).key?('accountId')
    return labels
  end

  {}
rescue StandardError => e
  if [Platform::GCE, Platform::EC2].include?(platform)
    @log.error "Failed to set monitored resource labels for #{type}: ",
               error: e
  end
  {}
end