lib/fluent/plugin/out_google_cloud.rb
# Constants for service names, resource types and etc.
Constants for service names, resource types and etc.
Constants for service names resource types and etc .
def configure(conf)
      super
      unless @logging_api_url == DEFAULT_LOGGING_API_URL || @use_grpc
        @log.warn 'Detected customized logging_api_url while use_grpc is not' \
                  ' enabled. Customized logging_api_url for the non-gRPC path' \
                  ' is not supported. The logging_api_url option will be' \
                  ' ignored.'
      end
      if @enable_metadata_agent
        @metadata_agent_url ||=
          if ENV[METADATA_AGENT_URL_ENV_VAR].to_s.empty?
            DEFAULT_METADATA_AGENT_URL
          else
            ENV[METADATA_AGENT_URL_ENV_VAR]
          end
      end
      if @enable_monitoring
        registry = Monitoring::MonitoringRegistryFactory.create @monitoring_type
        @successful_requests_count = registry.counter(
          :stackdriver_successful_requests_count,
          'A number of successful requests to the Stackdriver Logging API')
        @failed_requests_count = registry.counter(
          :stackdriver_failed_requests_count,
          'A number of failed requests to the Stackdriver Logging API,'\
            ' broken down by the error code')
        @ingested_entries_count = registry.counter(
          :stackdriver_ingested_entries_count,
          'A number of log entries ingested by Stackdriver Logging')
        @dropped_entries_count = registry.counter(
          :stackdriver_dropped_entries_count,
          'A number of log entries dropped by the Stackdriver output plugin')
        @retried_entries_count = registry.counter(
          :stackdriver_retried_entries_count,
          'The number of log entries that failed to be ingested by the'\
            ' Stackdriver output plugin due to a transient error and were'\
            ' retried')
        @ok_code = @use_grpc ? GRPC::Core::StatusCodes::OK : 200
      end
      unless @auth_method.nil? && @private_key_email.nil? &&
             @private_key_path.nil? && @private_key_passphrase.nil?
        extra = []
        extra << 'auth_method' unless @auth_method.nil?
        extra << 'private_key_email' unless @private_key_email.nil?
        extra << 'private_key_path' unless @private_key_path.nil?
        extra << 'private_key_passphrase' unless @private_key_passphrase.nil?
        raise Fluent::ConfigError,
              "#{PLUGIN_NAME} no longer supports auth_method.\n" \
              "Please remove configuration parameters: #{extra.join(' ')}"
      end
      set_regexp_patterns
      @platform = detect_platform
      ENV.delete(CREDENTIALS_PATH_ENV_VAR) if
        ENV[CREDENTIALS_PATH_ENV_VAR] == ''
      set_required_metadata_variables
      @resource ||= determine_agent_level_monitored_resource_via_legacy
      @tag_regexp_list = []
      if @resource.type == GKE_CONSTANTS[:resource_type]
        if fetch_gce_metadata('instance/attributes/'
                             ).split.include?('gcf_region')
          @gcf_region = fetch_gce_metadata('instance/attributes/gcf_region')
          @tag_regexp_list << [
            CLOUDFUNCTIONS_CONSTANTS[:resource_type],
            @compiled_cloudfunctions_tag_regexp
          ]
        end
        @tag_regexp_list << [
          GKE_CONSTANTS[:resource_type], @compiled_kubernetes_tag_regexp
        ]
      end
      @common_labels = determine_agent_level_common_labels
      @resource.freeze
      @resource.labels.freeze
      @common_labels.freeze
      if @use_grpc
        @construct_log_entry = method(:construct_log_entry_in_grpc_format)
        @write_request = method(:write_request_via_grpc)
      else
        @construct_log_entry = method(:construct_log_entry_in_rest_format)
        @write_request = method(:write_request_via_rest)
      end
      if [Platform::GCE, Platform::EC2].include?(@platform)
        @log.info 'Logs viewer address: https://console.cloud.google.com/logs/',
                  "viewer?project=#{@project_id}&resource=#{@resource.type}/",
                  "instance_id/#{@vm_id}"
      end
    end
