generated from amazon-archives/__template_Custom
-
Notifications
You must be signed in to change notification settings - Fork 181
Support profile options for PPL - Part I Implement phases level metrics. #4983
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
Merged
+655
−11
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3851abd
Init
penghuo edbb6e0
Cleanup ThreadLocal
penghuo 079072a
Update doc
penghuo 154a70d
Update Doc
penghuo 53b7589
Refactor Code
penghuo ee0d477
Remove unused code
penghuo 820d757
Address comments
penghuo 7ff2bb2
Add Task 1 - Add Phases level metrics
penghuo 0da0c4b
Reformat doc
penghuo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
core/src/main/java/org/opensearch/sql/monitor/profile/DefaultMetricImpl.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package org.opensearch.sql.monitor.profile; | ||
|
|
||
| import java.util.concurrent.atomic.LongAdder; | ||
|
|
||
| /** Concrete metric backed by {@link LongAdder}. */ | ||
| final class DefaultMetricImpl implements ProfileMetric { | ||
|
|
||
| private final String name; | ||
| private final LongAdder value = new LongAdder(); | ||
|
|
||
| /** | ||
| * Construct a metric with the provided name. | ||
| * | ||
| * @param name metric name | ||
| */ | ||
| DefaultMetricImpl(String name) { | ||
| this.name = name; | ||
| } | ||
|
|
||
| @Override | ||
| public String name() { | ||
| return name; | ||
| } | ||
|
|
||
| @Override | ||
| public long value() { | ||
| return value.sum(); | ||
| } | ||
|
|
||
| @Override | ||
| public void add(long delta) { | ||
| value.add(delta); | ||
| } | ||
|
|
||
| @Override | ||
| public void set(long value) { | ||
| this.value.reset(); | ||
| this.value.add(value); | ||
| } | ||
| } |
52 changes: 52 additions & 0 deletions
52
core/src/main/java/org/opensearch/sql/monitor/profile/DefaultProfileContext.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package org.opensearch.sql.monitor.profile; | ||
|
|
||
| import java.util.LinkedHashMap; | ||
| import java.util.Map; | ||
| import java.util.Objects; | ||
| import java.util.concurrent.ConcurrentHashMap; | ||
|
|
||
| /** Default implementation that records profiling metrics. */ | ||
| public class DefaultProfileContext implements ProfileContext { | ||
|
|
||
| private final long startNanos = System.nanoTime(); | ||
| private boolean finished; | ||
| private final Map<MetricName, DefaultMetricImpl> metrics = new ConcurrentHashMap<>(); | ||
| private QueryProfile profile; | ||
|
|
||
| public DefaultProfileContext() {} | ||
penghuo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /** {@inheritDoc} */ | ||
| @Override | ||
| public ProfileMetric getOrCreateMetric(MetricName name) { | ||
| Objects.requireNonNull(name, "name"); | ||
| return metrics.computeIfAbsent(name, key -> new DefaultMetricImpl(key.name())); | ||
| } | ||
penghuo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /** {@inheritDoc} */ | ||
| @Override | ||
| public synchronized QueryProfile finish() { | ||
| if (finished) { | ||
| return profile; | ||
| } | ||
| finished = true; | ||
| long endNanos = System.nanoTime(); | ||
| Map<MetricName, Double> snapshot = new LinkedHashMap<>(MetricName.values().length); | ||
| for (MetricName metricName : MetricName.values()) { | ||
| DefaultMetricImpl metric = metrics.get(metricName); | ||
| double millis = metric == null ? 0d : roundToMillis(metric.value()); | ||
| snapshot.put(metricName, millis); | ||
| } | ||
| double totalMillis = roundToMillis(endNanos - startNanos); | ||
| profile = new QueryProfile(totalMillis, snapshot); | ||
| return profile; | ||
| } | ||
penghuo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| private double roundToMillis(long nanos) { | ||
| return Math.round((nanos / 1_000_000.0d) * 100.0d) / 100.0d; | ||
| } | ||
| } | ||
14 changes: 14 additions & 0 deletions
14
core/src/main/java/org/opensearch/sql/monitor/profile/MetricName.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package org.opensearch.sql.monitor.profile; | ||
|
|
||
| /** Named metrics used by query profiling. */ | ||
| public enum MetricName { | ||
|
Collaborator
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. Do we need PARSE_TIME, though it should be tiny?
Collaborator
Author
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 ignore it for now, should be minial. |
||
| ANALYZE, | ||
| OPTIMIZE, | ||
| EXECUTE, | ||
| FORMAT | ||
| } | ||
29 changes: 29 additions & 0 deletions
29
core/src/main/java/org/opensearch/sql/monitor/profile/NoopProfileContext.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package org.opensearch.sql.monitor.profile; | ||
|
|
||
| import java.util.Objects; | ||
|
|
||
| /** Disabled profiling context. */ | ||
| public final class NoopProfileContext implements ProfileContext { | ||
|
|
||
| public static final NoopProfileContext INSTANCE = new NoopProfileContext(); | ||
|
|
||
| private NoopProfileContext() {} | ||
|
|
||
| /** {@inheritDoc} */ | ||
| @Override | ||
| public ProfileMetric getOrCreateMetric(MetricName name) { | ||
| Objects.requireNonNull(name, "name"); | ||
| return NoopProfileMetric.INSTANCE; | ||
| } | ||
|
|
||
| /** {@inheritDoc} */ | ||
| @Override | ||
| public QueryProfile finish() { | ||
| return null; | ||
| } | ||
| } |
34 changes: 34 additions & 0 deletions
34
core/src/main/java/org/opensearch/sql/monitor/profile/NoopProfileMetric.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package org.opensearch.sql.monitor.profile; | ||
|
|
||
| /** No-op metric implementation. */ | ||
| final class NoopProfileMetric implements ProfileMetric { | ||
|
|
||
| static final NoopProfileMetric INSTANCE = new NoopProfileMetric(); | ||
|
|
||
| private NoopProfileMetric() {} | ||
|
|
||
| /** {@inheritDoc} */ | ||
| @Override | ||
| public String name() { | ||
| return ""; | ||
| } | ||
|
|
||
| /** {@inheritDoc} */ | ||
| @Override | ||
| public long value() { | ||
| return 0; | ||
| } | ||
|
|
||
| /** {@inheritDoc} */ | ||
| @Override | ||
| public void add(long delta) {} | ||
|
|
||
| /** {@inheritDoc} */ | ||
| @Override | ||
| public void set(long value) {} | ||
| } |
24 changes: 24 additions & 0 deletions
24
core/src/main/java/org/opensearch/sql/monitor/profile/ProfileContext.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package org.opensearch.sql.monitor.profile; | ||
|
|
||
| /** Context for collecting profiling metrics during query execution. */ | ||
| public interface ProfileContext { | ||
| /** | ||
| * Obtain or create a metric with the provided name. | ||
| * | ||
| * @param name fully qualified metric name | ||
| * @return metric instance | ||
| */ | ||
| ProfileMetric getOrCreateMetric(MetricName name); | ||
|
|
||
| /** | ||
| * Finalize profiling and return a snapshot. | ||
| * | ||
| * @return immutable query profile snapshot | ||
| */ | ||
| QueryProfile finish(); | ||
| } |
33 changes: 33 additions & 0 deletions
33
core/src/main/java/org/opensearch/sql/monitor/profile/ProfileMetric.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package org.opensearch.sql.monitor.profile; | ||
|
|
||
| /** Metric for query profiling. */ | ||
| public interface ProfileMetric { | ||
| /** | ||
| * @return metric name. | ||
| */ | ||
| String name(); | ||
|
|
||
| /** | ||
| * @return current metric value. | ||
| */ | ||
| long value(); | ||
|
|
||
| /** | ||
| * Increment the metric by the given delta. | ||
| * | ||
| * @param delta amount to add | ||
| */ | ||
| void add(long delta); | ||
|
|
||
| /** | ||
| * Set the metric to the provided value. | ||
| * | ||
| * @param value new metric value | ||
| */ | ||
| void set(long value); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.