Skip to content
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

[Monitoring] Add cluster metadata to cluster_stats docs #33860

Expand Up @@ -112,7 +112,8 @@ protected Collection<MonitoringDoc> doCollect(final MonitoringDoc.Node node,
// Adds a cluster stats document
return Collections.singleton(
new ClusterStatsMonitoringDoc(clusterUuid, timestamp(), interval, node, clusterName, version, clusterStats.getStatus(),
license, apmIndicesExist, xpackUsage, clusterStats, clusterState, clusterNeedsTLSEnabled));
license, apmIndicesExist, xpackUsage, clusterStats, clusterState,
clusterNeedsTLSEnabled));
}

boolean doAPMIndicesExist(final ClusterState clusterState) {
Expand Down
Expand Up @@ -8,10 +8,12 @@
import org.elasticsearch.action.admin.cluster.stats.ClusterStatsResponse;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.health.ClusterHealthStatus;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.cluster.node.DiscoveryNodes;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.collect.MapBuilder;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.license.License;
Expand Down Expand Up @@ -45,6 +47,7 @@ public class ClusterStatsMonitoringDoc extends MonitoringDoc {
ClusterState.Metric.NODES));

public static final String TYPE = "cluster_stats";
protected static final String SETTING_CLUSTER_METADATA = "cluster.metadata";

private final String clusterName;
private final String version;
Expand Down Expand Up @@ -118,6 +121,14 @@ boolean getClusterNeedsTLSEnabled() {
return clusterNeedsTLSEnabled;
}

Settings getClusterMetaDataSettings() {
MetaData metaData = this.clusterState.getMetaData();
if (metaData == null) {
return Settings.EMPTY;
}
return metaData.settings().getAsSettings(SETTING_CLUSTER_METADATA);
}

@Override
protected void innerToXContent(XContentBuilder builder, Params params) throws IOException {
builder.field("cluster_name", clusterName);
Expand Down Expand Up @@ -156,6 +167,25 @@ protected void innerToXContent(XContentBuilder builder, Params params) throws IO
builder.endObject();
}

Settings clusterMetaDataSettings = getClusterMetaDataSettings();
if (clusterMetaDataSettings != null) {
builder.startObject("cluster_settings");
{
if (clusterMetaDataSettings.size() > 0) {
builder.startObject("cluster");
{
builder.startObject("metadata");
{
clusterMetaDataSettings.toXContent(builder, params);
}
builder.endObject();
}
builder.endObject();
}
}
builder.endObject();
}

builder.startObject("stack_stats");
{
// in the future, it may be useful to pass in an object that represents APM (and others), but for now this
Expand Down
Expand Up @@ -203,7 +203,12 @@ public void testToXContent() throws IOException {
Version.V_6_0_0_beta1);

final ClusterState clusterState = ClusterState.builder(clusterName)
.metaData(MetaData.builder().clusterUUID(clusterUuid).build())
.metaData(MetaData.builder()
.clusterUUID(clusterUuid)
.transientSettings(Settings.builder()
.put("cluster.metadata.display_name", "my_prod_cluster")
.build())
.build())
.stateUUID("_state_uuid")
.version(12L)
.nodes(DiscoveryNodes.builder()
Expand Down Expand Up @@ -521,6 +526,13 @@ public void testToXContent() throws IOException {
+ "}"
+ "}"
+ "},"
+ "\"cluster_settings\":{"
+ "\"cluster\":{"
+ "\"metadata\":{"
+ "\"display_name\":\"my_prod_cluster\""
+ "}"
+ "}"
+ "},"
+ "\"stack_stats\":{"
+ "\"apm\":{"
+ "\"found\":" + apmIndicesExist
Expand Down