def configure ( conf ) super unless @logging_api_url == DEFAULT_LOGGING_API_URL || @use_grpc @log . warn 'Detected customized logging_api_url while use_grpc is not' ' enabled. Customized logging_api_url for the non-gRPC path' ' is not supported. The logging_api_url option will be' ' ignored.' end if @enable_metadata_agent @metadata_agent_url ||= if ENV [ METADATA_AGENT_URL_ENV_VAR ] . to_s . empty? DEFAULT_METADATA_AGENT_URL else ENV [ METADATA_AGENT_URL_ENV_VAR ] end end if @enable_monitoring registry = Monitoring :: MonitoringRegistryFactory . create @monitoring_type @successful_requests_count = registry . counter ( :stackdriver_successful_requests_count , 'A number of successful requests to the Stackdriver Logging API' ) @failed_requests_count = registry . counter ( :stackdriver_failed_requests_count , 'A number of failed requests to the Stackdriver Logging API,' ' broken down by the error code' ) @ingested_entries_count = registry . counter ( :stackdriver_ingested_entries_count , 'A number of log entries ingested by Stackdriver Logging' ) @dropped_entries_count = registry . counter ( :stackdriver_dropped_entries_count , 'A number of log entries dropped by the Stackdriver output plugin' ) @retried_entries_count = registry . counter ( :stackdriver_retried_entries_count , 'The number of log entries that failed to be ingested by the' ' Stackdriver output plugin due to a transient error and were' ' retried' ) @ok_code = @use_grpc ? GRPC :: Core :: StatusCodes :: OK : 200 end unless @auth_method . nil? && @private_key_email . nil? && @private_key_path . nil? && @private_key_passphrase . nil? extra = [ ] extra << 'auth_method' unless @auth_method . nil? extra << 'private_key_email' unless @private_key_email . nil? extra << 'private_key_path' unless @private_key_path . nil? extra << 'private_key_passphrase' unless @private_key_passphrase . nil? raise Fluent :: ConfigError , "#{PLUGIN_NAME} no longer supports auth_method.\n" "Please remove configuration parameters: #{extra.join(' ')}" end set_regexp_patterns @platform = detect_platform ENV . delete ( CREDENTIALS_PATH_ENV_VAR ) if ENV [ CREDENTIALS_PATH_ENV_VAR ] == '' set_required_metadata_variables @resource ||= determine_agent_level_monitored_resource_via_legacy @tag_regexp_list = [ ] if @resource . type == GKE_CONSTANTS [ :resource_type ] if fetch_gce_metadata ( 'instance/attributes/' ) . split . include? ( 'gcf_region' ) @gcf_region = fetch_gce_metadata ( 'instance/attributes/gcf_region' ) @tag_regexp_list << [ CLOUDFUNCTIONS_CONSTANTS [ :resource_type ] , @compiled_cloudfunctions_tag_regexp ] end @tag_regexp_list << [ GKE_CONSTANTS [ :resource_type ] , @compiled_kubernetes_tag_regexp ] end @common_labels = determine_agent_level_common_labels @resource . freeze @resource . labels . freeze @common_labels . freeze if @use_grpc @construct_log_entry = method ( :construct_log_entry_in_grpc_format ) @write_request = method ( :write_request_via_grpc ) else @construct_log_entry = method ( :construct_log_entry_in_rest_format ) @write_request = method ( :write_request_via_rest ) end if [ Platform :: GCE , Platform :: EC2 ] . include? ( @platform ) @log . info 'Logs viewer address: https://console.cloud.google.com/logs/' , "viewer?project=#{@project_id}&resource=#{@resource.type}/" , "instance_id/#{@vm_id}" end end
Constants for service names, resource types and etc.
Constants for service names resource types and etc .
# TODO(qingling128): Remove this warning after the support is added. Also # remove the comment in the description of this configuration. # 1. If @metadata_agent_url is customized (aka not nil), use that. # 2. Otherwise check the presence of the environment variable #    STACKDRIVER_METADATA_AGENT_URL and use that if set. # 3. Fall back to the default if neither is set. # Convert to string to capture empty string. # If monitoring is enabled, register metrics in the default registry # and store metric objects for future use. # Alert on old authentication configuration. # Treat an empty setting of the credentials file path environment variable # as unset. This way the googleauth lib could fetch the credentials # following the fallback path. # Set required variables: @project_id, @vm_id, @vm_name and @zone. # Retrieve monitored resource. # Fail over to retrieve monitored resource via the legacy path if we fail # to get it from Metadata Agent. # Set regexp that we should match tags against later on. Using a list # instead of a map to ensure order. For example, tags will be matched # against Cloud Functions first, then GKE. # We only support Cloud Functions logs for GKE right now. # Fetch this info and store it to avoid recurring # metadata server calls. # Determine the common labels that should be added to all log entries # processed by this logging agent. # The resource and labels are now set up; ensure they can't be modified # without first duping them. # Log an informational message containing the Logs viewer URL
conf