Add discovery types to cluster stats (#36442)
Adds information about the used discovery types to the cluster stats, similar as we have for the network types.
This commit is contained in:
parent
d7c5d8049a
commit
d8e3d97a7d
|
@ -202,20 +202,25 @@ Will return, for example:
|
|||
},
|
||||
...
|
||||
],
|
||||
...
|
||||
"network_types": {
|
||||
...
|
||||
},
|
||||
"discovery_types": {
|
||||
...
|
||||
}
|
||||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// TESTRESPONSE[s/"plugins": \[[^\]]*\]/"plugins": $body.$_path/]
|
||||
// TESTRESPONSE[s/\.\.\./"network_types": "replace_me"/]
|
||||
// TESTRESPONSE[s/"network_types": \{[^\}]*\}/"network_types": $body.$_path/]
|
||||
// TESTRESPONSE[s/"discovery_types": \{[^\}]*\}/"discovery_types": $body.$_path/]
|
||||
// TESTRESPONSE[s/: (\-)?[0-9]+/: $body.$_path/]
|
||||
// TESTRESPONSE[s/: "[^"]*"/: $body.$_path/]
|
||||
// These replacements do a few things:
|
||||
// 1. Ignore the contents of the `plugins` object because we don't know all of
|
||||
// the plugins that will be in it. And because we figure folks don't need to
|
||||
// see an exhaustive list anyway.
|
||||
// 2. The last ... contains more things that we don't think are important to
|
||||
// include in the output.
|
||||
// 2. Similarly, ignore the contents of `network_types` and `discovery_types`.
|
||||
// 3. All of the numbers and strings on the right hand side of *every* field in
|
||||
// the response are ignored. So we're really only asserting things about the
|
||||
// the shape of this response, not the values in it.
|
||||
|
|
|
@ -66,3 +66,14 @@
|
|||
- is_true: nodes.fs
|
||||
- is_true: nodes.plugins
|
||||
- is_true: nodes.network_types
|
||||
|
||||
---
|
||||
"get cluster stats returns discovery types":
|
||||
- skip:
|
||||
version: " - 6.99.99"
|
||||
reason: "discovery types are added for v7.0.0"
|
||||
|
||||
- do:
|
||||
cluster.stats: {}
|
||||
|
||||
- is_true: nodes.discovery_types
|
||||
|
|
|
@ -34,6 +34,7 @@ import org.elasticsearch.common.unit.ByteSizeValue;
|
|||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.common.xcontent.ToXContentFragment;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.discovery.DiscoveryModule;
|
||||
import org.elasticsearch.monitor.fs.FsInfo;
|
||||
import org.elasticsearch.monitor.jvm.JvmInfo;
|
||||
import org.elasticsearch.plugins.PluginInfo;
|
||||
|
@ -59,6 +60,7 @@ public class ClusterStatsNodes implements ToXContentFragment {
|
|||
private final FsInfo.Path fs;
|
||||
private final Set<PluginInfo> plugins;
|
||||
private final NetworkTypes networkTypes;
|
||||
private final DiscoveryTypes discoveryTypes;
|
||||
|
||||
ClusterStatsNodes(List<ClusterStatsNodeResponse> nodeResponses) {
|
||||
this.versions = new HashSet<>();
|
||||
|
@ -90,6 +92,7 @@ public class ClusterStatsNodes implements ToXContentFragment {
|
|||
this.process = new ProcessStats(nodeStats);
|
||||
this.jvm = new JvmStats(nodeInfos, nodeStats);
|
||||
this.networkTypes = new NetworkTypes(nodeInfos);
|
||||
this.discoveryTypes = new DiscoveryTypes(nodeInfos);
|
||||
}
|
||||
|
||||
public Counts getCounts() {
|
||||
|
@ -167,6 +170,8 @@ public class ClusterStatsNodes implements ToXContentFragment {
|
|||
builder.startObject(Fields.NETWORK_TYPES);
|
||||
networkTypes.toXContent(builder, params);
|
||||
builder.endObject();
|
||||
|
||||
discoveryTypes.toXContent(builder, params);
|
||||
return builder;
|
||||
}
|
||||
|
||||
|
@ -612,4 +617,29 @@ public class ClusterStatsNodes implements ToXContentFragment {
|
|||
|
||||
}
|
||||
|
||||
static class DiscoveryTypes implements ToXContentFragment {
|
||||
|
||||
private final Map<String, AtomicInteger> discoveryTypes;
|
||||
|
||||
DiscoveryTypes(final List<NodeInfo> nodeInfos) {
|
||||
final Map<String, AtomicInteger> discoveryTypes = new HashMap<>();
|
||||
for (final NodeInfo nodeInfo : nodeInfos) {
|
||||
final Settings settings = nodeInfo.getSettings();
|
||||
final String discoveryType = DiscoveryModule.DISCOVERY_TYPE_SETTING.get(settings);
|
||||
discoveryTypes.computeIfAbsent(discoveryType, k -> new AtomicInteger()).incrementAndGet();
|
||||
}
|
||||
this.discoveryTypes = Collections.unmodifiableMap(discoveryTypes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject("discovery_types");
|
||||
for (final Map.Entry<String, AtomicInteger> entry : discoveryTypes.entrySet()) {
|
||||
builder.field(entry.getKey(), entry.getValue().get());
|
||||
}
|
||||
builder.endObject();
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ import org.elasticsearch.common.unit.ByteSizeValue;
|
|||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.discovery.DiscoveryModule;
|
||||
import org.elasticsearch.index.shard.ShardId;
|
||||
import org.elasticsearch.license.License;
|
||||
import org.elasticsearch.monitor.fs.FsInfo;
|
||||
|
@ -242,6 +243,7 @@ public class ClusterStatsMonitoringDocTests extends BaseMonitoringDocTestCase<Cl
|
|||
when(mockNodeInfo.getSettings()).thenReturn(Settings.builder()
|
||||
.put(NetworkModule.TRANSPORT_TYPE_KEY, "_transport")
|
||||
.put(NetworkModule.HTTP_TYPE_KEY, "_http")
|
||||
.put(DiscoveryModule.DISCOVERY_TYPE_SETTING.getKey(), "_disco")
|
||||
.build());
|
||||
|
||||
final PluginsAndModules mockPluginsAndModules = mock(PluginsAndModules.class);
|
||||
|
@ -512,6 +514,9 @@ public class ClusterStatsMonitoringDocTests extends BaseMonitoringDocTestCase<Cl
|
|||
+ "\"http_types\":{"
|
||||
+ "\"_http\":1"
|
||||
+ "}"
|
||||
+ "},"
|
||||
+ "\"discovery_types\":{"
|
||||
+ "\"_disco\":1"
|
||||
+ "}"
|
||||
+ "}"
|
||||
+ "},"
|
||||
|
|
Loading…
Reference in New Issue