lib/fluent/plugin/common.rb
# Determine agent level monitored resource labels based on the resource
# type. Each resource type has its own labels that need to be filled in.
Determine agent level monitored resource labels based on the resource
type. Each resource type has its own labels that need to be filled in.
Determine agent level monitored resource labels based on the resource type . Each resource type has its own labels that need to be filled in .
def determine_agent_level_monitored_resource_labels(
          platform, type, vm_id, zone)
      case type
      when APPENGINE_CONSTANTS[:resource_type]
        return {
          'module_id' =>
            fetch_gce_metadata(platform,
                               'instance/attributes/gae_backend_name'),
          'version_id' =>
            fetch_gce_metadata(platform,
                               'instance/attributes/gae_backend_version')
        }
      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
        }
      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' =>
            fetch_gce_metadata(platform, 'instance/attributes/cluster-name')
        }
      when DATAPROC_CONSTANTS[:resource_type]
        return {
          'cluster_uuid' =>
            fetch_gce_metadata(platform,
                               'instance/attributes/dataproc-cluster-uuid'),
          'cluster_name' =>
            fetch_gce_metadata(platform,
                               'instance/attributes/dataproc-cluster-name'),
          'region' =>
            fetch_gce_metadata(platform,
                               'instance/attributes/dataproc-region')
        }
      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'] = ec2_metadata(platform)['accountId'] if
          ec2_metadata(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
def determine_agent_level_monitored_resource_labels ( platform , type , vm_id , zone ) case type when APPENGINE_CONSTANTS [ :resource_type ] return { 'module_id' => fetch_gce_metadata ( platform , 'instance/attributes/gae_backend_name' ) , 'version_id' => fetch_gce_metadata ( platform , 'instance/attributes/gae_backend_version' ) } 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 } 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' => fetch_gce_metadata ( platform , 'instance/attributes/cluster-name' ) } when DATAPROC_CONSTANTS [ :resource_type ] return { 'cluster_uuid' => fetch_gce_metadata ( platform , 'instance/attributes/dataproc-cluster-uuid' ) , 'cluster_name' => fetch_gce_metadata ( platform , 'instance/attributes/dataproc-cluster-name' ) , 'region' => fetch_gce_metadata ( platform , 'instance/attributes/dataproc-region' ) } 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' ] = ec2_metadata ( platform ) [ 'accountId' ] if ec2_metadata ( 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
Determine agent level monitored resource labels based on the resource
type.
Determine agent level monitored resource labels based on the resource type .
# GAE app. # GCE. # GKE container. # Cloud Dataproc. # EC2.
platform
<not_specific>
type
<not_specific>
vm_id
<not_specific>
zone
<not_specific>