use of io.opentracing.ActiveSpan in project batfish by batfish.
the class WorkItemTest method testInjectExtractNoop.
@Test
public void testInjectExtractNoop() {
ActiveSpan activeSpan = _noopTracer.buildSpan("test span").startActive();
_workItem.setSourceSpan(activeSpan, _noopTracer);
try (ActiveSpan childSpan = _noopTracer.buildSpan("test span").addReference(References.FOLLOWS_FROM, _workItem.getSourceSpan(_noopTracer)).startActive()) {
assertThat(childSpan, notNullValue());
assertThat(childSpan, instanceOf(NoopActiveSpan.class));
}
}
use of io.opentracing.ActiveSpan in project batfish by batfish.
the class WorkItemTest method testNullActiveSpanNoop.
@Test
public void testNullActiveSpanNoop() {
_workItem.setSourceSpan(null, _noopTracer);
SpanContext sourceSpanContext = _workItem.getSourceSpan(_noopTracer);
try (ActiveSpan childSpan = _noopTracer.buildSpan("test dangling child").addReference(References.FOLLOWS_FROM, sourceSpanContext).startActive()) {
assertThat(childSpan, notNullValue());
assertThat(childSpan, instanceOf(NoopActiveSpan.class));
}
}
use of io.opentracing.ActiveSpan in project batfish by batfish.
the class WorkItemTest method testExtractOnlyNoop.
@Test
public void testExtractOnlyNoop() {
SpanContext sourceSpanContext = _workItem.getSourceSpan(_noopTracer);
try (ActiveSpan childSpan = _noopTracer.buildSpan("test dangling child").addReference(References.FOLLOWS_FROM, sourceSpanContext).startActive()) {
assertThat(childSpan, notNullValue());
assertThat(childSpan, instanceOf(NoopActiveSpan.class));
}
}
use of io.opentracing.ActiveSpan in project batfish by batfish.
the class Batfish method serializeNetworkConfigs.
private void serializeNetworkConfigs(Path testRigPath, Path outputPath, ParseVendorConfigurationAnswerElement answerElement, SortedMap<String, VendorConfiguration> overlayHostConfigurations) {
Map<Path, String> configurationData = readConfigurationFiles(testRigPath, BfConsts.RELPATH_CONFIGURATIONS_DIR);
Map<String, VendorConfiguration> vendorConfigurations;
try (ActiveSpan parseNetworkConfigsSpan = GlobalTracer.get().buildSpan("Parse network configs").startActive()) {
// avoid unused warning
assert parseNetworkConfigsSpan != null;
vendorConfigurations = parseVendorConfigurations(configurationData, answerElement, ConfigurationFormat.UNKNOWN);
}
if (vendorConfigurations == null) {
throw new BatfishException("Exiting due to parser errors");
}
_logger.infof("Testrig:%s in container:%s has total number of network configs:%d", getTestrigName(), getContainerName(), vendorConfigurations.size());
_logger.info("\n*** SERIALIZING VENDOR CONFIGURATION STRUCTURES ***\n");
_logger.resetTimer();
CommonUtil.createDirectories(outputPath);
Map<Path, VendorConfiguration> output = new TreeMap<>();
vendorConfigurations.forEach((name, vc) -> {
if (name.contains(File.separator)) {
// iptables will get a hostname like configs/iptables-save if they
// are not set up correctly using host files
_logger.errorf("Cannot serialize configuration with hostname %s\n", name);
answerElement.addRedFlagWarning(name, new Warning("Cannot serialize network config. Bad hostname " + name.replace("\\", "/"), "MISCELLANEOUS"));
} else {
// apply overlay if it exists
VendorConfiguration overlayConfig = overlayHostConfigurations.get(name);
if (overlayConfig != null) {
vc.setOverlayConfiguration(overlayConfig);
overlayHostConfigurations.remove(name);
}
Path currentOutputPath = outputPath.resolve(name);
output.put(currentOutputPath, vc);
}
});
// warn about unused overlays
overlayHostConfigurations.forEach((name, overlay) -> {
answerElement.getParseStatus().put(name, ParseStatus.ORPHANED);
});
serializeObjects(output);
_logger.printElapsedTime();
}
use of io.opentracing.ActiveSpan in project batfish by batfish.
the class Batfish method analyze.
private Answer analyze() {
Answer answer = new Answer();
AnswerSummary summary = new AnswerSummary();
String analysisName = _settings.getAnalysisName();
String containerName = _settings.getContainerDir().getFileName().toString();
Path analysisQuestionsDir = _settings.getContainerDir().resolve(Paths.get(BfConsts.RELPATH_ANALYSES_DIR, analysisName, BfConsts.RELPATH_QUESTIONS_DIR).toString());
if (!Files.exists(analysisQuestionsDir)) {
throw new BatfishException("Analysis questions dir does not exist: '" + analysisQuestionsDir + "'");
}
RunAnalysisAnswerElement ae = new RunAnalysisAnswerElement();
try (Stream<Path> questions = CommonUtil.list(analysisQuestionsDir)) {
questions.forEach(analysisQuestionDir -> {
String questionName = analysisQuestionDir.getFileName().toString();
Path analysisQuestionPath = analysisQuestionDir.resolve(BfConsts.RELPATH_QUESTION_FILE);
_settings.setQuestionPath(analysisQuestionPath);
Answer currentAnswer;
try (ActiveSpan analysisQuestionSpan = GlobalTracer.get().buildSpan(String.format("Getting answer to question %s from analysis %s", questionName, analysisName)).startActive()) {
// make span not show up as unused
assert analysisQuestionSpan != null;
currentAnswer = answer();
}
// Ensuring that question was parsed successfully
if (currentAnswer.getQuestion() != null) {
try {
// TODO: This can be represented much cleanly and easily with a Json
_logger.infof("Ran question:%s from analysis:%s in container:%s; work-id:%s, status:%s, " + "computed dataplane:%s, parameters:%s\n", questionName, analysisName, containerName, getTaskId(), currentAnswer.getSummary().getNumFailed() > 0 ? "failed" : "passed", currentAnswer.getQuestion().getDataPlane(), BatfishObjectMapper.writeString(currentAnswer.getQuestion().getInstance().getVariables()));
} catch (JsonProcessingException e) {
throw new BatfishException(String.format("Error logging question %s in analysis %s", questionName, analysisName), e);
}
}
initAnalysisQuestionPath(analysisName, questionName);
outputAnswer(currentAnswer);
ae.getAnswers().put(questionName, currentAnswer);
_settings.setQuestionPath(null);
summary.combine(currentAnswer.getSummary());
});
}
answer.addAnswerElement(ae);
answer.setSummary(summary);
return answer;
}
Aggregations