public static void generate(String cluster, OutputStream out,
                                List<PrometheusRawMetricsProvider> metricsProviders)
            throws IOException {
        ByteBuf buf = PulsarByteBufAllocator.DEFAULT.heapBuffer();
        try {
            SimpleTextOutputStream stream = new SimpleTextOutputStream(buf);
            generateSystemMetrics(stream, cluster);
            if (metricsProviders != null) {
                for (PrometheusRawMetricsProvider metricsProvider : metricsProviders) {
                    metricsProvider.generate(stream);
                }
            }
            out.write(buf.array(), buf.arrayOffset(), buf.readableBytes());
        } finally {
            buf.release();
        }
    }
@Test
    public void testGenerateSystemMetricsWithSpecifyCluster() throws Exception {
        String defaultClusterValue = "cluster_test";
        String specifyClusterValue = "lb_x";
        String metricsName = "label_contains_cluster" + randomString();
        Counter counter = new Counter.Builder()
                .name(metricsName)
                .labelNames(LABEL_NAME_CLUSTER)
                .help("x")
                .register(CollectorRegistry.defaultRegistry);
        counter.labels(specifyClusterValue).inc();
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        PrometheusMetricsGeneratorUtils.generate(defaultClusterValue, out,  Collections.emptyList());
        assertTrue(out.toString().contains(
                String.format("%s_total{cluster=\"%s\"} 1.0", metricsName, specifyClusterValue)
        ));
        // cleanup
        out.close();
        CollectorRegistry.defaultRegistry.unregister(counter);
    }