
    h                     D   d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZ d	d
dZ e	j                  e	j                  j                  e	j                  j                   e	j                  j"                         G d de	j$                               Zee_        y)z!'logging metrics create' command.    )absolute_import)division)unicode_literals)util)arg_parsers)base)logz          Create a logs-based metric to count the number of log entries that
          match a filter expression. Logs-based metrics can also be used to
          extract values from logs and create a distribution of the values.
      a            To create a metric that counts the number of log entries with a
          severity level higher than WARNING, run:

            $ {command} high_severity_count --description="Number of high severity log entries" --log-filter="severity > WARNING"

          Detailed information about filters can be found at:
          [](https://cloud.google.com/logging/docs/view/logging-query-language)

          To create a metric that uses advanced features like distribution or
          user-defined labels, run:

            $ {command} my_metric --config-from-file=$PATH_TO_FILE

          The config file can be in YAML or JSON format. Detailed information
          about how to configure metrics can be found at: [](https://cloud.google.com/logging/docs/reference/v2/rest/v2/projects.metrics#LogMetric).

          To create a bucket log-based metric, run:

            $ {command} my_bucket_metric --description="DESCRIPTION" --log-filter="LOG_FILTER" --bucket-name="BUCKET_NAME"
      )DESCRIPTIONEXAMPLESc                   &    e Zd ZdZed        Zd Zy)CreatezCreate a logs-based metric.c                 8   | j                  dd       | j                  ddd      }|j                  d      }|j                  ddd	
       |j                  ddd
       |j                  dd       |j                  ddt        j                                y)z Register flags for this command.metric_namezThe name of the new metric.)helpzData about the new metric.T)r   mutexrequiredzCA group of arguments to specify simple counter logs-based metrics. z--descriptionzThe metric's description.)r   r   z--log-filterzThe metric's filter expression.z--bucket-namez4The Log Bucket name which owns the log-based metric.z--config-from-filezIA path to a YAML or JSON file specifying the logs-based metric to create.)r   typeN)add_argumentadd_argument_groupr   FileContents)parserconfig_grouplegacy_mode_groups      %lib/surface/logging/metrics/create.pyArgszCreate.Args@   s     ,IJ,,2N376: - .L %77 8  ""$) # + ""/ # 1 ""C # E 2%G#.#;#;#=  ?    c                    t        j                         }t        j                  |j                  |j                  |j
                  |j                  |j                        }|j                  t        j                         |      }t        j                         j                  j                  |      }t        j                  |j                         |S )zThis is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      The created metric.
    )r   description
log_filterbucket_namedata)parent	logMetric)r   GetMessagesCreateLogMetricr   r   r   r    config_from_file#LoggingProjectsMetricsCreateRequestGetCurrentProjectParent	GetClientprojects_metricsr   r	   CreatedResource)selfargsmessages
new_metricrequestresults         r   Runz
Create.RunY   s     !H%%$$$$??$$""$J ::++- ; EG^^..55g>F(()Mr   N)__name__
__module____qualname____doc__staticmethodr   r2    r   r   r   r   ;   s     $? ?0r   r   N)r6   
__future__r   r   r   googlecloudsdk.api_lib.loggingr   googlecloudsdk.callioper   r   googlecloudsdk.corer	   DETAILED_HELPReleaseTracksReleaseTrackGABETAALPHACreateCommandr   detailed_helpr8   r   r   <module>rE      s     ( &  ' / / ( #	
	
@ D%%(($*;*;*@*@%%++-2T 2-2j % r   