-
Notifications
You must be signed in to change notification settings - Fork 24.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Adds a full list of supported aggregations to the node info API. This list will be used in transform tests and telemetry mapping tests that will be added as follow-up PRs. Fixes #59774
- Loading branch information
Showing
13 changed files
with
188 additions
and
8 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
rest-api-spec/src/main/resources/rest-api-spec/test/nodes.info/40_aggs.yml
This file contains 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,18 @@ | ||
--- | ||
"node_info test aggregations": | ||
- skip: | ||
version: " - 7.9.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 ] | ||
|
||
- match : { nodes.$node_id.aggregations.filter: { "types": ["other"] } } |
This file contains 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 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 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 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 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 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 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
108 changes: 108 additions & 0 deletions
108
server/src/main/java/org/elasticsearch/search/aggregations/support/AggregationInfo.java
This file contains 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,108 @@ | ||
/* | ||
* 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.support; | ||
|
||
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.Collections; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.Set; | ||
import java.util.TreeMap; | ||
import java.util.TreeSet; | ||
import java.util.concurrent.atomic.LongAdder; | ||
|
||
public class AggregationInfo implements ReportingService.Info { | ||
|
||
private final Map<String, Set<String>> aggs; | ||
|
||
AggregationInfo(Map<String, Map<String, LongAdder>> aggs) { | ||
// we use a treemap/treeset here to have a test-able / predictable order | ||
Map<String, Set<String>> aggsMap = new TreeMap<>(); | ||
aggs.forEach((s, m) -> aggsMap.put(s, Collections.unmodifiableSet(new TreeSet<>(m.keySet())))); | ||
this.aggs = Collections.unmodifiableMap(aggsMap); | ||
} | ||
|
||
/** | ||
* 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>> getAggregations() { | ||
return aggs; | ||
} | ||
|
||
@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); | ||
} | ||
} |
This file contains 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 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 |
---|---|---|
|
@@ -57,6 +57,7 @@ public void testGetInfo() { | |
null, | ||
null, | ||
null, | ||
null, | ||
null); | ||
|
||
// OsInfo is absent | ||
|
This file contains 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 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