@VisibleForTesting
    static void instantiateGarbageCollectorMetrics(
            MetricGroup metrics, List<GarbageCollectorMXBean> garbageCollectors) {
        for (final GarbageCollectorMXBean garbageCollector : garbageCollectors) {
            MetricGroup gcGroup = metrics.addGroup(garbageCollector.getName());

            gcGroup.gauge("Count", garbageCollector::getCollectionCount);
            Gauge<Long> timeGauge = gcGroup.gauge("Time", garbageCollector::getCollectionTime);
            gcGroup.meter("TimeMsPerSecond", new MeterView(timeGauge));
        }
        Gauge<Long> totalGcTime =
                () ->
                        garbageCollectors.stream()
                                .mapToLong(GarbageCollectorMXBean::getCollectionTime)
                                .sum();

        Gauge<Long> totalGcCount =
                () ->
                        garbageCollectors.stream()
                                .mapToLong(GarbageCollectorMXBean::getCollectionCount)
                                .sum();

        MetricGroup allGroup = metrics.addGroup("All");
        allGroup.gauge("Count", totalGcCount);
        Gauge<Long> totalTime = allGroup.gauge("Time", totalGcTime);
        allGroup.meter("TimeMsPerSecond", new MeterView(totalTime));
    }
@Test
    public void testGcMetricCompleteness() {
        Map<String, InterceptingOperatorMetricGroup> addedGroups = new HashMap<>();
        InterceptingOperatorMetricGroup gcGroup =
                new InterceptingOperatorMetricGroup() {
                    @Override
                    public MetricGroup addGroup(String name) {
                        return addedGroups.computeIfAbsent(
                                name, k -> new InterceptingOperatorMetricGroup());
                    }
                };

        List<GarbageCollectorMXBean> garbageCollectors = new ArrayList<>();
        garbageCollectors.add(new TestGcBean("gc1", 100, 500));
        garbageCollectors.add(new TestGcBean("gc2", 50, 250));

        MetricUtils.instantiateGarbageCollectorMetrics(gcGroup, garbageCollectors);
        assertThat(addedGroups).containsOnlyKeys("gc1", "gc2", "All");

        // Make sure individual collector metrics are correct
        validateCollectorMetric(addedGroups.get("gc1"), 100, 500L);
        validateCollectorMetric(addedGroups.get("gc2"), 50L, 250L);

        // Make sure all/total collector metrics are correct
        validateCollectorMetric(addedGroups.get("All"), 150L, 750L);
    }