public static MapMetrics getOrCreateMapMetrics(String name) {
    if (self == null) {
      return dummyMapMetrics;
    }

    Map<String, Metric> metrics = self.registry.getMetrics();
    Metric map = metrics.get(name);
    if (map instanceof MapMetrics) {
      return (MapMetrics) map;
    }

    // Looks like it doesn't exist.  Lock so that two threads don't create it at once.
    synchronized (Metrics.class) {
      // Recheck to make sure someone didn't create it while we waited.
      map = self.registry
          .getMetrics()
          .get(name);
      if (map instanceof MapMetrics) {
        return (MapMetrics) map;
      }

      try {
        self.registry.register(name, new MapMetrics());
      } catch (IllegalArgumentException e) {
        // HIVE-25959: The registry's register function will call the MetricRegistry#onMetricAdded
        //   which forward the call to the MetricRegistry#notifyListenerOfAddedMetric method.
        // This method will throw an IllegalArgumentException because our custom MapMetrics type not supported
        //   to avoid this we handle this.
        if (!e.getMessage().contains("Unknown metric type")) {
          throw new IllegalArgumentException("Failed to register metric", e);
        }
      }
      map = self.registry
          .getMetrics()
          .get(name);
      if (map instanceof MapMetrics) {
        return (MapMetrics) map;
      }
      return dummyMapMetrics;
    }
  }
Get a Map that represents a multi-field metric,
or create a new one if it does not already exist.
@param name Name of map metric.  This should come from MetricConstants
@return MapMetric .
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/metrics/Metrics.java