private void performPendingMetricsOperations() {
        modifyMetricsLock.lock();
        try {
            log.trace("{}: entering performPendingMetricsOperations", suiteName);
            for (PendingMetricsChange change = pending.pollLast();
                 change != null;
                 change = pending.pollLast()) {
                if (change.provider == null) {
                    if (log.isTraceEnabled()) {
                        log.trace("{}: removing metric {}", suiteName, change.metricName);
                    }
                    metrics.removeMetric(change.metricName);
                } else {
                    if (log.isTraceEnabled()) {
                        log.trace("{}: adding metric {}", suiteName, change.metricName);
                    }
                    metrics.addMetric(change.metricName, change.provider);
                }
            }
            log.trace("{}: leaving performPendingMetricsOperations", suiteName);
        } finally {
            modifyMetricsLock.unlock();
        }
    }
Perform pending metrics additions or removals.
It is important to perform them in order.  For example, we don't want to try
to remove a metric that we haven't finished adding yet.
clients/src/main/java/org/apache/kafka/common/metrics/internals/IntGaugeSuite.java