@Test
  public void customPercentilesMetricsRegistryTest() {
    // test that if custom percentile is not set, no corresponding metrics would be generated.
    MetricRegistry metricRegistry = routerMetrics.getMetricRegistry();
    MetricFilter filter = new MetricFilter() {
      @Override
      public boolean matches(String name, Metric metric) {
        return name.endsWith("thPercentile");
      }
    };
    SortedMap<String, Gauge> gauges = metricRegistry.getGauges(filter);
    assertTrue("No gauges should be created because custom percentile is not set", gauges.isEmpty());
    // test that dedicated gauges are correctly created for custom percentiles.
    String customPercentiles = "0.91,0.97";
    RouterConfig routerConfig = createRouterConfig(false, 1, 1, 6, customPercentiles, true);
    String[] percentileArray = customPercentiles.split(",");
    Arrays.sort(percentileArray);
    List<String> sortedPercentiles = Arrays.stream(percentileArray)
        .map(p -> String.valueOf(Double.parseDouble(p) * 100))
        .collect(Collectors.toList());
    routerMetrics = new NonBlockingRouterMetrics(mockClusterMap, routerConfig);
    gauges = routerMetrics.getMetricRegistry().getGauges(filter);
    // Note that each percentile creates 4 metrics (GetBlobInfo/GetBlob joins LocalColo/CrossColo). So, the total number of
    // metrics should equal to 4 * (# of given custom percentiles)
    assertEquals("The number of custom percentile gauge doesn't match", sortedPercentiles.size() * 4, gauges.size());
    Iterator mapItor = gauges.keySet().iterator();
    Iterator<String> listItor = sortedPercentiles.iterator();
    while (listItor.hasNext()) {
      String gaugeName = (String) mapItor.next();
      String percentileStr = listItor.next();
      assertTrue("The gauge name doesn't match", gaugeName.endsWith(percentileStr + ".thPercentile"));
    }
    // reset router metrics to clean up registered custom percentile metrics
    routerMetrics = new NonBlockingRouterMetrics(mockClusterMap, defaultRouterConfig);
  }
Test that {@link NonBlockingRouterMetrics} can correctly register custom percentiles. An example of metric name is:
"com.github.ambry.router.GetOperation.LocalColoLatencyMs.91.0.thPercentile"
ambry-router/src/test/java/com/github/ambry/router/AdaptiveOperationTrackerTest.java