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

Allow getting metrics after the operator is closed #9615

Merged
merged 1 commit into from
Nov 8, 2021
Merged
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 @@ -538,6 +538,11 @@ private void closeOperators(int lastOperatorIndex)
operatorContext.getDriverContext().getTaskId());
}
finally {
workProcessorOperatorContext.metrics.set(operator.getMetrics());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should also set connectorMetrics (if its first operator in pipeline) (+ test)

BTW: I think you can just modify io.trino.operator.WorkProcessorPipelineSourceOperator#workProcessorOperatorStateMonitor method to report metrics after:

if (state.getType() == FINISHED) {
..
}

if

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should also set connectorMetrics (if its first operator in pipeline) (+ test)

Thanks, added in 2c2aca64e9.

I think you can just modify io.trino.operator.WorkProcessorPipelineSourceOperator#workProcessorOperatorStateMonitor method

I am not sure, since closeOperators is dropping the closed operators in the finally clause:


Please let me know if you meant to refactor closeOperators method as well.

if (operator instanceof WorkProcessorSourceOperator) {
WorkProcessorSourceOperator sourceOperator = (WorkProcessorSourceOperator) operator;
workProcessorOperatorContext.connectorMetrics.set(sourceOperator.getConnectorMetrics());
}
workProcessorOperatorContext.memoryTrackingContext.close();
workProcessorOperatorContext.finalOperatorInfo = operator.getOperatorInfo().orElse(null);
workProcessorOperatorContext.operator = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,9 @@ public boolean isFinished()
public void close()
throws Exception
{
sourceOperator.close();
operatorContext.setLatestMetrics(sourceOperator.getMetrics());
rzeyde-varada marked this conversation as resolved.
Show resolved Hide resolved
operatorContext.setLatestConnectorMetrics(sourceOperator.getConnectorMetrics());
sourceOperator.close();
}

private void updateOperatorStats()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,12 @@ public void testWorkProcessorPipelineSourceOperator()
// assert source operator stats are correct
OperatorStats sourceOperatorStats = operatorStats.get(0);

assertEquals(sourceOperatorStats.getMetrics().getMetrics(), ImmutableMap.of("testSourceMetric", new LongCount(1)));
assertEquals(sourceOperatorStats.getConnectorMetrics().getMetrics(), ImmutableMap.of("testSourceConnectorMetric", new LongCount(2)));
assertEquals(sourceOperatorStats.getMetrics().getMetrics(), ImmutableMap.of(
"testSourceMetric", new LongCount(1),
"testSourceClosed", new LongCount(1)));
assertEquals(sourceOperatorStats.getConnectorMetrics().getMetrics(), ImmutableMap.of(
"testSourceConnectorMetric", new LongCount(2),
"testSourceConnectorClosed", new LongCount(1)));

assertEquals(sourceOperatorStats.getDynamicFilterSplitsProcessed(), 42L);

Expand Down Expand Up @@ -239,8 +243,12 @@ public void testWorkProcessorPipelineSourceOperator()

// assert pipeline metrics
List<OperatorStats> operatorSummaries = pipelineStats.getOperatorSummaries();
assertEquals(operatorSummaries.get(0).getMetrics().getMetrics(), ImmutableMap.of("testSourceMetric", new LongCount(1)));
assertEquals(operatorSummaries.get(0).getConnectorMetrics().getMetrics(), ImmutableMap.of("testSourceConnectorMetric", new LongCount(2)));
assertEquals(operatorSummaries.get(0).getMetrics().getMetrics(), ImmutableMap.of(
"testSourceMetric", new LongCount(1),
"testSourceClosed", new LongCount(1)));
assertEquals(operatorSummaries.get(0).getConnectorMetrics().getMetrics(), ImmutableMap.of(
"testSourceConnectorMetric", new LongCount(2),
"testSourceConnectorClosed", new LongCount(1)));
assertEquals(operatorSummaries.get(1).getMetrics().getMetrics(), ImmutableMap.of("testOperatorMetric", new LongCount(1)));
}

Expand Down Expand Up @@ -425,13 +433,18 @@ public long getDynamicFilterSplitsProcessed()
@Override
public Metrics getMetrics()
{
return new Metrics(ImmutableMap.of("testSourceMetric", new LongCount(1)));
System.err.println("closed: " + closed);
return new Metrics(ImmutableMap.of(
"testSourceMetric", new LongCount(1),
"testSourceClosed", new LongCount(closed ? 1 : 0)));
}

@Override
public Metrics getConnectorMetrics()
{
return new Metrics(ImmutableMap.of("testSourceConnectorMetric", new LongCount(2)));
return new Metrics(ImmutableMap.of(
"testSourceConnectorMetric", new LongCount(2),
"testSourceConnectorClosed", new LongCount(closed ? 1 : 0)));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ default CompletableFuture<?> isBlocked()
* Returns the connector's metrics, mapping a metric ID to its latest value.
* Each call must return an immutable snapshot of available metrics.
* Same ID metrics are merged across all tasks and exposed via OperatorStats.
* This method can be called after the page source is closed.
*/
default Metrics getMetrics()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ private static class DynamicFilteringPageSource
private final boolean enableLazyDynamicFiltering;
private long rows;
private long completedPositions;
private boolean closed;

private DynamicFilteringPageSource(FixedPageSource delegate, List<ColumnHandle> columns, DynamicFilter dynamicFilter, boolean enableLazyDynamicFiltering)
{
Expand Down Expand Up @@ -171,14 +172,15 @@ public long getSystemMemoryUsage()
public void close()
{
delegate.close();
closed = true;
}

@Override
public Metrics getMetrics()
{
return new Metrics(ImmutableMap.of(
"rows", new LongCount(rows),
"finished", new LongCount(isFinished() ? 1 : 0),
"finished", new LongCount(closed ? 1 : 0),
"started", new LongCount(1)));
}
}
Expand Down