public static MetricSnapshots convert(List<MatchedRule> matchedRules) {
        Map<String, List<MatchedRule>> rulesByPrometheusMetricName = new HashMap<>();

        for (MatchedRule matchedRule : matchedRules) {
            List<MatchedRule> matchedRulesWithSameName =
                    rulesByPrometheusMetricName.computeIfAbsent(
                            matchedRule.name, name -> new ArrayList<>());
            matchedRulesWithSameName.add(matchedRule);
        }

        if (LOGGER.isLoggable(Level.FINE)) {
            rulesByPrometheusMetricName
                    .values()
                    .forEach(
                            matchedRules1 ->
                                    matchedRules1.forEach(
                                            matchedRule ->
                                                    LOGGER.log(
                                                            Level.FINE,
                                                            "matchedRule %s",
                                                            matchedRule)));
        }

        MetricSnapshots.Builder result = MetricSnapshots.builder();
        for (List<MatchedRule> rulesWithSameName : rulesByPrometheusMetricName.values()) {
            result.metricSnapshot(convertRulesWithSameName(rulesWithSameName));
        }
        return result.build();
    }
@Test
    public void testMatchedRuleAggregation() {
        List<MatchedRule> matchedRules = new ArrayList<>();

        matchedRules.add(
                new MatchedRule(
                        "jvm_memory_committed_bytes",
                        "java.lang<type=Memory><HeapMemoryUsage>committed: 16252928",
                        "UNKNOWN",
                        "java.lang.management.MemoryUsage"
                                + " java.lang:name=null,type=Memory,attribute=committed",
                        of("area"),
                        of("heap"),
                        1.6252928E7,
                        1.0));

        matchedRules.add(
                new MatchedRule(
                        "jvm_memory_committed_bytes",
                        "java.lang<type=Memory><NonHeapMemoryUsage>committed: 17170432",
                        "UNKNOWN",
                        "java.lang.management.MemoryUsage"
                                + " java.lang:name=null,type=Memory,attribute=committed",
                        of("area"),
                        of("nonheap"),
                        2.1757952E7,
                        1.0));

        MetricSnapshots metricSnapshots =
                MatchedRuleToMetricSnapshotsConverter.convert(matchedRules);

        assertThat(metricSnapshots).hasSize(1);

        metricSnapshots.forEach(
                metricSnapshot -> {
                    MetricMetadata metricMetadata = metricSnapshot.getMetadata();

                    assertThat(metricMetadata.getName()).isEqualTo("jvm_memory_committed_bytes");
                    assertThat(metricMetadata.getPrometheusName())
                            .isEqualTo("jvm_memory_committed_bytes");

                    List<? extends DataPointSnapshot> dataPointSnapshots =
                            metricSnapshot.getDataPoints();
                    assertThat(dataPointSnapshots).hasSize(2);
                });
    }