@VisibleForTesting static void unsafeResetExporter() { synchronized (monitor) { if (instance != null) { instance.intervalMetricReader.stop(); } instance = null; } } }
@Test public void intervalExport() { FakeMetricExporter fakeMetricExporter = new FakeMetricExporter(); IntervalMetricReader intervalMetricReader = IntervalMetricReader.create( fakeMetricExporter, MetricReader.create( MetricReader.Options.builder() .setMetricProducerManager(metricProducerManager) .build()), IntervalMetricReader.Options.builder() .setExportInterval(Duration.create(0, (int) MILLISECONDS.toNanos(100))) .build()); assertThat(fakeMetricExporter.waitForNumberOfExports(1)) .containsExactly(Collections.singletonList(METRIC)); assertThat(fakeMetricExporter.waitForNumberOfExports(2)) .containsExactly(Collections.singletonList(METRIC), Collections.singletonList(METRIC)); intervalMetricReader.stop(); }
private SignalFxStatsExporter( SignalFxStatsConfiguration configuration, MetricProducerManager metricProducerManager) { this.configuration = Preconditions.checkNotNull(configuration, "configuration"); this.intervalMetricReader = IntervalMetricReader.create( new SignalFxMetricExporter( SignalFxMetricsSenderFactory.DEFAULT, configuration.getIngestEndpoint(), configuration.getToken()), MetricReader.create( MetricReader.Options.builder() .setMetricProducerManager(metricProducerManager) .setSpanName(EXPORTER_SPAN_NAME) .build()), IntervalMetricReader.Options.builder() .setExportInterval(configuration.getExportInterval()) .build()); }
/** * Creates a new {@link IntervalMetricReader}. * * @param metricExporter the {@link MetricExporter} to be called after. * @param metricReader the {@link MetricReader} to be used to read metrics. * @param options the {@link Options} for the new {@link IntervalMetricReader}. * @return a new {@link IntervalMetricReader}. * @since 0.19 */ public static IntervalMetricReader create( MetricExporter metricExporter, MetricReader metricReader, Options options) { checkNotNull(options, "options"); Duration exportInterval = checkNotNull(options.getExportInterval(), "exportInterval"); checkArgument(exportInterval.compareTo(ZERO) > 0, "Export interval must be positive"); return new IntervalMetricReader( new Worker( checkNotNull(metricExporter, "metricExporter"), exportInterval.toMillis(), checkNotNull(metricReader, "metricReader"))); }
@Test public void exportAfterStop() { FakeMetricExporter fakeMetricExporter = new FakeMetricExporter(); IntervalMetricReader intervalMetricReader = IntervalMetricReader.create( fakeMetricExporter, MetricReader.create( MetricReader.Options.builder() .setMetricProducerManager(metricProducerManager) .build()), IntervalMetricReader.Options.builder() .setExportInterval(Duration.create(10, 0)) .build()); // Rely that this will be called in less than 10 seconds. intervalMetricReader.stop(); assertThat(fakeMetricExporter.waitForNumberOfExports(1)) .containsExactly(Collections.singletonList(METRIC)); } }
private StackdriverStatsExporter( String projectId, MetricServiceClient metricServiceClient, Duration exportInterval, MonitoredResource monitoredResource, @Nullable String metricNamePrefix) { IntervalMetricReader.Options.Builder intervalMetricReaderOptionsBuilder = IntervalMetricReader.Options.builder(); if (exportInterval != null) { intervalMetricReaderOptionsBuilder.setExportInterval(exportInterval); } intervalMetricReader = IntervalMetricReader.create( new CreateMetricDescriptorExporter( projectId, metricServiceClient, metricNamePrefix, new CreateTimeSeriesExporter( projectId, metricServiceClient, monitoredResource, metricNamePrefix)), MetricReader.create( MetricReader.Options.builder() .setMetricProducerManager( Metrics.getExportComponent().getMetricProducerManager()) .setSpanName(EXPORTER_SPAN_NAME) .build()), intervalMetricReaderOptionsBuilder.build()); }
/** * Creates a new {@link IntervalMetricReader}. * * @param metricExporter the {@link MetricExporter} to be called after. * @param metricReader the {@link MetricReader} to be used to read metrics. * @param options the {@link Options} for the new {@link IntervalMetricReader}. * @return a new {@link IntervalMetricReader}. * @since 0.19 */ public static IntervalMetricReader create( MetricExporter metricExporter, MetricReader metricReader, Options options) { checkNotNull(options, "options"); Duration exportInterval = checkNotNull(options.getExportInterval(), "exportInterval"); checkArgument(exportInterval.compareTo(ZERO) > 0, "Export interval must be positive"); return new IntervalMetricReader( new Worker( checkNotNull(metricExporter, "metricExporter"), exportInterval.toMillis(), checkNotNull(metricReader, "metricReader"))); }
@VisibleForTesting static void unsafeResetExporter() { synchronized (monitor) { if (exporter != null) { if (exporter.intervalMetricReader != null) { exporter.intervalMetricReader.stop(); } exporter = null; } } }