Skip to content

Commit

Permalink
[7.x] Ensure default watches are updated for rolling upgrades. (elast…
Browse files Browse the repository at this point in the history
…ic#57185) (elastic#57563)

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.
  • Loading branch information
jakelandis authored Jun 4, 2020
1 parent dfb6def commit f4a3d96
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.sniff.ElasticsearchNodesSniffer;
import org.elasticsearch.client.sniff.Sniffer;
import org.elasticsearch.cluster.ClusterStateListener;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.Strings;
Expand Down Expand Up @@ -415,7 +416,7 @@ public Iterator<Setting<?>> settings() {
private static final ConcurrentHashMap<String, SecureString> SECURE_AUTH_PASSWORDS = new ConcurrentHashMap<>();
private final ThreadContext threadContext;
private final DateFormatter dateTimeFormatter;

private final ClusterStateListener onLocalMasterListener;
/**
* Create an {@link HttpExporter}.
*
Expand Down Expand Up @@ -476,6 +477,14 @@ public HttpExporter(final Config config, final SSLService sslService, final Thre

// mark resources as dirty after any node failure or license change
listener.setResource(resource);

//for a mixed cluster upgrade, ensure that if master changes and this is the master, allow the resources to re-publish
onLocalMasterListener = clusterChangedEvent -> {
if (clusterChangedEvent.nodesDelta().masterNodeChanged() && clusterChangedEvent.localNodeMaster()) {
resource.markDirty();
}
};
config.clusterService().addListener(onLocalMasterListener);
}

/**
Expand Down Expand Up @@ -935,9 +944,11 @@ public void openBulk(final ActionListener<ExportBulk> listener) {
@Override
public void doClose() {
try {
config.clusterService().removeListener(onLocalMasterListener);
if (sniffer != null) {
sniffer.close();
}

} catch (Exception e) {
logger.error("an error occurred while closing the internal client sniffer", e);
} finally {
Expand Down

0 comments on commit f4a3d96

Please sign in to comment.