-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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 aggregation list to node info #60074
Changes from 1 commit
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
"node_info test aggregations": | ||
- skip: | ||
version: " - 7.99.99" | ||
reason: "aggregation info only supported in 8.0.0+" | ||
features: [arbitrary_key] | ||
|
||
|
||
- do: | ||
nodes.info: {} | ||
- set: | ||
nodes._arbitrary_key_: node_id | ||
|
||
- do: | ||
nodes.info: | ||
metric: [ aggregations ] | ||
|
||
# if this test failed because a new aggregation was added, please open an issues in the elastic/telemetry repository | ||
# so they can update the mapping accordingly | ||
- match : { nodes.$node_id.aggregations.filter: { "types": ["other"] } } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.search.aggregations; | ||
|
||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
import org.elasticsearch.common.xcontent.XContentBuilder; | ||
import org.elasticsearch.node.ReportingService; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.Set; | ||
import java.util.TreeMap; | ||
import java.util.TreeSet; | ||
|
||
public class AggregationInfo implements ReportingService.Info { | ||
|
||
private final Map<String, Set<String>> aggs; | ||
|
||
public AggregationInfo(Map<String, Set<String>> aggs) { | ||
this.aggs = aggs; | ||
} | ||
|
||
/** | ||
* Read from a stream. | ||
*/ | ||
public AggregationInfo(StreamInput in) throws IOException { | ||
aggs = new TreeMap<>(); | ||
final int size = in.readVInt(); | ||
for (int i = 0; i < size; i++) { | ||
String key = in.readString(); | ||
final int keys = in.readVInt(); | ||
final Set<String> types = new TreeSet<>(); | ||
for (int j = 0; j < keys; j ++) { | ||
types.add(in.readString()); | ||
} | ||
aggs.put(key, types); | ||
} | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
out.writeVInt(aggs.size()); | ||
for (Map.Entry<String, Set<String>> e : aggs.entrySet()) { | ||
out.writeString(e.getKey()); | ||
out.writeVInt(e.getValue().size()); | ||
for (String type : e.getValue()) { | ||
out.writeString(type); | ||
} | ||
} | ||
} | ||
|
||
public Map<String, Set<String>> getProcessors() { | ||
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. getProcessors() ? I assume the name is off, but is this even needed ? 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. Copy and paste error. Will fix. |
||
return aggs; | ||
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. We're leaking a mutable reference here. It doesn't look like we mutate it anywhere, might be worth wrapping it to be immutable, if the object creation cost for the wrapper isn't too much. |
||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.startObject("aggregations"); | ||
for (Map.Entry<String, Set<String>> e : aggs.entrySet()) { | ||
builder.startObject(e.getKey()); | ||
builder.startArray("types"); | ||
for (String s : e.getValue()) { | ||
builder.value(s); | ||
} | ||
builder.endArray(); | ||
builder.endObject(); | ||
} | ||
builder.endObject(); | ||
return builder; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
AggregationInfo that = (AggregationInfo) o; | ||
return Objects.equals(aggs, that.aggs); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(aggs); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,6 +57,7 @@ public void testGetInfo() { | |
null, | ||
null, | ||
null, | ||
null, | ||
null); | ||
|
||
// OsInfo is absent | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this comment seems abit out of place, and probably shouldn't reference a private repo.
also, I guess I don't understand the output. is it aggregrations.??.types = ?? . Is there anything that prevents checking for known types
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was sure I removed it. This comment is out of place. Good catch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The output looks like this:
and both types and aggs change depending on license that this is ran under.