Skip to content
This repository has been archived by the owner on Dec 23, 2023. It is now read-only.

Exporter/OcAgent: Add deadline option. #1899

Merged
merged 1 commit into from
May 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Also provide a `MetricServiceStub` option so that advanced users can use a custo
Monitoring client to make RPCs.
- Use `Configuration` builder pattern for creating `JaegerTraceExporter`, `ZipkinTraceExporter` and
`InstanaTraceExporter`. Provide a `Deadline` option with default value 10 seconds.
- Provide a `Deadline` option to Datadog and Elasticsearch exporter. Default value is 10 seconds.
- Provide a `Deadline` option to Datadog, Elasticsearch and OcAgent exporter. Default value is 10 seconds.
- Extract the common timeout logic of Trace exporters to `opencensus-exporter-trace-util`.

## 0.21.0 - 2019-04-30
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ public static void createAndRegister(OcAgentTraceExporterConfiguration configura
configuration.getUseInsecure(),
configuration.getSslContext(),
configuration.getRetryInterval(),
configuration.getEnableConfig());
configuration.getEnableConfig(),
configuration.getDeadline());
registerInternal(newHandler);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public abstract class OcAgentTraceExporterConfiguration {
@VisibleForTesting static final String DEFAULT_END_POINT = "localhost:55678";
@VisibleForTesting static final String DEFAULT_SERVICE_NAME = "OpenCensus";
@VisibleForTesting static final Duration DEFAULT_RETRY_INTERVAL = Duration.create(300, 0);
@VisibleForTesting static final Duration DEFAULT_DEADLINE = Duration.create(10, 0);
@VisibleForTesting static final Duration ZERO = Duration.create(0, 0);

OcAgentTraceExporterConfiguration() {}
Expand Down Expand Up @@ -101,6 +102,16 @@ public abstract class OcAgentTraceExporterConfiguration {
*/
public abstract boolean getEnableConfig();

/**
* Returns the deadline for exporting to Agent/Collector.
*
* <p>Default value is 10 seconds.
*
* @return the export deadline.
* @since 0.22
*/
public abstract Duration getDeadline();

/**
* Returns a new {@link Builder}.
*
Expand All @@ -113,7 +124,8 @@ public static Builder builder() {
.setServiceName(DEFAULT_SERVICE_NAME)
.setEnableConfig(true)
.setUseInsecure(true)
.setRetryInterval(DEFAULT_RETRY_INTERVAL);
.setRetryInterval(DEFAULT_RETRY_INTERVAL)
.setDeadline(DEFAULT_DEADLINE);
}

/**
Expand Down Expand Up @@ -181,19 +193,31 @@ public abstract static class Builder {
*/
public abstract Builder setEnableConfig(boolean enableConfig);

/**
* Sets the deadline for exporting to Agent/Collector.
*
* @param deadline the export deadline.
* @return this
* @since 0.22
*/
public abstract Builder setDeadline(Duration deadline);

// TODO(songya): add an option that controls whether to always keep the RPC connection alive.

abstract Duration getRetryInterval();

abstract OcAgentTraceExporterConfiguration autoBuild();

abstract Duration getDeadline();

/**
* Builds a {@link OcAgentTraceExporterConfiguration}.
*
* @return a {@code OcAgentTraceExporterConfiguration}.
* @since 0.20
*/
public OcAgentTraceExporterConfiguration build() {
Preconditions.checkArgument(getDeadline().compareTo(ZERO) > 0, "Deadline must be positive.");
Preconditions.checkArgument(
getRetryInterval().compareTo(ZERO) > 0, "Retry interval must be positive.");
return autoBuild();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,21 @@
import io.grpc.netty.NettyChannelBuilder;
import io.netty.handler.ssl.SslContext;
import io.opencensus.common.Duration;
import io.opencensus.exporter.trace.util.TimeLimitedHandler;
import io.opencensus.proto.agent.common.v1.Node;
import io.opencensus.proto.agent.trace.v1.ExportTraceServiceRequest;
import io.opencensus.proto.agent.trace.v1.TraceServiceGrpc;
import io.opencensus.trace.export.SpanData;
import io.opencensus.trace.export.SpanExporter.Handler;
import java.util.Collection;
import java.util.logging.Logger;
import javax.annotation.Nullable;

/** Exporting handler for OC-Agent Tracing. */
final class OcAgentTraceExporterHandler extends Handler {
final class OcAgentTraceExporterHandler extends TimeLimitedHandler {

private static final Logger logger =
Logger.getLogger(OcAgentTraceExporterHandler.class.getName());
private static final String EXPORT_SPAN_NAME = "ExportOpenCensusProtoSpans";

private final String endPoint;
private final Node node;
Expand All @@ -51,15 +52,17 @@ final class OcAgentTraceExporterHandler extends Handler {
boolean useInsecure,
@Nullable SslContext sslContext,
Duration retryInterval,
boolean enableConfig) {
boolean enableConfig,
Duration deadline) {
super(deadline, EXPORT_SPAN_NAME);
this.endPoint = endPoint;
this.node = OcAgentNodeUtils.getNodeInfo(serviceName);
this.useInsecure = useInsecure;
this.sslContext = sslContext;
}

@Override
public void export(Collection<SpanData> spanDataList) {
public void timeLimitedExport(Collection<SpanData> spanDataList) {
if (exportRpcHandler == null || exportRpcHandler.isCompleted()) {
// If not connected, try to initiate a new connection when a new batch of spans arrive.
// Export RPC doesn't respect the retry interval.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public void defaultConfiguration() {
assertThat(configuration.getRetryInterval())
.isEqualTo(OcAgentTraceExporterConfiguration.DEFAULT_RETRY_INTERVAL);
assertThat(configuration.getEnableConfig()).isTrue();
assertThat(configuration.getDeadline())
.isEqualTo(OcAgentTraceExporterConfiguration.DEFAULT_DEADLINE);
}

@Test
Expand All @@ -57,12 +59,14 @@ public void setAndGet() throws SSLException {
.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);
}
}