示例#1
0
    def verify_write_call_metric(self, project_id, instance_id, table_id,
                                 status, count):
        """Check if a metric was recorded for the Datastore IO write API call."""
        process_wide_monitoring_infos = list(
            MetricsEnvironment.process_wide_container(
            ).to_runner_api_monitoring_infos(None).values())
        resource = resource_identifiers.BigtableTable(project_id, instance_id,
                                                      table_id)
        labels = {
            monitoring_infos.SERVICE_LABEL: 'BigTable',
            monitoring_infos.METHOD_LABEL: 'google.bigtable.v2.MutateRows',
            monitoring_infos.RESOURCE_LABEL: resource,
            monitoring_infos.BIGTABLE_PROJECT_ID_LABEL: project_id,
            monitoring_infos.INSTANCE_ID_LABEL: instance_id,
            monitoring_infos.TABLE_ID_LABEL: table_id,
            monitoring_infos.STATUS_LABEL: status
        }
        expected_mi = monitoring_infos.int64_counter(
            monitoring_infos.API_REQUEST_COUNT_URN, count, labels=labels)
        expected_mi.ClearField("start_time")

        found = False
        for actual_mi in process_wide_monitoring_infos:
            actual_mi.ClearField("start_time")
            if expected_mi == actual_mi:
                found = True
                break
        self.assertTrue(
            found, "Did not find write call metric with status: %s" % status)
示例#2
0
 def start_service_call_metrics(self, project_id, instance_id, table_id):
   resource = resource_identifiers.BigtableTable(
       project_id, instance_id, table_id)
   labels = {
       monitoring_infos.SERVICE_LABEL: 'BigTable',
       # TODO(JIRA-11985): Add Ptransform label.
       monitoring_infos.METHOD_LABEL: 'google.bigtable.v2.MutateRows',
       monitoring_infos.RESOURCE_LABEL: resource,
       monitoring_infos.BIGTABLE_PROJECT_ID_LABEL: (
           self.beam_options['project_id']),
       monitoring_infos.INSTANCE_ID_LABEL: self.beam_options['instance_id'],
       monitoring_infos.TABLE_ID_LABEL: self.beam_options['table_id']
   }
   return ServiceCallMetric(
       request_count_urn=monitoring_infos.API_REQUEST_COUNT_URN,
       base_labels=labels)