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
assertThat(healthIndicatorResult.summary(), containsString("received an exception"));
            }
            while (cluster.clusterNodes.stream().anyMatch(Cluster.ClusterNode::deliverBlackholedRequests)) {
                logger.debug("--> stabilising again after delivering blackholed requests");
                cluster.runFor(DEFAULT_STABILISATION_TIME, "Cannot call stabilise() because there is no master");
            }
        }
    }
    public void testYellowWithTooManyMasterChanges() {
        testChangeMasterThreeTimes(2, 100, "The elected master node has changed");
    }
    public void testYellowWithTooManyMasterNullTransitions() {
        testChangeMasterThreeTimes(100, 2, "no master multiple times");
    }
    private void testChangeMasterThreeTimes(int acceptableIdentityChanges, int acceptableNullTransitions, String expectedSummarySubstring) {
        int clusterSize = 5;
        int masterChanges = 3;
        Settings settings = Settings.builder()
            .put(CoordinationDiagnosticsService.IDENTITY_CHANGES_THRESHOLD_SETTING.getKey(), acceptableIdentityChanges)
            .put(CoordinationDiagnosticsService.NO_MASTER_TRANSITIONS_THRESHOLD_SETTING.getKey(), acceptableNullTransitions)
            .build();
        try (Cluster cluster = new Cluster(clusterSize, true, settings)) {
            cluster.runRandomly();
            cluster.stabilise();
            
            for (int i = 0; i < masterChanges; i++) {
                final Cluster.ClusterNode leader = cluster.getAnyLeader();
                logger.info("--> blackholing leader {}", leader);
                leader.disconnect();
                cluster.stabilise();