Skip to content

Commit 2545d34

Browse files
committed
Wrap execute and explain with context.measure() for profiling
Wrap analyticsEngine.execute() and analyticsEngine.explain() calls with context.measure(MetricName.EXECUTE, ...) so execution time is captured in the profiling metrics. Planning is auto-profiled by UnifiedQueryPlanner. Signed-off-by: Kai Huang <kaihuang@amazon.com> Signed-off-by: Kai Huang <ahkcs@amazon.com>
1 parent 2cf5183 commit 2545d34

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

plugin/src/main/java/org/opensearch/sql/plugin/rest/RestUnifiedQueryAction.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.opensearch.sql.executor.analytics.AnalyticsExecutionEngine;
3232
import org.opensearch.sql.executor.analytics.QueryPlanExecutor;
3333
import org.opensearch.sql.lang.LangSpec;
34+
import org.opensearch.sql.monitor.profile.MetricName;
3435
import org.opensearch.sql.plugin.rest.analytics.stub.StubSchemaProvider;
3536
import org.opensearch.sql.plugin.transport.TransportPPLQueryResponse;
3637
import org.opensearch.sql.ppl.domain.PPLQueryRequest;
@@ -122,7 +123,14 @@ private void doExecute(
122123
CalcitePlanContext planContext = context.getPlanContext();
123124
plan = addQuerySizeLimit(plan, planContext);
124125

125-
analyticsEngine.execute(plan, planContext, createQueryListener(queryType, listener));
126+
RelNode finalPlan = plan;
127+
context.measure(
128+
MetricName.EXECUTE,
129+
() -> {
130+
analyticsEngine.execute(
131+
finalPlan, planContext, createQueryListener(queryType, listener));
132+
return null;
133+
});
126134
} catch (Exception e) {
127135
listener.onFailure(e);
128136
}
@@ -140,7 +148,13 @@ private void doExplain(
140148
CalcitePlanContext planContext = context.getPlanContext();
141149
plan = addQuerySizeLimit(plan, planContext);
142150

143-
analyticsEngine.explain(plan, pplRequest.mode(), planContext, listener);
151+
RelNode finalPlan = plan;
152+
context.measure(
153+
MetricName.EXECUTE,
154+
() -> {
155+
analyticsEngine.explain(finalPlan, pplRequest.mode(), planContext, listener);
156+
return null;
157+
});
144158
} catch (Exception e) {
145159
listener.onFailure(e);
146160
}

0 commit comments

Comments
 (0)