@VisibleForTesting
  public static void updateMetricsFromShowCompact(ShowCompactResponse showCompactResponse) {
    CompactionMetricData metricData = CompactionMetricData.of(showCompactResponse.getCompacts());

    // Get the current count for each state
    Map<String, Long> counts = metricData.getStateCount();

    // Update metrics
    for (int i = 0; i < TxnStore.COMPACTION_STATES.length; ++i) {
      String key = COMPACTION_STATUS_PREFIX + replaceWhitespace(TxnStore.COMPACTION_STATES[i]);
      Long count = counts.get(TxnStore.COMPACTION_STATES[i]);
      if (count != null) {
        Metrics.getOrCreateGauge(key)
            .set(count.intValue());
      } else {
        Metrics.getOrCreateGauge(key)
            .set(0);
      }
    }

    Metrics.getOrCreateMapMetrics(COMPACTION_POOLS_INITIATED_ITEM_COUNT).update(metricData.getInitiatedCountPerPool());
    Metrics.getOrCreateMapMetrics(COMPACTION_POOLS_WORKING_ITEM_COUNT).update(metricData.getWorkingCountPerPool());
    Metrics.getOrCreateMapMetrics(COMPACTION_POOLS_OLDEST_INITIATED_AGE).update(metricData.getLongestEnqueueDurationPerPool());
    Metrics.getOrCreateMapMetrics(COMPACTION_POOLS_OLDEST_WORKING_AGE).update(metricData.getLongestWorkingDurationPerPool());

    updateOldestCompactionMetric(COMPACTION_OLDEST_ENQUEUE_AGE, metricData.getOldestEnqueueTime());
    updateOldestCompactionMetric(COMPACTION_OLDEST_WORKING_AGE, metricData.getOldestWorkingTime());
    updateOldestCompactionMetric(COMPACTION_OLDEST_CLEANING_AGE, metricData.getOldestCleaningTime());

    Metrics.getOrCreateGauge(COMPACTION_NUM_INITIATORS)
        .set((int) metricData.getInitiatorsCount());
    Metrics.getOrCreateGauge(COMPACTION_NUM_WORKERS)
        .set((int) metricData.getWorkersCount());

    Metrics.getOrCreateGauge(COMPACTION_NUM_INITIATOR_VERSIONS)
        .set((int) metricData.getInitiatorVersionsCount());
    Metrics.getOrCreateGauge(COMPACTION_NUM_WORKER_VERSIONS)
        .set((int) metricData.getWorkerVersionsCount());
  }
Collect and publish ACID and compaction related metrics.
Everything should be behind 2 feature flags: {@link MetastoreConf.ConfVars#METRICS_ENABLED} and
{@link MetastoreConf.ConfVars#METASTORE_ACIDMETRICS_THREAD_ON}.
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/metrics/AcidMetricService.java