Skip to content

Commit 2a4bcf0

Browse files
authored
Ensure default watches are updated for rolling upgrades. (#57185)
For a rolling/mixed cluster upgrade (add new version to existing cluster then shutdown old instances), the watches that ship by default with monitoring may not get properly updated to the new version. Monitoring watches can only get published if the internal state is marked as dirty. If a node is not master, will also get marked as clean (e.g. not dirty). For a mixed cluster upgrade, it is possible for the new node to be added, not as master, the internal state gets marked as clean so that no more attempts can be made to publish the watches. This happens on all new nodes. Once the old nodes are de-commissioned one of the new version nodes in the cluster gets promoted to master. However, that new master node (with out intervention like restarting the node or removing/adding exporters) will never attempt to re-publish since the internal state was already marked as clean. This commit adds a cluster state listener to mark the resource dirty when a node is promoted to master. This will allow the new resource to be published without any intervention.
1 parent 62e2778 commit 2a4bcf0

File tree

1 file changed

+12
-1
lines changed
  • x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/exporter/http

1 file changed

+12
-1
lines changed

x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/exporter/http/HttpExporter.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.elasticsearch.client.RestClientBuilder;
2222
import org.elasticsearch.client.sniff.ElasticsearchNodesSniffer;
2323
import org.elasticsearch.client.sniff.Sniffer;
24+
import org.elasticsearch.cluster.ClusterStateListener;
2425
import org.elasticsearch.cluster.service.ClusterService;
2526
import org.elasticsearch.common.Nullable;
2627
import org.elasticsearch.common.Strings;
@@ -363,7 +364,7 @@ public Iterator<Setting<?>> settings() {
363364
private static final ConcurrentHashMap<String, SecureString> SECURE_AUTH_PASSWORDS = new ConcurrentHashMap<>();
364365
private final ThreadContext threadContext;
365366
private final DateFormatter dateTimeFormatter;
366-
367+
private final ClusterStateListener onLocalMasterListener;
367368
/**
368369
* Create an {@link HttpExporter}.
369370
*
@@ -424,6 +425,14 @@ public HttpExporter(final Config config, final SSLService sslService, final Thre
424425

425426
// mark resources as dirty after any node failure or license change
426427
listener.setResource(resource);
428+
429+
//for a mixed cluster upgrade, ensure that if master changes and this is the master, allow the resources to re-publish
430+
onLocalMasterListener = clusterChangedEvent -> {
431+
if (clusterChangedEvent.nodesDelta().masterNodeChanged() && clusterChangedEvent.localNodeMaster()) {
432+
resource.markDirty();
433+
}
434+
};
435+
config.clusterService().addListener(onLocalMasterListener);
427436
}
428437

429438
/**
@@ -864,9 +873,11 @@ public void openBulk(final ActionListener<ExportBulk> listener) {
864873
@Override
865874
public void doClose() {
866875
try {
876+
config.clusterService().removeListener(onLocalMasterListener);
867877
if (sniffer != null) {
868878
sniffer.close();
869879
}
880+
870881
} catch (Exception e) {
871882
logger.error("an error occurred while closing the internal client sniffer", e);
872883
} finally {

0 commit comments

Comments
 (0)