-
Notifications
You must be signed in to change notification settings - Fork 4.4k
[BEAM-11092] Add bigquery io request count metric, implementing HarnessMonitoringInfos and process_wide metrics #13217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,9 +52,12 @@ | |
| from apache_beam.internal.http_client import get_new_http | ||
| from apache_beam.internal.metrics.metric import MetricLogger | ||
| from apache_beam.internal.metrics.metric import Metrics | ||
| from apache_beam.internal.metrics.metric import ServiceCallMetric | ||
| from apache_beam.io.gcp import bigquery_avro_tools | ||
| from apache_beam.io.gcp import resource_identifiers | ||
| from apache_beam.io.gcp.bigquery_io_metadata import create_bigquery_io_metadata | ||
| from apache_beam.io.gcp.internal.clients import bigquery | ||
| from apache_beam.metrics import monitoring_infos | ||
| from apache_beam.options import value_provider | ||
| from apache_beam.options.pipeline_options import GoogleCloudOptions | ||
| from apache_beam.runners.dataflow.native_io import iobase as dataflow_io | ||
|
|
@@ -566,14 +569,43 @@ def _insert_all_rows( | |
| skipInvalidRows=skip_invalid_rows, | ||
| # TODO(silviuc): Should have an option for ignoreUnknownValues? | ||
| rows=rows)) | ||
|
|
||
| resource = resource_identifiers.BigQueryTable( | ||
| project_id, dataset_id, table_id) | ||
|
|
||
| labels = { | ||
| # TODO(ajamato): Add Ptransform label. | ||
| monitoring_infos.SERVICE_LABEL: 'BigQuery', | ||
| # Refer to any method which writes elements to BigQuery in batches | ||
| # as "BigQueryBatchWrite". I.e. storage API's insertAll, or future | ||
| # APIs introduced. | ||
| monitoring_infos.METHOD_LABEL: 'BigQueryBatchWrite', | ||
|
||
| monitoring_infos.RESOURCE_LABEL: resource, | ||
| monitoring_infos.BIGQUERY_PROJECT_ID_LABEL: project_id, | ||
| monitoring_infos.BIGQUERY_DATASET_LABEL: dataset_id, | ||
| monitoring_infos.BIGQUERY_TABLE_LABEL: table_id, | ||
| } | ||
| service_call_metric = ServiceCallMetric( | ||
| request_count_urn=monitoring_infos.API_REQUEST_COUNT_URN, | ||
| base_labels=labels) | ||
|
|
||
| started_millis = int(time.time() * 1000) | ||
| response = None | ||
| try: | ||
| response = self.client.tabledata.InsertAll(request) | ||
| # response.insertErrors is not [] if errors encountered. | ||
| if not response.insertErrors: | ||
| service_call_metric.call('ok') | ||
| for insert_error in response.insertErrors: | ||
| for error in insert_error.errors: | ||
| service_call_metric.call(error.reason) | ||
| except HttpError as e: | ||
| service_call_metric.call(e) | ||
| finally: | ||
| self._latency_histogram_metric.update( | ||
| int(time.time() * 1000) - started_millis) | ||
| return not response.insertErrors, response.insertErrors | ||
| if response: | ||
| return not response.insertErrors, response.insertErrors | ||
| return False, [] | ||
|
|
||
| @retry.with_exponential_backoff( | ||
| num_retries=MAX_RETRIES, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| # | ||
| # Licensed to the Apache Software Foundation (ASF) under one or more | ||
| # contributor license agreements. See the NOTICE file distributed with | ||
| # this work for additional information regarding copyright ownership. | ||
| # The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| # (the "License"); you may not use this file except in compliance with | ||
| # the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # | ||
|
|
||
| """Helper functions to generate resource labels strings for GCP entitites | ||
|
|
||
| These can be used on MonitoringInfo 'resource' labels. | ||
|
|
||
| See example entities: | ||
| https://s.apache.org/beam-gcp-debuggability | ||
|
|
||
| For GCP entities, populate the RESOURCE label with the aip.dev/122 format: | ||
| https://google.aip.dev/122 | ||
|
|
||
| If an official GCP format does not exist, try to use the following format. | ||
| //whatever.googleapis.com/parents/{parentId}/whatevers/{whateverId} | ||
| """ | ||
|
|
||
|
|
||
| def BigQueryTable(project_id, dataset_id, table_id): | ||
| return '//bigquery.googleapis.com/projects/%s/datasets/%s/tables/%s' % ( | ||
| project_id, dataset_id, table_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fyi - from now on, you can use type hints directly, not as comments (no need to change anything atm)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ack