private static Optional<String> toMBeanName(LinkedHashMap<String, String> tags) {
        if (tags == null) {
            return Optional.empty();
        }

        LinkedHashMap<String, String> nonEmptyTags = collectNonEmptyTags(tags, LinkedHashMap::new);
        if (nonEmptyTags.isEmpty()) {
            return Optional.empty();
        } else {
            StringBuilder tagsString = new StringBuilder();
            for (Map.Entry<String, String> tagEntry : nonEmptyTags.entrySet()) {
                String sanitizedValue = Sanitizer.jmxSanitize(tagEntry.getValue());
                tagsString.append(",");
                tagsString.append(tagEntry.getKey());
                tagsString.append("=");
                tagsString.append(sanitizedValue);
            }
            return Optional.of(tagsString.toString());
        }
    }
convenience method to replace {@link com.yammer.metrics.Metrics#defaultRegistry()}
server-common/src/main/java/org/apache/kafka/server/metrics/KafkaYammerMetrics.java