-
Notifications
You must be signed in to change notification settings - Fork 277
Add Query Subplans to Metrics [Query Metric Service] #2849
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
base: integration
Are you sure you want to change the base?
Changes from 2 commits
aceabd4
da5ea95
6ed0fea
d704bc6
db5f4e8
35d9321
f8a1e97
e226c82
392d052
545c855
1d088e5
658d743
2863d16
cc008a9
df76401
d3e5d4a
bdce5a8
19c0a89
b3c5023
cefeac0
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 |
|---|---|---|
|
|
@@ -684,6 +684,9 @@ public int getFieldNumber(String name) { | |
| @XmlElement | ||
| protected String plan = null; | ||
| @XmlElement | ||
| @XmlJavaTypeAdapter(StringRangeCountMapAdapter.class) | ||
| protected Map<String,RangeCounts> subPlans = new HashMap<>(); | ||
| @XmlElement | ||
| protected long loginTime = -1; | ||
| @XmlElementWrapper(name = "predictions") | ||
| @XmlElement(name = "prediction") | ||
|
|
@@ -699,6 +702,46 @@ public enum Lifecycle { | |
| NONE, DEFINED, INITIALIZED, RESULTS, CLOSED, CANCELLED, MAXRESULTS, NEXTTIMEOUT, TIMEOUT, SHUTDOWN, MAXWORK | ||
| } | ||
|
|
||
| public void addSubPlan(String plan, RangeCounts rangeCounts) { | ||
| synchronized (this.subPlans) { | ||
| if (subPlans.containsKey(plan)) { | ||
| RangeCounts combinedCounts = new RangeCounts(); | ||
| RangeCounts currentCounts = subPlans.get(plan); | ||
| combinedCounts.setDocumentRangeCount(currentCounts.getDocumentRangeCount() + rangeCounts.getDocumentRangeCount()); | ||
| combinedCounts.setShardRangeCount(currentCounts.getShardRangeCount() + rangeCounts.getShardRangeCount()); | ||
| subPlans.put(plan, combinedCounts); | ||
| } else { | ||
| subPlans.put(plan, rangeCounts); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public void addSubPlans(Map<String,RangeCounts> subplanMap) { | ||
| synchronized (this.subPlans) { | ||
| if (subplanMap != null && !subplanMap.isEmpty()) { | ||
| for (Map.Entry<String,RangeCounts> entry : subplanMap.entrySet()) { | ||
| if (subPlans.containsKey(entry.getKey())) { | ||
| RangeCounts combinedCounts = new RangeCounts(); | ||
| RangeCounts currentCounts = subPlans.get(entry.getKey()); | ||
| combinedCounts.setDocumentRangeCount(currentCounts.getDocumentRangeCount() + entry.getValue().getDocumentRangeCount()); | ||
| combinedCounts.setShardRangeCount(currentCounts.getShardRangeCount() + entry.getValue().getShardRangeCount()); | ||
| subPlans.put(entry.getKey(), combinedCounts); | ||
| } else { | ||
| subPlans.put(entry.getKey(), entry.getValue()); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
foster33 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| public Map<String,RangeCounts> getSubPlans() { | ||
| return subPlans; | ||
| } | ||
|
|
||
| public void setSubPlans(Map<String,RangeCounts> subPlans) { | ||
| this.subPlans = subPlans; | ||
| } | ||
|
|
||
|
||
| public String getQueryType() { | ||
| return queryType; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| package datawave.microservice.querymetric; | ||
|
|
||
| import java.io.Serializable; | ||
| import java.util.Objects; | ||
|
|
||
| import org.apache.commons.lang3.builder.EqualsBuilder; | ||
|
|
||
| public class RangeCounts implements Serializable { | ||
|
|
||
| private long documentRangeCount; | ||
| private long shardRangeCount; | ||
|
|
||
| public long getDocumentRangeCount() { | ||
| return documentRangeCount; | ||
| } | ||
|
|
||
| public long getShardRangeCount() { | ||
| return shardRangeCount; | ||
| } | ||
|
|
||
| public void setDocumentRangeCount(long newDocumentRangeCount) { | ||
| this.documentRangeCount = newDocumentRangeCount; | ||
| } | ||
|
|
||
| public void setShardRangeCount(long newShardRangeCount) { | ||
| this.shardRangeCount = newShardRangeCount; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) { | ||
| return true; | ||
| } | ||
|
|
||
| if (o == null || getClass() != o.getClass()) { | ||
| return false; | ||
| } | ||
|
|
||
| RangeCounts that = (RangeCounts) o; | ||
|
|
||
| return new EqualsBuilder().append(documentRangeCount, that.documentRangeCount).append(shardRangeCount, that.shardRangeCount).isEquals(); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(documentRangeCount, shardRangeCount); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| package datawave.microservice.querymetric; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| import javax.xml.bind.annotation.XmlAttribute; | ||
| import javax.xml.bind.annotation.XmlElement; | ||
| import javax.xml.bind.annotation.XmlValue; | ||
| import javax.xml.bind.annotation.adapters.XmlAdapter; | ||
|
|
||
| /** | ||
| * Provides JAX-B marshalling/unmarshalling of {@link Map} of String to RangeCount. This allows the marshalled type to be in our own namespace rather than in | ||
| * the "default" one, which when triggered will then assume the "" prefix and push all of our own elements into the "ns2" prefix. | ||
| */ | ||
| public class StringRangeCountMapAdapter extends XmlAdapter<StringRangeCountMapAdapter.StringRangeCountMap,Map<String,RangeCounts>> { | ||
|
|
||
| @Override | ||
| public Map<String,RangeCounts> unmarshal(StringRangeCountMap v) throws Exception { | ||
| HashMap<String,RangeCounts> map = new HashMap<>(); | ||
| for (StringRangeCountMapEntry entry : v.entries) { | ||
| RangeCounts unmarshalledRangeCounts = new RangeCounts(); | ||
| unmarshalledRangeCounts.setDocumentRangeCount(Long.parseLong(entry.value.split(",")[0])); | ||
| unmarshalledRangeCounts.setShardRangeCount(Long.parseLong(entry.value.split(",")[1])); | ||
| map.put(entry.key, unmarshalledRangeCounts); | ||
| } | ||
| return map; | ||
| } | ||
|
|
||
| @Override | ||
| public StringRangeCountMap marshal(Map<String,RangeCounts> v) throws Exception { | ||
| StringRangeCountMap map = new StringRangeCountMap(); | ||
| for (Map.Entry<String,RangeCounts> entry : v.entrySet()) { | ||
| map.entries.add(new StringRangeCountMapEntry(entry.getKey(), toText(entry.getValue()))); | ||
| } | ||
| return map; | ||
| } | ||
|
|
||
| public String toText(RangeCounts counts) { | ||
| return counts.getDocumentRangeCount() + "," + counts.getShardRangeCount(); | ||
| } | ||
|
|
||
| public static class StringRangeCountMap { | ||
| @XmlElement(name = "entry") | ||
| private List<StringRangeCountMapEntry> entries = new ArrayList<>(); | ||
| } | ||
|
|
||
| public static class StringRangeCountMapEntry { | ||
| @XmlAttribute(name = "name") | ||
| private String key; | ||
| @XmlValue | ||
| private String value; | ||
|
|
||
| public StringRangeCountMapEntry() {} | ||
|
|
||
| public StringRangeCountMapEntry(String key, String value) { | ||
| this.key = key; | ||
| this.value = value; | ||
| } | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.