io.opencensus.common.Duration Java Examples
The following examples show how to use
io.opencensus.common.Duration.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OcAgentMetricsExporter.java From opencensus-java with Apache License 2.0 | 6 votes |
private OcAgentMetricsExporter( String endPoint, Boolean useInsecure, @Nullable SslContext sslContext, String serviceName, Duration exportInterval, Duration retryInterval, MetricProducerManager metricProducerManager) { OcAgentMetricsExporterWorker worker = new OcAgentMetricsExporterWorker( endPoint, useInsecure, sslContext, exportInterval, retryInterval, serviceName, metricProducerManager); workerThread = new Thread(worker); workerThread.setDaemon(true); workerThread.setName("OcAgentMetricsExporterWorker"); }
Example #2
Source File: SpanExporterImplTest.java From opencensus-java with Apache License 2.0 | 6 votes |
@Test public void exportSpansToMultipleServices() { SpanExporterImpl spanExporter = SpanExporterImpl.create(4, Duration.create(1, 0)); StartEndHandler startEndHandler = new StartEndHandlerImpl( spanExporter, runningSpanStore, sampledSpanStore, new SimpleEventQueue()); spanExporter.registerHandler("test.service", serviceHandler); TestHandler serviceHandler2 = new TestHandler(); spanExporter.registerHandler("test.service2", serviceHandler2); RecordEventsSpanImpl span1 = createSampledEndedSpan(startEndHandler, SPAN_NAME_1); RecordEventsSpanImpl span2 = createSampledEndedSpan(startEndHandler, SPAN_NAME_2); List<SpanData> exported1 = serviceHandler.waitForExport(2); List<SpanData> exported2 = serviceHandler2.waitForExport(2); assertThat(exported1).containsExactly(span1.toSpanData(), span2.toSpanData()); assertThat(exported2).containsExactly(span1.toSpanData(), span2.toSpanData()); }
Example #3
Source File: SpanExporterImplTest.java From opencensus-java with Apache License 2.0 | 6 votes |
@Test public void serviceHandlerThrowsException() { doThrow(new IllegalArgumentException("No export for you.")) .when(mockServiceHandler) .export(ArgumentMatchers.<SpanData>anyList()); SpanExporterImpl spanExporter = SpanExporterImpl.create(4, Duration.create(1, 0)); StartEndHandler startEndHandler = new StartEndHandlerImpl( spanExporter, runningSpanStore, sampledSpanStore, new SimpleEventQueue()); spanExporter.registerHandler("test.service", serviceHandler); spanExporter.registerHandler("mock.service", mockServiceHandler); RecordEventsSpanImpl span1 = createSampledEndedSpan(startEndHandler, SPAN_NAME_1); List<SpanData> exported = serviceHandler.waitForExport(1); assertThat(exported).containsExactly(span1.toSpanData()); // Continue to export after the exception was received. RecordEventsSpanImpl span2 = createSampledEndedSpan(startEndHandler, SPAN_NAME_1); exported = serviceHandler.waitForExport(1); assertThat(exported).containsExactly(span2.toSpanData()); }
Example #4
Source File: SpanExporterImplTest.java From opencensus-java with Apache License 2.0 | 6 votes |
@Test public void exportNotSampledSpans() { SpanExporterImpl spanExporter = SpanExporterImpl.create(4, Duration.create(1, 0)); StartEndHandler startEndHandler = new StartEndHandlerImpl( spanExporter, runningSpanStore, sampledSpanStore, new SimpleEventQueue()); spanExporter.registerHandler("test.service", serviceHandler); RecordEventsSpanImpl span1 = createNotSampledEndedSpan(startEndHandler, SPAN_NAME_1); RecordEventsSpanImpl span2 = createSampledEndedSpan(startEndHandler, SPAN_NAME_2); // Spans are recorded and exported in the same order as they are ended, we test that a non // sampled span is not exported by creating and ending a sampled span after a non sampled span // and checking that the first exported span is the sampled span (the non sampled did not get // exported). List<SpanData> exported = serviceHandler.waitForExport(1); // Need to check this because otherwise the variable span1 is unused, other option is to not // have a span1 variable. assertThat(exported).doesNotContain(span1.toSpanData()); assertThat(exported).containsExactly(span2.toSpanData()); }
Example #5
Source File: OcAgentTraceExporterConfigurationTest.java From opencensus-java with Apache License 2.0 | 6 votes |
@Test public void setAndGet() throws SSLException { Duration oneMinute = Duration.create(60, 0); SslContext sslContext = SslContextBuilder.forClient().build(); OcAgentTraceExporterConfiguration configuration = OcAgentTraceExporterConfiguration.builder() .setEndPoint("192.168.0.1:50051") .setServiceName("service") .setUseInsecure(false) .setSslContext(sslContext) .setRetryInterval(oneMinute) .setEnableConfig(false) .setDeadline(oneMinute) .build(); assertThat(configuration.getEndPoint()).isEqualTo("192.168.0.1:50051"); assertThat(configuration.getServiceName()).isEqualTo("service"); assertThat(configuration.getUseInsecure()).isFalse(); assertThat(configuration.getSslContext()).isEqualTo(sslContext); assertThat(configuration.getRetryInterval()).isEqualTo(oneMinute); assertThat(configuration.getEnableConfig()).isFalse(); assertThat(configuration.getDeadline()).isEqualTo(oneMinute); }
Example #6
Source File: SpanExporterImplTest.java From opencensus-java with Apache License 2.0 | 6 votes |
@Test public void exportMoreSpansThanTheBufferSize() { SpanExporterImpl spanExporter = SpanExporterImpl.create(4, Duration.create(1, 0)); StartEndHandler startEndHandler = new StartEndHandlerImpl( spanExporter, runningSpanStore, sampledSpanStore, new SimpleEventQueue()); spanExporter.registerHandler("test.service", serviceHandler); RecordEventsSpanImpl span1 = createSampledEndedSpan(startEndHandler, SPAN_NAME_1); RecordEventsSpanImpl span2 = createSampledEndedSpan(startEndHandler, SPAN_NAME_1); RecordEventsSpanImpl span3 = createSampledEndedSpan(startEndHandler, SPAN_NAME_1); RecordEventsSpanImpl span4 = createSampledEndedSpan(startEndHandler, SPAN_NAME_1); RecordEventsSpanImpl span5 = createSampledEndedSpan(startEndHandler, SPAN_NAME_1); RecordEventsSpanImpl span6 = createSampledEndedSpan(startEndHandler, SPAN_NAME_1); List<SpanData> exported = serviceHandler.waitForExport(6); assertThat(exported) .containsExactly( span1.toSpanData(), span2.toSpanData(), span3.toSpanData(), span4.toSpanData(), span5.toSpanData(), span6.toSpanData()); }
Example #7
Source File: SpanExporterImplTest.java From opencensus-java with Apache License 2.0 | 6 votes |
@Test(timeout = 10000L) public void exportNotSampledSpansFlushed() { // Set the export delay to zero, for no timeout, in order to confirm the #flush() below works SpanExporterImpl spanExporter = SpanExporterImpl.create(4, Duration.create(0, 0)); StartEndHandler startEndHandler = new StartEndHandlerImpl( spanExporter, runningSpanStore, sampledSpanStore, new SimpleEventQueue()); spanExporter.registerHandler("test.service", serviceHandler); RecordEventsSpanImpl span2 = createSampledEndedSpan(startEndHandler, SPAN_NAME_2); // Force a flush, without this, the #waitForExport() call below would block indefinitely. spanExporter.flush(); List<SpanData> exported = serviceHandler.waitForExport(1); assertThat(exported).containsExactly(span2.toSpanData()); }
Example #8
Source File: InProcessSampledSpanStoreImplTest.java From opencensus-java with Apache License 2.0 | 6 votes |
@Test public void getLatencySampledSpans_QueryBetweenMultipleBuckets() { RecordEventsSpanImpl span1 = createSampledSpan(REGISTERED_SPAN_NAME); testClock.advanceTime(Duration.create(0, (int) TimeUnit.MICROSECONDS.toNanos(20))); span1.end(); // Advance time to allow other spans to be sampled. testClock.advanceTime(Duration.create(5, 0)); RecordEventsSpanImpl span2 = createSampledSpan(REGISTERED_SPAN_NAME); testClock.advanceTime(Duration.create(0, (int) TimeUnit.MICROSECONDS.toNanos(200))); span2.end(); Collection<SpanData> samples = sampleStore.getLatencySampledSpans( LatencyFilter.create( REGISTERED_SPAN_NAME, TimeUnit.MICROSECONDS.toNanos(15), TimeUnit.MICROSECONDS.toNanos(250), 0)); assertThat(samples).containsExactly(span1.toSpanData(), span2.toSpanData()); }
Example #9
Source File: InProcessSampledSpanStoreImplTest.java From opencensus-java with Apache License 2.0 | 6 votes |
@Test public void getLatencySampledSpans_MaxSpansToReturn() { RecordEventsSpanImpl span1 = createSampledSpan(REGISTERED_SPAN_NAME); testClock.advanceTime(Duration.create(0, (int) TimeUnit.MICROSECONDS.toNanos(20))); span1.end(); // Advance time to allow other spans to be sampled. testClock.advanceTime(Duration.create(5, 0)); RecordEventsSpanImpl span2 = createSampledSpan(REGISTERED_SPAN_NAME); testClock.advanceTime(Duration.create(0, (int) TimeUnit.MICROSECONDS.toNanos(200))); span2.end(); Collection<SpanData> samples = sampleStore.getLatencySampledSpans( LatencyFilter.create( REGISTERED_SPAN_NAME, TimeUnit.MICROSECONDS.toNanos(15), TimeUnit.MICROSECONDS.toNanos(250), 1)); assertThat(samples.size()).isEqualTo(1); assertThat(samples.contains(span1.toSpanData())).isTrue(); }
Example #10
Source File: InProcessSampledSpanStoreImplTest.java From opencensus-java with Apache License 2.0 | 6 votes |
@Test public void getErrorSampledSpans_MaxSpansToReturn() { RecordEventsSpanImpl span1 = createSampledSpan(REGISTERED_SPAN_NAME); testClock.advanceTime(Duration.create(0, 1000)); span1.end(EndSpanOptions.builder().setStatus(Status.CANCELLED).build()); // Advance time to allow other spans to be sampled. testClock.advanceTime(Duration.create(5, 0)); RecordEventsSpanImpl span2 = createSampledSpan(REGISTERED_SPAN_NAME); testClock.advanceTime(Duration.create(0, 1000)); span2.end(EndSpanOptions.builder().setStatus(Status.CANCELLED).build()); Collection<SpanData> samples = sampleStore.getErrorSampledSpans( ErrorFilter.create(REGISTERED_SPAN_NAME, CanonicalCode.CANCELLED, 1)); assertThat(samples.size()).isEqualTo(1); // No order guaranteed so one of the spans should be in the list. assertThat(samples).containsAnyOf(span1.toSpanData(), span2.toSpanData()); }
Example #11
Source File: RecordEventsSpanImplTest.java From opencensus-java with Apache License 2.0 | 6 votes |
@Test public void status_ViaSetStatus() { RecordEventsSpanImpl span = RecordEventsSpanImpl.startSpan( spanContext, SPAN_NAME, null, parentSpanId, false, TraceParams.DEFAULT, startEndHandler, timestampConverter, testClock); Mockito.verify(startEndHandler, Mockito.times(1)).onStart(span); testClock.advanceTime(Duration.create(0, 100)); assertThat(span.getStatus()).isEqualTo(Status.OK); span.setStatus(Status.CANCELLED); assertThat(span.getStatus()).isEqualTo(Status.CANCELLED); span.end(); assertThat(span.getStatus()).isEqualTo(Status.CANCELLED); }
Example #12
Source File: OcAgentMetricsExporter.java From opencensus-java with Apache License 2.0 | 6 votes |
private static void createInternal( String endPoint, boolean useInsecure, @Nullable SslContext sslContext, String serviceName, Duration exportInterval, Duration retryInterval) { checkArgument( useInsecure == (sslContext == null), "Either use insecure or provide a valid SslContext."); synchronized (monitor) { checkState(exporter == null, "OcAgent Metrics exporter is already created."); exporter = new OcAgentMetricsExporter( endPoint, useInsecure, sslContext, serviceName, exportInterval, retryInterval, Metrics.getExportComponent().getMetricProducerManager()); exporter.workerThread.start(); } }
Example #13
Source File: OcAgentMetricsExporterWorker.java From opencensus-java with Apache License 2.0 | 6 votes |
OcAgentMetricsExporterWorker( String endPoint, boolean useInsecure, @Nullable SslContext sslContext, Duration exportInterval, Duration retryInterval, String serviceName, MetricProducerManager metricProducerManager) { this.endPoint = endPoint; this.useInsecure = useInsecure; this.sslContext = sslContext; this.exportIntervalMillis = exportInterval.toMillis(); this.retryIntervalMillis = retryInterval.toMillis(); this.serviceName = serviceName; this.metricProducerManager = metricProducerManager; }
Example #14
Source File: OcAgentMetricsExporterConfigurationTest.java From opencensus-java with Apache License 2.0 | 6 votes |
@Test public void setAndGet() throws SSLException { Duration oneMinute = Duration.create(60, 0); Duration fiveMinutes = Duration.create(300, 0); SslContext sslContext = SslContextBuilder.forClient().build(); OcAgentMetricsExporterConfiguration configuration = OcAgentMetricsExporterConfiguration.builder() .setEndPoint("192.168.0.1:50051") .setServiceName("service") .setUseInsecure(false) .setSslContext(sslContext) .setRetryInterval(fiveMinutes) .setExportInterval(oneMinute) .build(); assertThat(configuration.getEndPoint()).isEqualTo("192.168.0.1:50051"); assertThat(configuration.getServiceName()).isEqualTo("service"); assertThat(configuration.getUseInsecure()).isFalse(); assertThat(configuration.getSslContext()).isEqualTo(sslContext); assertThat(configuration.getRetryInterval()).isEqualTo(fiveMinutes); assertThat(configuration.getExportInterval()).isEqualTo(oneMinute); }
Example #15
Source File: IntervalMetricReaderTest.java From opencensus-java with Apache License 2.0 | 6 votes |
@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(); }
Example #16
Source File: IntervalMetricReaderTest.java From opencensus-java with Apache License 2.0 | 6 votes |
@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)); }
Example #17
Source File: StackdriverStatsExporter.java From opencensus-java with Apache License 2.0 | 6 votes |
/** * Creates a StackdriverStatsExporter for an explicit project ID and using explicit credentials, * with default Monitored Resource. * * <p>Only one Stackdriver exporter can be created. * * @param credentials a credentials used to authenticate API calls. * @param projectId the cloud project id. * @param exportInterval the interval between pushing stats to StackDriver. * @throws IllegalStateException if a Stackdriver exporter already exists. * @deprecated in favor of {@link #createAndRegister(StackdriverStatsConfiguration)}. * @since 0.9 */ @Deprecated public static void createAndRegisterWithCredentialsAndProjectId( Credentials credentials, String projectId, Duration exportInterval) throws IOException { checkNotNull(credentials, "credentials"); checkNotNull(projectId, "projectId"); checkNotNull(exportInterval, "exportInterval"); createInternal( credentials, projectId, exportInterval, DEFAULT_RESOURCE, null, DEFAULT_CONSTANT_LABELS, DEFAULT_DEADLINE, null); }
Example #18
Source File: StackdriverStatsExporter.java From opencensus-java with Apache License 2.0 | 6 votes |
private static void createInternal( @Nullable Credentials credentials, String projectId, Duration exportInterval, MonitoredResource monitoredResource, @Nullable String metricNamePrefix, Map<LabelKey, LabelValue> constantLabels, Duration deadline, @Nullable MetricServiceStub stub) throws IOException { synchronized (monitor) { checkState(instance == null, "Stackdriver stats exporter is already created."); MetricServiceClient client = stub == null ? createMetricServiceClient(credentials, deadline) : MetricServiceClient.create(stub); instance = new StackdriverStatsExporter( projectId, client, exportInterval, monitoredResource, metricNamePrefix, constantLabels); } }
Example #19
Source File: StackdriverStatsExporter.java From opencensus-java with Apache License 2.0 | 6 votes |
@GuardedBy("monitor") @VisibleForTesting static MetricServiceClient createMetricServiceClient( @Nullable Credentials credentials, Duration deadline) throws IOException { MetricServiceSettings.Builder settingsBuilder = MetricServiceSettings.newBuilder() .setTransportChannelProvider( InstantiatingGrpcChannelProvider.newBuilder() .setHeaderProvider(OPENCENSUS_USER_AGENT_HEADER_PROVIDER) .build()); if (credentials != null) { settingsBuilder.setCredentialsProvider(FixedCredentialsProvider.create(credentials)); } org.threeten.bp.Duration stackdriverDuration = org.threeten.bp.Duration.ofMillis(deadline.toMillis()); // We use createMetricDescriptor and createTimeSeries APIs in this exporter. settingsBuilder.createMetricDescriptorSettings().setSimpleTimeoutNoRetries(stackdriverDuration); settingsBuilder.createTimeSeriesSettings().setSimpleTimeoutNoRetries(stackdriverDuration); return MetricServiceClient.create(settingsBuilder.build()); }
Example #20
Source File: StackdriverMetrics.java From firebase-android-sdk with Apache License 2.0 | 6 votes |
private void ensureStackdriver(Gradle gradle) { // make sure we only initialize stackdriver once as gradle daemon is not guaranteed to restart // across gradle invocations. if (!STACKDRIVER_INITIALIZED.compareAndSet(false, true)) { logger.lifecycle("Stackdriver exporter already initialized."); return; } logger.lifecycle("Initializing Stackdriver exporter."); try { StackdriverStatsExporter.createAndRegister( StackdriverStatsConfiguration.builder() .setExportInterval(Duration.fromMillis(STACKDRIVER_UPLOAD_PERIOD_MS)) .build()); // make sure gradle does not exit before metrics get uploaded to stackdriver. gradle.addBuildListener(new DrainingBuildListener(STACKDRIVER_UPLOAD_PERIOD_MS, logger)); } catch (IOException e) { throw new GradleException("Could not configure metrics exporter", e); } }
Example #21
Source File: MutableViewData.java From opencensus-java with Apache License 2.0 | 5 votes |
private IntervalMutableViewData(View view, Timestamp start) { super(view); Duration totalDuration = ((View.AggregationWindow.Interval) view.getWindow()).getDuration(); this.totalDuration = totalDuration; this.bucketDuration = Duration.fromMillis(totalDuration.toMillis() / N); // When initializing. add N empty buckets prior to the start timestamp of this // IntervalMutableViewData, so that the last bucket will be the current one in effect. shiftBucketList(N + 1, start); }
Example #22
Source File: InProcessSampledSpanStoreImplTest.java From opencensus-java with Apache License 2.0 | 5 votes |
@Test public void getErrorSampledSpans() { RecordEventsSpanImpl span = createSampledSpan(REGISTERED_SPAN_NAME); testClock.advanceTime(Duration.create(0, 1000)); span.end(EndSpanOptions.builder().setStatus(Status.CANCELLED).build()); Collection<SpanData> samples = sampleStore.getErrorSampledSpans( ErrorFilter.create(REGISTERED_SPAN_NAME, CanonicalCode.CANCELLED, 0)); assertThat(samples.size()).isEqualTo(1); assertThat(samples.contains(span.toSpanData())).isTrue(); }
Example #23
Source File: SpanExporterImpl.java From opencensus-java with Apache License 2.0 | 5 votes |
private Worker(int bufferSize, Duration scheduleDelay) { spans = new ArrayList<>(bufferSize); this.bufferSize = bufferSize; // We notify the worker thread when bufferSize elements in the queue, so we will most likely // have to process more than bufferSize elements but less than 2 * bufferSize in that cycle. // During the processing time we want to allow the same amount of elements to be queued. // So we need to have 4 * bufferSize maximum elements referenced as an estimate. this.maxReferencedSpans = 4L * bufferSize; this.scheduleDelayMillis = scheduleDelay.toMillis(); }
Example #24
Source File: HelloWorldServer.java From opencensus-java with Apache License 2.0 | 5 votes |
/** Main launches the server from the command line. */ public static void main(String[] args) throws IOException, InterruptedException { // Add final keyword to pass checkStyle. final int serverPort = getPortOrDefaultFromArgs(args, 0, 50051); final String cloudProjectId = getStringOrDefaultFromArgs(args, 1, null); final int zPagePort = getPortOrDefaultFromArgs(args, 2, 3000); final int prometheusPort = getPortOrDefaultFromArgs(args, 3, 9090); // Registers all RPC views. For demonstration all views are registered. You may want to // start with registering basic views and register other views as needed for your application. RpcViews.registerAllViews(); // Registers logging trace exporter. LoggingTraceExporter.register(); // Starts a HTTP server and registers all Zpages to it. ZPageHandlers.startHttpServerAndRegisterAll(zPagePort); logger.info("ZPages server starts at localhost:" + zPagePort); // Registers Stackdriver exporters. if (cloudProjectId != null) { StackdriverTraceExporter.createAndRegister( StackdriverTraceConfiguration.builder().setProjectId(cloudProjectId).build()); StackdriverStatsExporter.createAndRegister( StackdriverStatsConfiguration.builder() .setProjectId(cloudProjectId) .setExportInterval(Duration.create(60, 0)) .build()); } // Register Prometheus exporters and export metrics to a Prometheus HTTPServer. PrometheusStatsCollector.createAndRegister(); HTTPServer prometheusServer = new HTTPServer(prometheusPort, true); // Start the RPC server. You shouldn't see any output from gRPC before this. logger.info("gRPC starting."); final HelloWorldServer server = new HelloWorldServer(serverPort); server.start(); server.blockUntilShutdown(); }
Example #25
Source File: InProcessSampledSpanStoreImplTest.java From opencensus-java with Apache License 2.0 | 5 votes |
@Test public void getErrorSampledSpans_NullCode() { RecordEventsSpanImpl span1 = createSampledSpan(REGISTERED_SPAN_NAME); testClock.advanceTime(Duration.create(0, 1000)); span1.end(EndSpanOptions.builder().setStatus(Status.CANCELLED).build()); RecordEventsSpanImpl span2 = createSampledSpan(REGISTERED_SPAN_NAME); testClock.advanceTime(Duration.create(0, 1000)); span2.end(EndSpanOptions.builder().setStatus(Status.UNKNOWN).build()); Collection<SpanData> samples = sampleStore.getErrorSampledSpans(ErrorFilter.create(REGISTERED_SPAN_NAME, null, 0)); assertThat(samples.size()).isEqualTo(2); assertThat(samples).containsExactly(span1.toSpanData(), span2.toSpanData()); }
Example #26
Source File: InProcessSampledSpanStoreImplTest.java From opencensus-java with Apache License 2.0 | 5 votes |
@Test public void getLatencySampledSpans_ExclusiveUpperBound() { RecordEventsSpanImpl span = createSampledSpan(REGISTERED_SPAN_NAME); testClock.advanceTime(Duration.create(0, (int) TimeUnit.MICROSECONDS.toNanos(20))); span.end(); Collection<SpanData> samples = sampleStore.getLatencySampledSpans( LatencyFilter.create( REGISTERED_SPAN_NAME, TimeUnit.MICROSECONDS.toNanos(15), TimeUnit.MICROSECONDS.toNanos(20), 0)); assertThat(samples.size()).isEqualTo(0); }
Example #27
Source File: InProcessSampledSpanStoreImplTest.java From opencensus-java with Apache License 2.0 | 5 votes |
@Test public void ignoreNegativeSpanLatency() { RecordEventsSpanImpl span = createSampledSpan(REGISTERED_SPAN_NAME); testClock.advanceTime(Duration.create(0, (int) TimeUnit.MICROSECONDS.toNanos(-20))); span.end(); Collection<SpanData> samples = sampleStore.getLatencySampledSpans( LatencyFilter.create(REGISTERED_SPAN_NAME, 0, Long.MAX_VALUE, 0)); assertThat(samples.size()).isEqualTo(0); }
Example #28
Source File: IntervalMetricReader.java From opencensus-java with Apache License 2.0 | 5 votes |
/** * 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"))); }
Example #29
Source File: StackdriverStatsExporter.java From opencensus-java with Apache License 2.0 | 5 votes |
private StackdriverStatsExporter( String projectId, MetricServiceClient metricServiceClient, Duration exportInterval, MonitoredResource monitoredResource, @Nullable String metricNamePrefix, Map<LabelKey, LabelValue> constantLabels) { IntervalMetricReader.Options.Builder intervalMetricReaderOptionsBuilder = IntervalMetricReader.Options.builder(); intervalMetricReaderOptionsBuilder.setExportInterval(exportInterval); intervalMetricReader = IntervalMetricReader.create( new CreateMetricDescriptorExporter( projectId, metricServiceClient, metricNamePrefix, constantLabels, new CreateTimeSeriesExporter( projectId, metricServiceClient, monitoredResource, metricNamePrefix, constantLabels)), MetricReader.create( MetricReader.Options.builder() .setMetricProducerManager( Metrics.getExportComponent().getMetricProducerManager()) .setSpanName(EXPORTER_SPAN_NAME) .build()), intervalMetricReaderOptionsBuilder.build()); }
Example #30
Source File: SignalFxStatsConfigurationTest.java From opencensus-java with Apache License 2.0 | 5 votes |
@Test public void buildWithFields() throws URISyntaxException { URI url = new URI("http://example.com"); Duration duration = Duration.create(5, 0); SignalFxStatsConfiguration configuration = SignalFxStatsConfiguration.builder() .setToken(TEST_TOKEN) .setIngestEndpoint(url) .setExportInterval(duration) .build(); assertEquals(TEST_TOKEN, configuration.getToken()); assertEquals(url, configuration.getIngestEndpoint()); assertEquals(duration, configuration.getExportInterval()); }