Today the stable-master health indicator reports `yellow` health if it sees the elected master change 4 times in 30 minutes. However, this could be caused by planned activity such as a rolling restart, and in that case we should not consider a sequence of master failovers as a sign of ill health.

I think we can solve this by refining this check to disregard master nodes that have restarted since they were master, or are no longer in the cluster at all. Restarting the master will always trigger a failover, and the stable-master indicator need not worry about whether the node restart was planned or not; separately, unplanned node restarts are definitely a sign of ill health, but that applies whether the node was the elected master or not. Similarly, if a node is no longer in the cluster then either it is no longer running (again, whether that's planned or not is irrelevant to the stable-master indicator) or else it is running and failing to join the cluster (and hence reporting its own ill health).
server/src/test/java/org/elasticsearch/cluster/coordination/CoordinationDiagnosticsServiceTests.java
}
        }
    }
    public void testRedForNoMasterNoQuorum() {
        /*
         * This test brings up a 4-node cluster (3 master-eligible, one not). After the cluster stabilizes, one node is elected master.
         * Then we disconnect all master nodes from all other nodes and allow the cluster to simulate running for a little longer. At
         * that point, the non-master node thinks that there are no master nodes. The two master eligible nodes that were not initially
         * elected master think that no quorum can be formed. Depending on timing, the node that had originally been elected master
         * either thinks that it is still master, or that no quorum can be formed.
         */
        try (Cluster cluster = new Cluster(4, false, Settings.EMPTY)) {
            
            createAndAddNonMasterNode(cluster);
            cluster.runRandomly();
            cluster.stabilise();
            int masterNodeCount = 0;
            for (Cluster.ClusterNode node : cluster.clusterNodes) {
                if (node.getLocalNode().isMasterNode()) {
                    node.disconnect();
                    masterNodeCount++;
                }
            }
            int redNonMasterCount = 0;
            int redMasterCount = 0;
            int greenMasterCount = 0;
            cluster.runFor(DEFAULT_STABILISATION_TIME, "Cannot call stabilise() because there is no master");
            for (Cluster.ClusterNode node : cluster.clusterNodes) {
                CoordinationDiagnosticsService.CoordinationDiagnosticsResult healthIndicatorResult = node.coordinationDiagnosticsService
                    .diagnoseMasterStability(true);