Skip to content
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

Add ingest/processed/bytes metric #17581

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
import org.apache.druid.java.util.common.granularity.Granularity;
import org.apache.druid.java.util.common.io.Closer;
import org.apache.druid.java.util.common.logger.Logger;
import org.apache.druid.msq.counters.ChannelCounters;
import org.apache.druid.msq.counters.CounterSnapshots;
import org.apache.druid.msq.counters.CounterSnapshotsTree;
import org.apache.druid.msq.indexing.InputChannelFactory;
Expand Down Expand Up @@ -162,6 +163,7 @@
import org.apache.druid.msq.querykit.scan.ScanQueryKit;
import org.apache.druid.msq.shuffle.input.DurableStorageInputChannelFactory;
import org.apache.druid.msq.shuffle.input.WorkerInputChannelFactory;
import org.apache.druid.msq.statistics.ClusterByStatisticsCollector;
import org.apache.druid.msq.statistics.PartialKeyStatisticsInformation;
import org.apache.druid.msq.util.IntervalUtils;
import org.apache.druid.msq.util.MSQFutureUtils;
Expand Down Expand Up @@ -514,7 +516,7 @@ private MSQTaskReportPayload runInternal(final QueryListener queryListener, fina
stagesReport = null;
}

return new MSQTaskReportPayload(
final MSQTaskReportPayload msqTaskReportPayload = new MSQTaskReportPayload(
makeStatusReport(
taskStateForReport,
errorForReport,
Expand All @@ -529,6 +531,32 @@ private MSQTaskReportPayload runInternal(final QueryListener queryListener, fina
countersSnapshot,
null
);
// Emit summary metrics
emitSummaryMetrics(msqTaskReportPayload, querySpec);
return msqTaskReportPayload;
}

private void emitSummaryMetrics(final MSQTaskReportPayload msqTaskReportPayload, final MSQSpec querySpec)
{
long totalProcessedBytes = 0;

if (msqTaskReportPayload.getCounters() != null) {
totalProcessedBytes = msqTaskReportPayload.getCounters()
.copyMap()
.values()
.stream()
.flatMap(counterSnapshotsMap -> counterSnapshotsMap.values().stream())
.flatMap(counterSnapshots -> counterSnapshots.getMap().entrySet().stream())
.filter(entry -> entry.getKey().startsWith("input"))
.mapToLong(entry -> {
ChannelCounters.Snapshot snapshot = (ChannelCounters.Snapshot) entry.getValue();
return snapshot.getBytes() == null ? 0L : Arrays.stream(snapshot.getBytes()).sum();
})
.sum();
}

log.debug("Processed bytes[%d] for query[%s].", totalProcessedBytes, querySpec.getQuery());
context.emitMetric("ingest/processed/bytes", totalProcessedBytes);
}

/**
Expand Down Expand Up @@ -2418,7 +2446,7 @@ private void startTaskLauncher()
}

/**
* Enqueues the fetching {@link org.apache.druid.msq.statistics.ClusterByStatisticsCollector}
* Enqueues the fetching {@link ClusterByStatisticsCollector}
* from each worker via {@link WorkerSketchFetcher}
*/
private void fetchStatsFromWorkers()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
import org.apache.druid.java.util.common.StringUtils;
import org.apache.druid.java.util.common.granularity.Granularity;
import org.apache.druid.java.util.common.logger.Logger;
import org.apache.druid.java.util.emitter.service.ServiceMetricEvent;
import org.apache.druid.rpc.HttpResponseException;
import org.apache.druid.rpc.indexing.OverlordClient;
import org.apache.druid.segment.SegmentSchemaMapping;
Expand Down Expand Up @@ -1251,12 +1252,19 @@ private TaskStatus runSequential(TaskToolbox toolbox) throws Exception
*/
private TaskReport.ReportMap getTaskCompletionReports(TaskStatus taskStatus)
{
return buildIngestionStatsAndContextReport(
final var taskCompletionReport = buildIngestionStatsAndContextReport(
IngestionState.COMPLETED,
taskStatus.getErrorMsg(),
segmentsRead,
segmentsPublished
);
final var totalProcessedBytes = indexGenerateRowStats.lhs.get("processedBytes");
// Emit the processed bytes metric
final ServiceMetricEvent.Builder metricBuilder = new ServiceMetricEvent.Builder();
//IndexTaskUtils.setTaskDimensions(metricBuilder, task);
toolbox.getEmitter().emit(
metricBuilder.setMetric("ingest/processed/bytes", (Number) totalProcessedBytes));
return taskCompletionReport;
}

@Override
Expand Down Expand Up @@ -1633,6 +1641,9 @@ private Pair<Map<String, Object>, Map<String, Object>> doGetRowStatsAndUnparseab
);
buildSegmentsRowStats.addRowIngestionMetersTotals(rowStatsForRunningTasks);

// Emit the processed bytes metric
emitMetric(toolbox.getEmitter(), "ingest/processed/bytes", rowStatsForRunningTasks.getProcessedBytes());

return createStatsAndErrorsReport(buildSegmentsRowStats.getTotals(), unparseableEvents);
}

Expand Down
Loading