Ejemplo n.º 1
0
 def _query_metric(self, query_name):
   project_id = self._spanner_configuration.project
   resource = resource_identifiers.SpannerSqlQuery(project_id, query_name)
   labels = {
       **self.base_labels,
       monitoring_infos.RESOURCE_LABEL: resource,
       monitoring_infos.SPANNER_QUERY_NAME: query_name
   }
   service_call_metric = ServiceCallMetric(
       request_count_urn=monitoring_infos.API_REQUEST_COUNT_URN,
       base_labels=labels)
   return service_call_metric
Ejemplo n.º 2
0
  def verify_sql_read_call_metric(
      self, project, database, query_name, status, count):
    resource = resource_identifiers.SpannerSqlQuery(project, query_name)
    labels = {
        monitoring_infos.SERVICE_LABEL: 'Spanner',
        monitoring_infos.METHOD_LABEL: 'Read',
        monitoring_infos.SPANNER_PROJECT_ID: project,
        monitoring_infos.SPANNER_DATABASE_ID: database,
        monitoring_infos.RESOURCE_LABEL: resource,
        monitoring_infos.SPANNER_QUERY_NAME: query_name,
        monitoring_infos.STATUS_LABEL: status
    }

    metric_name = MetricName(
        None, None, urn=monitoring_infos.API_REQUEST_COUNT_URN, labels=labels)
    metric_value = MetricsEnvironment.process_wide_container().get_counter(
        metric_name).get_cumulative()

    self.assertEqual(metric_value, count)