phet commented on code in PR #3667:
URL: https://github.com/apache/gobblin/pull/3667#discussion_r1160832023
##########
gobblin-runtime/src/main/java/org/apache/gobblin/runtime/AbstractJobLauncher.java:
##########
@@ -728,6 +729,39 @@ protected void
postProcessTaskStates(@SuppressWarnings("unused") List<TaskState>
*/
protected void postProcessJobState(JobState jobState) {
postProcessTaskStates(jobState.getTaskStates());
+ if (!GobblinMetrics.isEnabled(this.jobProps)) {
+ return;
+ }
+ List<DatasetTaskSummary> datasetTaskSummaries = new ArrayList<>();
+ Map<String, JobState.DatasetState> datasetStates =
this.jobContext.getDatasetStatesByUrns();
+ // Only process successful datasets unless configuration to process failed
datasets is set
+ for (JobState.DatasetState datasetState : datasetStates.values()) {
+ if (datasetState.getState() == JobState.RunningState.COMMITTED
+ || (datasetState.getState() == JobState.RunningState.FAILED &&
this.jobContext.getJobCommitPolicy() ==
JobCommitPolicy.COMMIT_SUCCESSFUL_TASKS)) {
+ long totalBytesWritten = 0;
+ long totalRecordsWritten = 0;
+ for (TaskState taskState : datasetState.getTaskStates()) {
+ if ((taskState.getWorkingState() ==
WorkUnitState.WorkingState.COMMITTED
+ || PropertiesUtils.getPropAsBoolean(jobProps,
ConfigurationKeys.WRITER_COUNT_METRICS_FROM_FAILED_TASKS, "false"))
+ && taskState.contains(ConfigurationKeys.WRITER_BYTES_WRITTEN)
+ && taskState.contains(ConfigurationKeys.WRITER_RECORDS_WRITTEN))
{
+ totalBytesWritten +=
taskState.getPropAsLong(ConfigurationKeys.WRITER_BYTES_WRITTEN);
Review Comment:
is it truly necessary to check `contains` before getting? can't we just
get, while supplying the default of `0L`?
... or are you concerned one but not the other could be set and wanting to
inhibit counting just one in isolation? if so, add a comment for maintainers
##########
gobblin-runtime/src/main/java/org/apache/gobblin/runtime/AbstractJobLauncher.java:
##########
@@ -728,6 +729,39 @@ protected void
postProcessTaskStates(@SuppressWarnings("unused") List<TaskState>
*/
protected void postProcessJobState(JobState jobState) {
postProcessTaskStates(jobState.getTaskStates());
+ if (!GobblinMetrics.isEnabled(this.jobProps)) {
+ return;
+ }
+ List<DatasetTaskSummary> datasetTaskSummaries = new ArrayList<>();
+ Map<String, JobState.DatasetState> datasetStates =
this.jobContext.getDatasetStatesByUrns();
+ // Only process successful datasets unless configuration to process failed
datasets is set
+ for (JobState.DatasetState datasetState : datasetStates.values()) {
+ if (datasetState.getState() == JobState.RunningState.COMMITTED
+ || (datasetState.getState() == JobState.RunningState.FAILED &&
this.jobContext.getJobCommitPolicy() ==
JobCommitPolicy.COMMIT_SUCCESSFUL_TASKS)) {
+ long totalBytesWritten = 0;
+ long totalRecordsWritten = 0;
+ for (TaskState taskState : datasetState.getTaskStates()) {
+ if ((taskState.getWorkingState() ==
WorkUnitState.WorkingState.COMMITTED
+ || PropertiesUtils.getPropAsBoolean(jobProps,
ConfigurationKeys.WRITER_COUNT_METRICS_FROM_FAILED_TASKS, "false"))
Review Comment:
not sure how many iterations we might expect (esp. since only non-commit
case), but as a general principle: this reaches into the props inside an inner
loop, to pull out a value that's unchanged during execution. best practice
would be to read just once at the top.
##########
gobblin-runtime/src/main/java/org/apache/gobblin/runtime/DatasetTaskSummary.java:
##########
@@ -0,0 +1,46 @@
+/*
+ * 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.
+ */
+
+package org.apache.gobblin.runtime;
+
+/**
+ * A class returned by {@link org.apache.gobblin.runtime.SafeDatasetCommit} to
provide metrics for the dataset
+ * that can be reported as a single event in the commit phase.
+ */
+public class DatasetTaskSummary {
+ private final String datasetUrn;
+ private final long recordsWritten;
+ private final long bytesWritten;
Review Comment:
what about `lombok.Data`... wouldn't that create a POJO just like what's
here?
##########
gobblin-runtime/src/main/java/org/apache/gobblin/runtime/DatasetTaskSummary.java:
##########
@@ -0,0 +1,46 @@
+/*
+ * 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.
+ */
+
+package org.apache.gobblin.runtime;
+
+/**
+ * A class returned by {@link org.apache.gobblin.runtime.SafeDatasetCommit} to
provide metrics for the dataset
+ * that can be reported as a single event in the commit phase.
+ */
+public class DatasetTaskSummary {
Review Comment:
from the perspective of those reading these metrics, it would be nice to
know whether the count reflects what's committed or a failure. maybe a boolean?
(I'm presuming in the case of `COMMIT_SUCCESSFUL_TASKS` that the two could
be comingled)
##########
gobblin-service/src/main/java/org/apache/gobblin/service/monitoring/GaaSObservabilityEventProducer.java:
##########
@@ -93,6 +99,12 @@ private GaaSObservabilityEventExperimental
createGaaSObservabilityEvent(final St
Long jobOrchestratedTime =
jobState.contains(TimingEvent.JOB_ORCHESTRATED_TIME) ?
jobState.getPropAsLong(TimingEvent.JOB_ORCHESTRATED_TIME) : null;
Long jobPlanningPhaseStartTime =
jobState.contains(TimingEvent.WORKUNIT_PLAN_START_TIME) ?
jobState.getPropAsLong(TimingEvent.WORKUNIT_PLAN_START_TIME) : null;
Long jobPlanningPhaseEndTime =
jobState.contains(TimingEvent.WORKUNIT_PLAN_END_TIME) ?
jobState.getPropAsLong(TimingEvent.WORKUNIT_PLAN_END_TIME) : null;
+ Type datasetTaskSummaryType = new
TypeToken<ArrayList<DatasetTaskSummary>>(){}.getType();
+ List<DatasetTaskSummary> datasetTaskSummaries =
jobState.contains(TimingEvent.DATASET_TASK_SUMMARIES) ?
+
GsonUtils.GSON_WITH_DATE_HANDLING.fromJson(jobState.getProp(TimingEvent.DATASET_TASK_SUMMARIES),
datasetTaskSummaryType) : null;
+ List<DatasetMetric> datasetMetrics = datasetTaskSummaries != null ?
datasetTaskSummaries.stream().map(summary ->
+ new DatasetMetric(summary.getDatasetUrn(), summary.getBytesWritten(),
summary.getRecordsWritten())).collect(Collectors.toList()) : null;
Review Comment:
any concern over tight coupling to instead encapsulate within a `static`
conversion like `DatasetTaskSummary::toDatasetMetric`?
(it seems preferable to me)
##########
gobblin-runtime/src/main/java/org/apache/gobblin/runtime/AbstractJobLauncher.java:
##########
@@ -728,6 +729,39 @@ protected void
postProcessTaskStates(@SuppressWarnings("unused") List<TaskState>
*/
protected void postProcessJobState(JobState jobState) {
postProcessTaskStates(jobState.getTaskStates());
+ if (!GobblinMetrics.isEnabled(this.jobProps)) {
+ return;
+ }
+ List<DatasetTaskSummary> datasetTaskSummaries = new ArrayList<>();
+ Map<String, JobState.DatasetState> datasetStates =
this.jobContext.getDatasetStatesByUrns();
+ // Only process successful datasets unless configuration to process failed
datasets is set
+ for (JobState.DatasetState datasetState : datasetStates.values()) {
+ if (datasetState.getState() == JobState.RunningState.COMMITTED
+ || (datasetState.getState() == JobState.RunningState.FAILED &&
this.jobContext.getJobCommitPolicy() ==
JobCommitPolicy.COMMIT_SUCCESSFUL_TASKS)) {
+ long totalBytesWritten = 0;
+ long totalRecordsWritten = 0;
+ for (TaskState taskState : datasetState.getTaskStates()) {
+ if ((taskState.getWorkingState() ==
WorkUnitState.WorkingState.COMMITTED
+ || PropertiesUtils.getPropAsBoolean(jobProps,
ConfigurationKeys.WRITER_COUNT_METRICS_FROM_FAILED_TASKS, "false"))
+ && taskState.contains(ConfigurationKeys.WRITER_BYTES_WRITTEN)
+ && taskState.contains(ConfigurationKeys.WRITER_RECORDS_WRITTEN))
{
+ totalBytesWritten +=
taskState.getPropAsLong(ConfigurationKeys.WRITER_BYTES_WRITTEN);
+ totalRecordsWritten +=
taskState.getPropAsLong(ConfigurationKeys.WRITER_RECORDS_WRITTEN);
+ }
+ }
+ LOG.info("Reporting that " + totalRecordsWritten + " records and " +
totalBytesWritten + " bytes were written for " + datasetState.getDatasetUrn());
Review Comment:
I suggest a more parseable, more "grep-able" and less conversational format
in case we ever want to audit events against logging.
e.g.
```
"DatasetMetrics for '%s' - (records: %d; bytes: %d)"
```
##########
gobblin-service/src/test/java/org/apache/gobblin/service/monitoring/GaaSObservabilityProducerTest.java:
##########
@@ -58,6 +61,10 @@ public void
testCreateGaaSObservabilityEventWithFullMetadata() throws Exception
TroubleshooterUtils.getContextIdForJob(flowGroup, flowName,
flowExecutionId, jobName),
createTestIssue("issueSummary", "issueCode", IssueSeverity.INFO)
);
+ List<DatasetTaskSummary> summaries = new ArrayList<>();
+ summaries.add(new DatasetTaskSummary("/testFolder", 100, 1000));
+ summaries.add(new DatasetTaskSummary("/testFolder2", 1000, 10000));
Review Comment:
nit - since you both write and then re-read for verification, rather than
hard-coding the same constants in both places, I'd save aside each
`DatasetTaskSummary` here to be able to access from it down below when it comes
to verification
##########
gobblin-metrics-libs/gobblin-metrics-base/src/main/avro/GaaSObservabilityEventExperimental.avsc:
##########
@@ -188,6 +188,38 @@
}
}
]
- }]
+ },
+ {
+ "name": "datasetsWritten",
+ "type": [
+ "null",
+ {
+ "type": "array",
+ "items": {
+ "type": "record",
+ "name": "DatasetMetric",
+ "doc": "DatasetMetric contains bytes and records written by
Gobblin writers for the dataset URN.",
+ "fields": [
+ {
+ "name": "datasetUrn",
+ "type": "string",
+ "doc": "URN of the dataset"
+ },
+ {
+ "name": "bytesWritten",
+ "type": "long",
+ "doc": "Number of bytes written for the dataset"
Review Comment:
which jobs is this applicable to? e.g. could it work for retention-release?
what about for pulling record-by-record from a CRM system and writing a subset
of the records fields to a relational DB?
how to measure the number of bytes "written" to the DB... maybe approximate
from the char count of the stringified SQL statement?
(the questions I'm unclear on are probably worth anticipating from those
looking at the "doc" strings here)
##########
gobblin-metrics-libs/gobblin-metrics-base/src/main/avro/GaaSObservabilityEventExperimental.avsc:
##########
@@ -188,6 +188,38 @@
}
}
]
- }]
+ },
+ {
+ "name": "datasetsWritten",
+ "type": [
+ "null",
+ {
+ "type": "array",
+ "items": {
+ "type": "record",
+ "name": "DatasetMetric",
+ "doc": "DatasetMetric contains bytes and records written by
Gobblin writers for the dataset URN.",
+ "fields": [
+ {
+ "name": "datasetUrn",
+ "type": "string",
+ "doc": "URN of the dataset"
+ },
+ {
+ "name": "bytesWritten",
+ "type": "long",
+ "doc": "Number of bytes written for the dataset"
+ },
+ {
+ "name": "recordsWritten",
+ "type": "long",
+ "doc": "Number of records written for the dataset"
Review Comment:
when we say "records", would that be files in the case of `CopySource` /
distcp? if so, let's describe accordingly in the doc string... and possibly
even in the name (e.g. `entitiesWritten`)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]