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
long nSecondsAgo = now - nSecondsTimeValue.getMillis();
        /*
         * We traverse the list backwards (since it is ordered by time ascending). Once we find an entry whose
         * timeAndMaster.startTimeMillis was more than nSeconds ago we can stop because it is not possible that any more of the nodes
         * we'll see have ended within the last nSeconds.
         */
        for (int i = masterHistoryCopy.size() - 1; i >= 0; i--) {
            TimeAndMaster timeAndMaster = masterHistoryCopy.get(i);
            if (timeAndMaster.master != null) {
                return true;
            }
            if (timeAndMaster.startTimeMillis < nSecondsAgo) {
                break;
            }
        }
        return false;
    }
    /*
     * This method creates a mutable copy of masterHistory that only has entries that have been active in the recent past
     * (maxHistoryAge). In this case, "active" means that either the master's start time has been within maxHistoryAge, or the master was
     *  replaced by another master within maxHistoryAge.
     */
    private List<TimeAndMaster> getRecentMasterHistory(List<TimeAndMaster> history) {
        if (history.size() < 2) {
            return history;
        }
        long now = currentTimeMillisSupplier.getAsLong();
        long oldestRelevantHistoryTime = now - maxHistoryAge.getMillis();
        List<TimeAndMaster> filteredHistory = new ArrayList<>();
        for (int i = 0; i < history.size(); i++) {