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) #34023

Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -113,7 +113,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,6 +8,7 @@
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;
Expand Down Expand Up @@ -45,6 +46,7 @@ public class ClusterStatsMonitoringDoc extends MonitoringDoc {
ClusterState.Metric.NODES));

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

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

String getClusterDisplayName() {
MetaData metaData = this.clusterState.getMetaData();
if (metaData == null) {
return null;
}
return metaData.settings().get(SETTING_DISPLAY_NAME);
}

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

String displayName = getClusterDisplayName();
if (displayName != null) {
builder.startObject("cluster_settings");
{
builder.startObject("cluster");
{
builder.startObject("metadata");
{
builder.field("display_name", displayName);
}
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
Expand Up @@ -316,7 +316,7 @@ private void assertMonitoringDocSourceNode(final Map<String, Object> sourceNode)
private void assertClusterStatsMonitoringDoc(final Map<String, Object> document,
final boolean apmIndicesExist) {
final Map<String, Object> source = (Map<String, Object>) document.get("_source");
assertEquals(11, source.size());
assertEquals(12, source.size());

assertThat((String) source.get("cluster_name"), not(isEmptyOrNullString()));
assertThat(source.get("version"), equalTo(Version.CURRENT.toString()));
Expand Down