@Test public void testSamplesInOrder() { RecordingStat<Integer> statA = mockedStat(); RecordingStat<Integer> statB = mockedStat(); RecordingStat<Integer> statC = mockedStat(); RecordingStat<Integer> statD = mockedStat(); expect(statRegistry.getStats()) .andReturn(ImmutableList.<RecordingStat<? extends Number>>of(statB, statA, statC, statD)); expect(statB.getName()).andReturn("statB"); expect(statB.sample()).andReturn(1); expect(statA.getName()).andReturn("statA"); expect(statA.sample()).andReturn(2); expect(statC.getName()).andReturn("statC"); expect(statC.sample()).andReturn(3); expect(statD.getName()).andReturn("statD"); expect(statD.sample()).andReturn(4); control.replay(); repo.runSampler(clock); }
@VisibleForTesting synchronized void runSampler(Clock clock) { timestamps.add(clock.nowMillis()); long startNanos = clock.nowNanos(); for (RecordingStat<? extends Number> var : statRegistry.getStats()) { timeSeries.getUnchecked(var.getName()).addSample(var.sample()); } scrapeDuration.accumulate( Amount.of(clock.nowNanos() - startNanos, Time.NANOSECONDS).as(Time.MICROSECONDS)); }
TimeSeriesRepositoryImpl extends AbstractScheduledService implements TimeSeriesRepository { @VisibleForTesting synchronized void runSampler(Clock clock) { timestamps.add(clock.nowMillis()); long startNanos = clock.nowNanos(); for (RecordingStat<? extends Number> var : statRegistry.getStats()) { timeSeries.getUnchecked(var.getName()).addSample(var.sample()); } scrapeDuration.accumulate( Amount.of(clock.nowNanos() - startNanos, Time.NANOSECONDS).as(Time.MICROSECONDS)); } }
TimeSeriesRepositoryImpl extends AbstractScheduledService implements TimeSeriesRepository { @VisibleForTesting synchronized void runSampler(Clock clock) { timestamps.add(clock.nowMillis()); long startNanos = clock.nowNanos(); for (RecordingStat<? extends Number> var : statRegistry.getStats()) { timeSeries.getUnchecked(var.getName()).addSample(var.sample()); } scrapeDuration.accumulate( Amount.of(clock.nowNanos() - startNanos, Time.NANOSECONDS).as(Time.MICROSECONDS)); } @Inject  TimeSeriesRepositoryImpl(
      StatRegistry statRegistry,
      @Named(SAMPLE_PERIOD) Amount<Long, Time> samplePeriod,
      @Named(SAMPLE_RETENTION_PERIOD) final Amount<Long, Time> retentionPeriod,
      BuildInfo buildInfo); }
TimeSeriesRepositoryImpl extends AbstractScheduledService implements TimeSeriesRepository { @VisibleForTesting synchronized void runSampler(Clock clock) { timestamps.add(clock.nowMillis()); long startNanos = clock.nowNanos(); for (RecordingStat<? extends Number> var : statRegistry.getStats()) { timeSeries.getUnchecked(var.getName()).addSample(var.sample()); } scrapeDuration.accumulate( Amount.of(clock.nowNanos() - startNanos, Time.NANOSECONDS).as(Time.MICROSECONDS)); } @Inject  TimeSeriesRepositoryImpl(
      StatRegistry statRegistry,
      @Named(SAMPLE_PERIOD) Amount<Long, Time> samplePeriod,
      @Named(SAMPLE_RETENTION_PERIOD) final Amount<Long, Time> retentionPeriod,
      BuildInfo buildInfo); @Override synchronized Set<String> getAvailableSeries(); @Override synchronized TimeSeries get(String name); @Override synchronized Iterable<Number> getTimestamps(); }
TimeSeriesRepositoryImpl extends AbstractScheduledService implements TimeSeriesRepository { @VisibleForTesting synchronized void runSampler(Clock clock) { timestamps.add(clock.nowMillis()); long startNanos = clock.nowNanos(); for (RecordingStat<? extends Number> var : statRegistry.getStats()) { timeSeries.getUnchecked(var.getName()).addSample(var.sample()); } scrapeDuration.accumulate( Amount.of(clock.nowNanos() - startNanos, Time.NANOSECONDS).as(Time.MICROSECONDS)); } @Inject  TimeSeriesRepositoryImpl(
      StatRegistry statRegistry,
      @Named(SAMPLE_PERIOD) Amount<Long, Time> samplePeriod,
      @Named(SAMPLE_RETENTION_PERIOD) final Amount<Long, Time> retentionPeriod,
      BuildInfo buildInfo); @Override synchronized Set<String> getAvailableSeries(); @Override synchronized TimeSeries get(String name); @Override synchronized Iterable<Number> getTimestamps(); static final String SAMPLE_PERIOD; static final String SAMPLE_RETENTION_PERIOD; }