@Override
    public MetricsConfig build() {
        MetricsConfig metrics = new MetricsConfig();
        super.build(metrics);

        metrics.setProtocol(protocol);
        metrics.setEnableJvm(enableJvm);
        metrics.setEnableThreadpool(enableThreadpool);
        metrics.setEnableRegistry(enableRegistry);
        metrics.setEnableMetadata(enableMetadata);
        metrics.setExportMetricsService(exportMetricsService);
        metrics.setEnableMetricsInit(enableMetricsInit);
        metrics.setEnableCollectorSync(enableCollectorSync);
        metrics.setCollectorSyncPeriod(collectorSyncPeriod);
        metrics.setPrometheus(prometheus);
        metrics.setAggregation(aggregation);
        metrics.setHistogram(histogram);
        metrics.setExportServiceProtocol(exportServiceProtocol);
        metrics.setExportServicePort(exportServicePort);
        metrics.setUseGlobalRegistry(useGlobalRegistry);
        metrics.setEnableRpc(enableRpc);
        metrics.setRpcLevel(rpcLevel);
        return metrics;
    }
@Test
    void build() {
        PrometheusConfig.Exporter exporter = new PrometheusConfig.Exporter();
        exporter.setEnabled(true);
        exporter.setEnableHttpServiceDiscovery(true);
        exporter.setHttpServiceDiscoveryUrl("localhost:8080");

        PrometheusConfig.Pushgateway pushGateway = new PrometheusConfig.Pushgateway();
        pushGateway.setEnabled(true);
        pushGateway.setBaseUrl("localhost:9091");
        pushGateway.setUsername("username");
        pushGateway.setPassword("password");
        pushGateway.setJob("job");
        pushGateway.setPushInterval(30);

        PrometheusConfig prometheus = new PrometheusConfig();
        prometheus.setExporter(exporter);
        prometheus.setPushgateway(pushGateway);

        HistogramConfig histogram = new HistogramConfig();
        histogram.setEnabled(true);
        histogram.setMaxExpectedMs(1000);
        histogram.setBucketsMs(new Integer[] {100, 200, 300, 400, 500});
        histogram.setPercentiles(new double[] {0.5, 0.9, 0.95, 0.99});

        AggregationConfig aggregation = new AggregationConfig();
        aggregation.setEnabled(true);
        aggregation.setEnableQps(false);
        aggregation.setBucketNum(100);

        MetricsBuilder builder = MetricsBuilder.newBuilder();
        builder.protocol("test")
                .enableJvm(true)
                .enableThreadPool(true)
                .enableRegistry(false)
                .enableMetadata(false)
                .exportMetricsService(true)
                .enableMetricsInit(false)
                .enableCollectorSync(true)
                .collectorSyncPeriod(10)
                .prometheus(prometheus)
                .histogram(histogram)
                .aggregation(aggregation)
                .exportServiceProtocol("tri")
                .exportServicePort(10010)
                .useGlobalRegistry(true)
                .enableRpc(true)
                .rpcLevel("METHOD");

        MetricsConfig config = builder.build();
        MetricsConfig config2 = builder.build();

        Assertions.assertEquals("test", config.getProtocol());
        Assertions.assertTrue(config.getEnableJvm());
        Assertions.assertTrue(config.getEnableThreadpool());
        Assertions.assertFalse(config.getEnableRegistry());
        Assertions.assertFalse(config.getEnableMetadata());
        Assertions.assertTrue(config.getExportMetricsService());
        Assertions.assertFalse(config.getEnableMetricsInit());
        Assertions.assertTrue(config.getEnableCollectorSync());
        Assertions.assertEquals(10, config.getCollectorSyncPeriod());
        Assertions.assertSame(prometheus, config.getPrometheus());
        Assertions.assertSame(exporter, config.getPrometheus().getExporter());
        Assertions.assertSame(pushGateway, config.getPrometheus().getPushgateway());
        Assertions.assertTrue(config.getPrometheus().getExporter().getEnabled());
        Assertions.assertTrue(config.getPrometheus().getExporter().getEnableHttpServiceDiscovery());
        Assertions.assertEquals(
                "localhost:8080", config.getPrometheus().getExporter().getHttpServiceDiscoveryUrl());
        Assertions.assertTrue(config.getPrometheus().getPushgateway().getEnabled());
        Assertions.assertEquals(
                "localhost:9091", config.getPrometheus().getPushgateway().getBaseUrl());
        Assertions.assertEquals(
                "username", config.getPrometheus().getPushgateway().getUsername());
        Assertions.assertEquals(
                "password", config.getPrometheus().getPushgateway().getPassword());
        Assertions.assertEquals("job", config.getPrometheus().getPushgateway().getJob());
        Assertions.assertEquals(30, config.getPrometheus().getPushgateway().getPushInterval());
        Assertions.assertSame(histogram, config.getHistogram());
        Assertions.assertTrue(config.getHistogram().getEnabled());
        Assertions.assertEquals(1000, config.getHistogram().getMaxExpectedMs());
        Assertions.assertArrayEquals(
                new Integer[] {100, 200, 300, 400, 500}, config.getHistogram().getBucketsMs());
        Assertions.assertArrayEquals(
                new double[] {0.5, 0.9, 0.95, 0.99}, config.getHistogram().getPercentiles());
        Assertions.assertSame(aggregation, config.getAggregation());
        Assertions.assertTrue(config.getAggregation().getEnabled());
        Assertions.assertFalse(config.getAggregation().getEnableQps());
        Assertions.assertEquals(100, config.getAggregation().getBucketNum());
        Assertions.assertEquals("tri", config.getExportServiceProtocol());
        Assertions.assertEquals(10010, config.getExportServicePort());
        Assertions.assertTrue(config.getUseGlobalRegistry());
        Assertions.assertTrue(config.getEnableRpc());
        Assertions.assertEquals("METHOD", config.getRpcLevel());
        Assertions.assertNotSame(config, config2);
    }