Exemple #1
0
    def Run(self, args):
        """This 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 updated metric.
    """
        # Calling the API's Update method on a non-existing metric creates it.
        # Make sure the metric exists so we don't accidentally create it.
        metric = util.GetClient().projects_metrics.Get(util.GetMessages(
        ).LoggingProjectsMetricsGetRequest(metricName=util.CreateResourceName(
            util.GetCurrentProjectParent(), 'metrics', args.metric_name)))

        updated_metric = util.UpdateLogMetric(metric,
                                              description=args.description,
                                              log_filter=args.log_filter)

        result = util.GetClient().projects_metrics.Update(
            util.GetMessages().LoggingProjectsMetricsUpdateRequest(
                metricName=util.CreateResourceName(
                    util.GetCurrentProjectParent(), 'metrics',
                    args.metric_name),
                logMetric=updated_metric))
        log.UpdatedResource(args.metric_name)
        return result
Exemple #2
0
 def YieldAllSinks(self, project):
     """Yield all log and log service sinks from the specified project."""
     client = util.GetClientV1()
     messages = util.GetMessagesV1()
     # First get all the log sinks.
     response = list_pager.YieldFromList(
         client.projects_logs,
         messages.LoggingProjectsLogsListRequest(projectsId=project),
         field='logs',
         batch_size=None,
         batch_size_attribute='pageSize')
     for log in response:
         # We need only the base log name, not the full resource uri.
         log_id = util.ExtractLogId(log.name)
         for typed_sink in self.ListLogSinks(project, log_id):
             yield typed_sink
     # Now get all the log service sinks.
     response = list_pager.YieldFromList(
         client.projects_logServices,
         messages.LoggingProjectsLogServicesListRequest(projectsId=project),
         field='logServices',
         batch_size=None,
         batch_size_attribute='pageSize')
     for service in response:
         # In contrast, service.name correctly contains only the name.
         for typed_sink in self.ListLogServiceSinks(project, service.name):
             yield typed_sink
     # Lastly, get all v2 sinks.
     for typed_sink in self.ListSinks(util.GetCurrentProjectParent()):
         yield typed_sink
Exemple #3
0
    def Run(self, args):
        """This 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 updated metric.
    """
        # One of the flags is required to update the metric.
        if not (args.description or args.log_filter):
            raise exceptions.MinimumArgumentException(
                ['--description', '--log-filter'])

        # Calling the API's Update method on a non-existing metric creates it.
        # Make sure the metric exists so we don't accidentally create it.
        metric = util.GetClient().projects_metrics.Get(util.GetMessages(
        ).LoggingProjectsMetricsGetRequest(metricName=util.CreateResourceName(
            util.GetCurrentProjectParent(), 'metrics', args.metric_name)))

        if args.description:
            metric_description = args.description
        else:
            metric_description = metric.description
        if args.log_filter:
            metric_filter = args.log_filter
        else:
            metric_filter = metric.filter

        updated_metric = util.GetMessages().LogMetric(
            name=args.metric_name,
            description=metric_description,
            filter=metric_filter)

        result = util.GetClient().projects_metrics.Update(
            util.GetMessages().LoggingProjectsMetricsUpdateRequest(
                metricName=util.CreateResourceName(
                    util.GetCurrentProjectParent(), 'metrics',
                    args.metric_name),
                logMetric=updated_metric))
        log.UpdatedResource(args.metric_name)
        return result
Exemple #4
0
    def Run(self, args):
        """This 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 specified metric with its description and configured filter.
    """
        return util.GetClient().projects_metrics.Get(util.GetMessages(
        ).LoggingProjectsMetricsGetRequest(metricName=util.CreateResourceName(
            util.GetCurrentProjectParent(), 'metrics', args.metric_name)))
Exemple #5
0
  def Run(self, args):
    """This 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.
    """
    console_io.PromptContinue(
        'Really delete metric [%s]?' % args.metric_name, cancel_on_no=True)

    util.GetClient().projects_metrics.Delete(
        util.GetMessages().LoggingProjectsMetricsDeleteRequest(
            metricName=util.CreateResourceName(
                util.GetCurrentProjectParent(), 'metrics', args.metric_name)))
    log.DeletedResource(args.metric_name)
Exemple #6
0
    def Run(self, args):
        """This 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.
    """
        if not console_io.PromptContinue(
                'Really delete all log entries from [%s]?' % args.log_name):
            raise exceptions.ToolException('action canceled by user')

        util.GetClient().projects_logs.Delete(
            util.GetMessages().LoggingProjectsLogsDeleteRequest(
                logName=util.CreateLogResourceName(
                    util.GetCurrentProjectParent(), args.log_name)))
        log.DeletedResource(args.log_name)
Exemple #7
0
  def Run(self, args):
    """This 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 list of metrics.
    """
    request = util.GetMessages().LoggingProjectsMetricsListRequest(
        parent=util.GetCurrentProjectParent())

    return list_pager.YieldFromList(
        util.GetClient().projects_metrics, request, field='metrics',
        limit=args.limit, batch_size=None, batch_size_attribute='pageSize')
Exemple #8
0
    def Run(self, args):
        """This 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.
    """
        messages = util.GetMessages()
        new_metric = messages.LogMetric(name=args.metric_name,
                                        description=args.description,
                                        filter=args.log_filter)

        result = util.GetClient().projects_metrics.Create(
            messages.LoggingProjectsMetricsCreateRequest(
                parent=util.GetCurrentProjectParent(), logMetric=new_metric))
        log.CreatedResource(args.metric_name)
        return result