-
Notifications
You must be signed in to change notification settings - Fork 86
[PLUGIN-869] Added execution metrics for BQ Pushdown jobs #929
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,11 +18,15 @@ | |
|
|
||
| import com.google.cloud.bigquery.BigQuery; | ||
| import com.google.cloud.bigquery.DatasetId; | ||
| import com.google.cloud.bigquery.Job; | ||
| import com.google.cloud.bigquery.JobStatistics; | ||
| import com.google.cloud.bigquery.QueryStage; | ||
| import com.google.cloud.bigquery.StandardTableDefinition; | ||
| import com.google.cloud.bigquery.Table; | ||
| import com.google.cloud.bigquery.TableDefinition; | ||
| import com.google.cloud.bigquery.TableId; | ||
| import com.google.cloud.bigquery.TableInfo; | ||
| import com.google.gson.Gson; | ||
| import io.cdap.cdap.api.data.schema.Schema; | ||
| import io.cdap.cdap.etl.api.engine.sql.SQLEngineException; | ||
| import io.cdap.cdap.etl.api.join.JoinCondition; | ||
|
|
@@ -41,6 +45,7 @@ | |
| import java.util.Map; | ||
| import java.util.UUID; | ||
| import java.util.concurrent.TimeUnit; | ||
| import java.util.stream.Collectors; | ||
| import javax.annotation.Nullable; | ||
|
|
||
| /** | ||
|
|
@@ -49,6 +54,7 @@ | |
| public class BigQuerySQLEngineUtils { | ||
|
|
||
| private static final Logger LOG = LoggerFactory.getLogger(BigQuerySQLEngineUtils.class); | ||
| private static final Gson GSON = new Gson(); | ||
|
|
||
| public static final String GCS_PATH_FORMAT = BigQuerySinkUtils.GS_PATH_FORMAT + "/%s"; | ||
| public static final String BQ_TABLE_NAME_FORMAT = "%s_%s"; | ||
|
|
@@ -218,7 +224,7 @@ public static void validateOnExpressionJoinCondition(JoinCondition.OnExpression | |
|
|
||
| /** | ||
| * Validates stages for a Join on Key operation | ||
| * | ||
| * <p> | ||
| * TODO: Update logic once BQ SQL engine joins support multiple outer join tables | ||
| * | ||
| * @param joinDefinition Join Definition to validate | ||
|
|
@@ -292,4 +298,98 @@ public static Map<String, String> getJobTags(String operation) { | |
| labels.put("pushdown_operation", operation); | ||
| return Collections.unmodifiableMap(labels); | ||
| } | ||
|
|
||
| /** | ||
| * Logs information about a BigQUery Job execution using a specified Logger instance | ||
| * | ||
| * @param job BigQuery Job | ||
| */ | ||
| public static void logJobMetrics(Job job) { | ||
| // Ensure job has statistics information | ||
| if (job.getStatistics() == null) { | ||
| LOG.warn("No statistics were found for BigQuery job {}", job.getJobId()); | ||
| } | ||
|
|
||
| String startTimeStr = getISODateTimeString(job.getStatistics().getStartTime()); | ||
| String endTimeStr = getISODateTimeString(job.getStatistics().getEndTime()); | ||
| String executionTimeStr = getExecutionTimeString(job.getStatistics().getStartTime(), | ||
| job.getStatistics().getEndTime()); | ||
|
|
||
| // Print detailed query statistics if available | ||
| if (job.getStatistics() instanceof JobStatistics.QueryStatistics) { | ||
| JobStatistics.QueryStatistics queryStatistics = (JobStatistics.QueryStatistics) job.getStatistics(); | ||
| LOG.info("Metrics for job {}:\n" + | ||
| " Start: {} ,\n" + | ||
| " End: {} ,\n" + | ||
| " Execution time: {} ,\n" + | ||
| " Processed Bytes: {} ,\n" + | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you also log |
||
| " Billed Bytes: {} ,\n" + | ||
| " Total Slot ms: {} ,\n" + | ||
| " Records per stage (read/write): {}", | ||
| job.getJobId().getJob(), | ||
| startTimeStr, | ||
| endTimeStr, | ||
| executionTimeStr, | ||
| queryStatistics.getTotalBytesProcessed(), | ||
| queryStatistics.getTotalBytesBilled(), | ||
| queryStatistics.getTotalSlotMs(), | ||
| getQueryStageRecordCounts(queryStatistics.getQueryPlan())); | ||
|
|
||
| if (LOG.isTraceEnabled()) { | ||
| LOG.trace("Additional Metrics for job {}:\n" + | ||
| " Query Plan: {} ,\n" + | ||
| " Query Timeline: {} \n", | ||
| job.getJobId().getJob(), | ||
| GSON.toJson(queryStatistics.getQueryPlan()), | ||
| GSON.toJson(queryStatistics.getTimeline())); | ||
| } | ||
|
|
||
| return; | ||
| } | ||
|
|
||
| // Print basic metrics | ||
| JobStatistics statistics = job.getStatistics(); | ||
| LOG.info("Metrics for job: {}\n" + | ||
| " Start: {} ,\n" + | ||
| " End: {} ,\n" + | ||
| " Execution time: {}", | ||
| job.getJobId().getJob(), | ||
| startTimeStr, | ||
| endTimeStr, | ||
| executionTimeStr); | ||
| } | ||
|
|
||
| private static String getISODateTimeString(Long epoch) { | ||
| if (epoch == null) { | ||
| return "N/A"; | ||
| } | ||
|
|
||
| return Instant.ofEpochMilli(epoch).toString(); | ||
| } | ||
|
|
||
| private static String getExecutionTimeString(Long startEpoch, Long endEpoch) { | ||
| if (startEpoch == null || endEpoch == null) { | ||
| return "N/A"; | ||
| } | ||
|
|
||
| return (endEpoch - startEpoch) + " ms"; | ||
| } | ||
|
|
||
| private static String getQueryStageRecordCounts(List<QueryStage> queryPlan) { | ||
| if (queryPlan == null || queryPlan.isEmpty()) { | ||
| return "N/A"; | ||
| } | ||
|
|
||
| return queryPlan.stream() | ||
| .map(qs -> formatRecordCount(qs.getRecordsRead()) + "/" + formatRecordCount(qs.getRecordsWritten())) | ||
| .collect(Collectors.joining(" , ", "[ ", " ]")); | ||
| } | ||
|
|
||
| private static String formatRecordCount(Long val) { | ||
| if (val == null) { | ||
| return "N/A"; | ||
| } | ||
|
|
||
| return val.toString(); | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
nit: is this intentional?