private Map<String, Metric> flatten(Map<String, Metric> metrics, Set<MetricSet> children) {
        Map<String, Metric> joinedMetrics = new LinkedHashMap<>(metrics);

        for (MetricSet child : children) {
            child.getMetrics().forEach(
                    (name, metric) -> {
                        if (joinedMetrics.containsKey(name))
                            joinedMetrics.put(name, joinedMetrics.get(name).addDimensionsFrom(metric));
                        else
                            joinedMetrics.put(name, metric);
                    });
        }
        return joinedMetrics;
    }
Returns all metrics in this set, including all metrics in any contained metric sets.

Joins this set's metrics with its child sets into a named flat map of metrics.
In the case of duplicate metrics, the metrics directly defined in this set
takes precedence with respect to output name, description and dimension value
(even if they are empty), while new dimensions from the children will be added.

@return all the metrics contained in this set
metrics/src/main/java/ai/vespa/metrics/set/MetricSet.java