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/main/java/org/elasticsearch/cluster/coordination/MasterHistory.java
* null -> node1 -> null is 1 transition to null
     * node1 -> null -> node1 is 1 transition to null
     * node1 -> null -> node1 -> null is 2 transitions to null
     * node1 -> null -> node2 -> null is 2 transitions to null
     * @param masters The List of masters to use
     * @param n The number of times a non-null master must have switched to null
     * @return True if non-null masters have transitioned to null n or more timesin the given list of masters.
     */
    public static boolean hasMasterGoneNullAtLeastNTimes(List<DiscoveryNode> masters, int n) {
        int timesMasterHasGoneNull = 0;
        boolean previousNull = true;
        for (DiscoveryNode master : masters) {
            if (master == null) {
                if (previousNull == false) {
                    timesMasterHasGoneNull++;
                }
                previousNull = true;
            } else {
                previousNull = false;
            }
        }
        return timesMasterHasGoneNull >= n;
    }
    /**
     * An identity change is when we get notified of a change to a non-null master that is different from the previous non-null master.
     * Note that a master changes to null on (virtually) every identity change.
     * So for example:
     * node1 -> node2 is 1 identity change
     * node1 -> node2 -> node1 is 2 identity changes
     * node1 -> node2 -> node2 is 1 identity change (transitions from a node to itself do not count)