### Question:
PrometheusMetricsSystem implements ObservableMetricsSystem { @Override public Stream<Observation> streamObservations(final MetricCategory category) { return collectors.getOrDefault(category, Collections.emptySet()).stream() .flatMap(collector -> collector.collect().stream()) .flatMap(familySamples -> convertSamplesToObservations(category, familySamples)); } PrometheusMetricsSystem(
      final Set<MetricCategory> enabledCategories, final boolean timersEnabled); static ObservableMetricsSystem init(final MetricsConfiguration metricsConfiguration); @Override LabelledMetric<org.hyperledger.besu.plugin.services.metrics.Counter> createLabelledCounter(
      final MetricCategory category,
      final String name,
      final String help,
      final String... labelNames); @Override LabelledMetric<OperationTimer> createLabelledTimer(
      final MetricCategory category,
      final String name,
      final String help,
      final String... labelNames); @Override void createGauge(
      final MetricCategory category,
      final String name,
      final String help,
      final DoubleSupplier valueSupplier); void addCollector(final MetricCategory category, final Collector metric); @Override Stream<Observation> streamObservations(final MetricCategory category); @Override Stream<Observation> streamObservations(); String convertToPrometheusName(final MetricCategory category, final String name);  }### Answer:
@Test public void shouldCreateObservationFromCounter() { final Counter counter = metricsSystem.createCounter(PEERS, "connected", "Some help string"); counter.inc(); assertThat(metricsSystem.streamObservations()) .containsExactly(new Observation(PEERS, "connected", 1d, emptyList())); counter.inc(); assertThat(metricsSystem.streamObservations()) .containsExactly(new Observation(PEERS, "connected", 2d, emptyList())); }
@Test public void shouldIncrementCounterBySpecifiedAmount() { final Counter counter = metricsSystem.createCounter(PEERS, "connected", "Some help string"); counter.inc(5); assertThat(metricsSystem.streamObservations()) .containsExactly(new Observation(PEERS, "connected", 5d, emptyList())); counter.inc(6); assertThat(metricsSystem.streamObservations()) .containsExactly(new Observation(PEERS, "connected", 11d, emptyList())); }
@Test public void shouldCreateObservationsFromTimer() { final OperationTimer timer = metricsSystem.createTimer(RPC, "request", "Some help"); final OperationTimer.TimingContext context = timer.startTimer(); context.stopTimer(); assertThat(metricsSystem.streamObservations()) .usingElementComparator(IGNORE_VALUES) .containsExactlyInAnyOrder( new Observation(RPC, "request", null, asList("quantile", "0.2")), new Observation(RPC, "request", null, asList("quantile", "0.5")), new Observation(RPC, "request", null, asList("quantile", "0.8")), new Observation(RPC, "request", null, asList("quantile", "0.95")), new Observation(RPC, "request", null, asList("quantile", "0.99")), new Observation(RPC, "request", null, asList("quantile", "1.0")), new Observation(RPC, "request", null, singletonList("sum")), new Observation(RPC, "request", null, singletonList("count"))); }