private static List<MetricsPacket.Builder> toNodePackets(GenericNode node) {
        List<MetricsPacket.Builder> packets = new ArrayList<>();
        if (node == null) return packets;

        if (node.metrics == null || node.metrics.isEmpty()) {
            return List.of(new MetricsPacket.Builder(VESPA_NODE_SERVICE_ID)
                                         .statusCode(StatusCode.UP.ordinal())
                                         .timestamp(node.timeAsInstant()));
        }

        for (var genericMetrics : node.metrics) {
            var packet = new MetricsPacket.Builder(VESPA_NODE_SERVICE_ID)
                    .statusCode(StatusCode.UP.ordinal())
                    .timestamp(node.timeAsInstant());
            addMetrics(genericMetrics, packet);
            packets.add(packet);
        }
        return packets;
    }
Utilities for converting between metrics packets and the generic json format.

@author gjoranv
metrics-proxy/src/main/java/ai/vespa/metricsproxy/metric/model/json/GenericJsonUtil.java