use of io.opentracing.ActiveSpan in project batfish by batfish.
the class WorkItemTest method testExtractOnly.
@Test
public void testExtractOnly() {
SpanContext sourceSpanContext = _workItem.getSourceSpan(_mockTracer);
assertThat(sourceSpanContext, nullValue());
try (ActiveSpan childSpan = _mockTracer.buildSpan("test dangling child").addReference(References.FOLLOWS_FROM, sourceSpanContext).startActive()) {
assertThat(childSpan, notNullValue());
assertThat(childSpan, instanceOf(ThreadLocalActiveSpan.class));
}
}
use of io.opentracing.ActiveSpan in project batfish by batfish.
the class Client method execute.
private boolean execute(WorkItem wItem, @Nullable FileWriter outWriter) {
_logger.infof("work-id is %s\n", wItem.getId());
ActiveSpan activeSpan = GlobalTracer.get().activeSpan();
if (activeSpan != null) {
activeSpan.setTag("work-id", wItem.getId().toString());
}
wItem.addRequestParam(BfConsts.ARG_LOG_LEVEL, _settings.getBatfishLogLevel());
for (String option : _additionalBatfishOptions.keySet()) {
wItem.addRequestParam(option, _additionalBatfishOptions.get(option));
}
boolean queueWorkResult = _workHelper.queueWork(wItem);
_logger.infof("Queuing result: %s\n", queueWorkResult);
if (!queueWorkResult) {
return queueWorkResult;
}
boolean result = true;
if (!_backgroundExecution) {
_polledWorkItem = wItem;
result = pollWorkAndGetAnswer(wItem, outWriter);
_polledWorkItem = null;
}
return result;
}
use of io.opentracing.ActiveSpan in project batfish by batfish.
the class Client method pollWork.
private boolean pollWork(UUID wItemId, @Nullable FileWriter outWriter) {
Pair<WorkStatusCode, String> response;
try (ActiveSpan workStatusSpan = GlobalTracer.get().buildSpan("Waiting for work status").startActive()) {
// avoid unused warning
assert workStatusSpan != null;
// Poll the work item until it finishes or fails.
response = _workHelper.getWorkStatus(wItemId);
if (response == null) {
return false;
}
WorkStatusCode status = response.getFirst();
Backoff backoff = Backoff.builder().withMaximumBackoff(Duration.ofSeconds(1)).build();
while (!status.isTerminated() && backoff.hasNext()) {
printWorkStatusResponse(response, false);
try {
Thread.sleep(backoff.nextBackoff().toMillis());
} catch (InterruptedException e) {
throw new BatfishException("Interrupted while waiting for work item to complete", e);
}
response = _workHelper.getWorkStatus(wItemId);
if (response == null) {
return false;
}
status = response.getFirst();
}
printWorkStatusResponse(response, false);
}
return true;
}
use of io.opentracing.ActiveSpan in project batfish by batfish.
the class Client method processCommand.
boolean processCommand(String[] words, @Nullable FileWriter outWriter) {
Command command;
try {
command = Command.fromName(words[0]);
} catch (BatfishException e) {
_logger.errorf("Command failed: %s\n", e.getMessage());
return false;
}
List<String> options = getCommandOptions(words);
List<String> parameters = getCommandParameters(words, options.size());
try (ActiveSpan span = GlobalTracer.get().buildSpan(command.commandName()).startActive()) {
// make span not show up as unused.
assert span != null;
return processCommand(command, words, outWriter, options, parameters);
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
Aggregations