public synchronized KafkaMetric removeMetric(MetricName metricName) {
        KafkaMetric metric = this.metrics.remove(metricName);
        if (metric != null) {
            for (MetricsReporter reporter : reporters) {
                try {
                    reporter.metricRemoval(metric);
                } catch (Exception e) {
                    log.error("Error when removing metric from " + reporter.getClass().getName(), e);
                }
            }
            log.trace("Removed metric named {}", metricName);
        }
        return metric;
    }
Remove a metric if it exists and return it. Return null otherwise. If a metric is removed, `metricRemoval`
will be invoked for each reporter.

@param metricName The name of the metric
@return the removed `KafkaMetric` or null if no such metric exists
clients/src/main/java/org/apache/kafka/common/metrics/Metrics.java