-
Notifications
You must be signed in to change notification settings - Fork 63
feat: Add individual task telemetry to dumper system #949
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 4 commits
6e8bdac
8316a20
5136f05
541f5cb
17b84ab
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 |
|---|---|---|
|
|
@@ -25,6 +25,7 @@ | |
| import com.google.edwmigration.dumper.application.dumper.io.OutputHandle; | ||
| import com.google.edwmigration.dumper.application.dumper.io.OutputHandle.WriteMode; | ||
| import com.google.edwmigration.dumper.application.dumper.io.OutputHandleFactory; | ||
| import com.google.edwmigration.dumper.application.dumper.metrics.TaskRunMetrics; | ||
| import com.google.edwmigration.dumper.application.dumper.task.Task; | ||
| import com.google.edwmigration.dumper.application.dumper.task.TaskGroup; | ||
| import com.google.edwmigration.dumper.application.dumper.task.TaskRunContext; | ||
|
|
@@ -35,7 +36,9 @@ | |
| import java.nio.charset.StandardCharsets; | ||
| import java.sql.SQLException; | ||
| import java.time.Duration; | ||
| import java.time.Instant; | ||
| import java.util.Arrays; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.concurrent.atomic.AtomicInteger; | ||
| import javax.annotation.CheckForNull; | ||
|
|
@@ -56,17 +59,21 @@ public class TasksRunner implements TaskRunContextOps { | |
| private final TaskRunContext context; | ||
| private final TaskSetState.Impl state; | ||
| private final List<Task<?>> tasks; | ||
| private final TelemetryProcessor telemetryProcessor; | ||
| private final HashMap<String, String> MetricToErrorMap = new HashMap<>(); | ||
|
|
||
| public TasksRunner( | ||
| OutputHandleFactory sinkFactory, | ||
| Handle handle, | ||
| int threadPoolSize, | ||
| @Nonnull TaskSetState.Impl state, | ||
| List<Task<?>> tasks, | ||
| ConnectorArguments arguments) { | ||
| ConnectorArguments arguments, | ||
| TelemetryProcessor telemetryProcessor) { | ||
| context = createContext(sinkFactory, handle, threadPoolSize, arguments); | ||
| this.state = state; | ||
| this.tasks = tasks; | ||
| this.telemetryProcessor = telemetryProcessor; | ||
| totalNumberOfTasks = countTasks(tasks); | ||
| stopwatch = Stopwatch.createStarted(); | ||
| numberOfCompletedTasks = new AtomicInteger(); | ||
|
|
@@ -93,7 +100,13 @@ public <T> T runChildTask(@Nonnull Task<T> task) throws MetadataDumperUsageExcep | |
|
|
||
| public void run() throws MetadataDumperUsageException { | ||
| for (Task<?> task : tasks) { | ||
| Instant taskStartTime = Instant.now(); | ||
kaxuna marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| handleTask(task); | ||
|
|
||
| Instant taskEndTime = Instant.now(); | ||
| TaskState finalState = getTaskState(task); | ||
| addTaskTelemetry(task.getName(), taskStartTime, taskEndTime, finalState); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -168,6 +181,7 @@ private <T> T runTask(Task<T> task) throws MetadataDumperUsageException { | |
| else if (!task.handleException(e)) | ||
| logger.warn("Task failed: {}: {}", task, e.getMessage(), e); | ||
| state.setTaskException(task, TaskState.FAILED, e); | ||
| MetricToErrorMap.put(task.getName(), e.getMessage()); | ||
kaxuna marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| try { | ||
| OutputHandle sink = context.newOutputFileHandle(task.getTargetPath() + ".exception.txt"); | ||
| sink.asCharSink(StandardCharsets.UTF_8, WriteMode.CREATE_TRUNCATE) | ||
|
|
@@ -178,6 +192,7 @@ else if (!task.handleException(e)) | |
| String.valueOf(new DumperDiagnosticQuery(e).call()))); | ||
| } catch (Exception f) { | ||
| logger.warn("Exception-recorder failed: {}", f.getMessage(), f); | ||
| MetricToErrorMap.put(task.getName(), f.getMessage()); | ||
| } | ||
| } | ||
| return null; | ||
|
|
@@ -188,4 +203,24 @@ private int countTasks(List<Task<?>> tasks) { | |
| .mapToInt(task -> task instanceof TaskGroup ? countTasks(((TaskGroup) task).getTasks()) : 1) | ||
| .sum(); | ||
| } | ||
|
|
||
| private void addTaskTelemetry( | ||
| String taskName, Instant startTime, Instant endTime, TaskState state) { | ||
| if (telemetryProcessor != null) { | ||
|
||
| try { | ||
| TaskRunMetrics taskMetrics = | ||
| new TaskRunMetrics( | ||
| taskName, | ||
| state.name(), | ||
| startTime, | ||
| endTime, | ||
| MetricToErrorMap.getOrDefault(taskName, null)); | ||
|
|
||
| // Add to the telemetry payload | ||
| telemetryProcessor.addTaskTelemetry(taskMetrics); | ||
| } catch (Exception e) { | ||
kaxuna marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| logger.warn("Failed to add task telemetry for task: {}", taskName, e); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| /* | ||
| * Copyright 2022-2025 Google LLC | ||
| * Copyright 2013-2021 CompilerWorks | ||
| * | ||
| * Licensed 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 com.google.edwmigration.dumper.application.dumper.metrics; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
| import java.time.Instant; | ||
|
|
||
| /** | ||
| * keep immutable. TaskRunner is multi-threaded, so we need to make it thread-safe. | ||
| * | ||
| * @author kakha | ||
| */ | ||
| public class TaskRunMetrics implements TelemetryPayload { | ||
|
|
||
| @JsonProperty private String name; | ||
|
Member
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. I thinks we need both, |
||
|
|
||
| @JsonProperty private EventType eventType = EventType.TASK_RUN_METRICS; | ||
|
Member
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. It should be on level above, before |
||
|
|
||
| @JsonProperty private String overallStatus; | ||
|
|
||
| @JsonProperty private Instant measureStartInstance; | ||
kaxuna marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| @JsonProperty private Instant measureEndInstance; | ||
|
|
||
| @JsonProperty private String error; | ||
|
|
||
| public TaskRunMetrics() { | ||
| // Default constructor for Jackson deserialization | ||
| } | ||
|
|
||
| public TaskRunMetrics( | ||
| String name, | ||
| String overallStatus, | ||
| Instant measureStartInstance, | ||
| Instant measureEndInstance, | ||
| String error) { | ||
| this.name = name; | ||
| this.overallStatus = overallStatus; | ||
| this.measureStartInstance = measureStartInstance; | ||
| this.measureEndInstance = measureEndInstance; | ||
| this.error = error; | ||
| } | ||
|
|
||
| public EventType getEventType() { | ||
| return eventType; | ||
| } | ||
|
|
||
| public String getName() { | ||
| return name; | ||
| } | ||
|
|
||
| public String getOverallStatus() { | ||
| return overallStatus; | ||
| } | ||
|
|
||
| public Instant getMeasureStartInstance() { | ||
| return measureStartInstance; | ||
| } | ||
|
|
||
| public Instant getMeasureEndInstance() { | ||
| return measureEndInstance; | ||
| } | ||
|
|
||
| public String getError() { | ||
| return error; | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.