/** * Add one InvocationSequenceData to the aggregation. * * @param invocationSequenceData * invocationSequenceData to be aggregated */ public void aggregateInvocationSequenceData(InvocationSequenceData invocationSequenceData) { Object key = DIAGNOSIS_DATA_AGGREGATOR.getAggregationKey(invocationSequenceData); AggregatedDiagnosisData aggregatedObject = diagnosisDataAggregationMap.get(key); if (null != aggregatedObject) { DIAGNOSIS_DATA_AGGREGATOR.aggregate(aggregatedObject, invocationSequenceData); } else { aggregatedObject = DIAGNOSIS_DATA_AGGREGATOR.getAggregatedDiagnosisData(invocationSequenceData); diagnosisDataAggregationMap.put(key, aggregatedObject); } }
/** * Aggregate all the invocations that are considered as rootCause to the object * {@link RootCause}. * * @return Returns the number of candidates that are already checked. */ private int getRootCauses() { int causeCandidatesChecked = 0; double problemContextCommonContextDuration = InvocationSequenceDataHelper.calculateDuration(problemContext.getCommonContext()); // Root Cause candidates are put into one Root Cause as long as the condition is true. while ((sumExclusiveTime < (PROPORTION * problemContextCommonContextDuration)) && (causeCandidatesChecked < causeCandidates.size())) { InvocationSequenceData invocation = causeCandidates.get(causeCandidatesChecked); if (null == rootCause) { rootCause = diagnosisDataAggregator.getAggregatedDiagnosisData(invocation); } else { diagnosisDataAggregator.aggregate(rootCause, invocation); } sumExclusiveTime += DiagnosisHelper.getExclusiveDuration(invocation); causeCandidatesChecked++; } return causeCandidatesChecked; }
double duration = DiagnosisHelper.getExclusiveDuration(invocation); if (duration > lowerThreshold) { diagnosisDataAggregator.aggregate(rootCause, invocation); } else { break;
@Test(expectedExceptions = RuntimeException.class) public void collectProblemInstancesWithRuntimeExceptionProblemContext() { CauseStructure causeStructure = new CauseStructure(CauseType.SINGLE, SourceType.TIMERDATA); AggregatedDiagnosisData aggregatedInvocationSequenceData = null; aggregatedInvocationSequenceData = DiagnosisDataAggregator.getInstance().getAggregatedDiagnosisData(secondChildSequence); DiagnosisDataAggregator.getInstance().aggregate(aggregatedInvocationSequenceData, secondChildSequence); Multimap<String, Tag> tagMap = ArrayListMultimap.create(); Tag tagOne = new Tag(RuleConstants.DIAGNOSIS_TAG_GLOBAL_CONTEXT, secondChildSequence, Tags.rootTag(secondChildSequence)); Tag tagTwo = new Tag(RuleConstants.DIAGNOSIS_TAG_PROBLEM_CONTEXT, "Test", tagOne); Tag tagThree = new Tag(RuleConstants.DIAGNOSIS_TAG_PROBLEM_CAUSE, aggregatedInvocationSequenceData, tagTwo); Tag tagFour = new Tag(RuleConstants.DIAGNOSIS_TAG_CAUSE_STRUCTURE, causeStructure, tagThree); tagMap.put("D", tagFour); when(sessionContext.getInput()).thenReturn(secondChildSequence); when(sessionContext.getStorage()).thenReturn(storage); when(storage.mapTags(TagState.LEAF)).thenReturn(tagMap); ProblemOccurrenceResultCollector problemInstanceResultCollector = new ProblemOccurrenceResultCollector(); List<ProblemOccurrence> problemOccurrence = problemInstanceResultCollector.collect(sessionContext); assertThat(problemOccurrence, hasSize(0)); }
@Test(expectedExceptions = RuntimeException.class) public void collectProblemInstancesWithRuntimeExceptionCauseStructure() { AggregatedDiagnosisData aggregatedInvocationSequenceData = null; aggregatedInvocationSequenceData = DiagnosisDataAggregator.getInstance().getAggregatedDiagnosisData(secondChildSequence); DiagnosisDataAggregator.getInstance().aggregate(aggregatedInvocationSequenceData, secondChildSequence); Multimap<String, Tag> tagMap = ArrayListMultimap.create(); Tag tagOne = new Tag(RuleConstants.DIAGNOSIS_TAG_GLOBAL_CONTEXT, secondChildSequence, Tags.rootTag(secondChildSequence)); Tag tagTwo = new Tag(RuleConstants.DIAGNOSIS_TAG_PROBLEM_CONTEXT, new CauseCluster(secondChildSequence), tagOne); Tag tagThree = new Tag(RuleConstants.DIAGNOSIS_TAG_PROBLEM_CAUSE, aggregatedInvocationSequenceData, tagTwo); Tag tagFour = new Tag(RuleConstants.DIAGNOSIS_TAG_CAUSE_STRUCTURE, "Test", tagThree); tagMap.put("D", tagFour); when(sessionContext.getInput()).thenReturn(secondChildSequence); when(sessionContext.getStorage()).thenReturn(storage); when(storage.mapTags(TagState.LEAF)).thenReturn(tagMap); ProblemOccurrenceResultCollector problemInstanceResultCollector = new ProblemOccurrenceResultCollector(); List<ProblemOccurrence> problemOccurrence = problemInstanceResultCollector.collect(sessionContext); assertThat(problemOccurrence, hasSize(0)); }
@Test(expectedExceptions = RuntimeException.class) public void collectProblemInstancesWithRuntimeExceptionGlobalContext() { CauseStructure causeStructure = new CauseStructure(CauseType.SINGLE, SourceType.TIMERDATA); AggregatedDiagnosisData aggregatedInvocationSequenceData = null; aggregatedInvocationSequenceData = DiagnosisDataAggregator.getInstance().getAggregatedDiagnosisData(secondChildSequence); DiagnosisDataAggregator.getInstance().aggregate(aggregatedInvocationSequenceData, secondChildSequence); Multimap<String, Tag> tagMap = ArrayListMultimap.create(); Tag tagOne = new Tag(RuleConstants.DIAGNOSIS_TAG_GLOBAL_CONTEXT, "Test", Tags.rootTag(secondChildSequence)); Tag tagTwo = new Tag(RuleConstants.DIAGNOSIS_TAG_PROBLEM_CONTEXT, new CauseCluster(secondChildSequence), tagOne); Tag tagThree = new Tag(RuleConstants.DIAGNOSIS_TAG_PROBLEM_CAUSE, aggregatedInvocationSequenceData, tagTwo); Tag tagFour = new Tag(RuleConstants.DIAGNOSIS_TAG_CAUSE_STRUCTURE, causeStructure, tagThree); tagMap.put("D", tagFour); when(sessionContext.getInput()).thenReturn(secondChildSequence); when(sessionContext.getStorage()).thenReturn(storage); when(storage.mapTags(TagState.LEAF)).thenReturn(tagMap); ProblemOccurrenceResultCollector problemInstanceResultCollector = new ProblemOccurrenceResultCollector(); List<ProblemOccurrence> problemOccurrence = problemInstanceResultCollector.collect(sessionContext); assertThat(problemOccurrence, hasSize(0)); }
@Test public void collectProblemInstances() { CauseStructure causeStructure = new CauseStructure(CauseType.SINGLE, SourceType.TIMERDATA); AggregatedDiagnosisData aggregatedInvocationSequenceData = DiagnosisDataAggregator.getInstance().getAggregatedDiagnosisData(secondChildSequence); DiagnosisDataAggregator.getInstance().aggregate(aggregatedInvocationSequenceData, secondChildSequence); Multimap<String, Tag> tagMap = ArrayListMultimap.create(); Tag tagOne = new Tag(RuleConstants.DIAGNOSIS_TAG_GLOBAL_CONTEXT, secondChildSequence, Tags.rootTag(secondChildSequence)); Tag tagTwo = new Tag(RuleConstants.DIAGNOSIS_TAG_PROBLEM_CONTEXT, new CauseCluster(secondChildSequence), tagOne); Tag tagThree = new Tag(RuleConstants.DIAGNOSIS_TAG_PROBLEM_CAUSE, aggregatedInvocationSequenceData, tagTwo); Tag tagFour = new Tag(RuleConstants.DIAGNOSIS_TAG_CAUSE_STRUCTURE, causeStructure, tagThree); tagMap.put("Test", tagFour); when(sessionContext.getInput()).thenReturn(secondChildSequence); when(sessionContext.getStorage()).thenReturn(storage); when(storage.mapTags(TagState.LEAF)).thenReturn(tagMap); ProblemOccurrenceResultCollector problemInstanceResultCollector = new ProblemOccurrenceResultCollector(); List<ProblemOccurrence> problemOccurrence = problemInstanceResultCollector.collect(sessionContext); assertThat(problemOccurrence, hasSize(1)); }
@Test(expectedExceptions = RuntimeException.class) public void collectProblemInstancesWithRuntimeExceptionRootCause() { CauseStructure causeStructure = new CauseStructure(CauseType.SINGLE, SourceType.TIMERDATA); AggregatedDiagnosisData aggregatedInvocationSequenceData = null; aggregatedInvocationSequenceData = DiagnosisDataAggregator.getInstance().getAggregatedDiagnosisData(secondChildSequence); DiagnosisDataAggregator.getInstance().aggregate(aggregatedInvocationSequenceData, secondChildSequence); Multimap<String, Tag> tagMap = ArrayListMultimap.create(); Tag tagOne = new Tag(RuleConstants.DIAGNOSIS_TAG_GLOBAL_CONTEXT, secondChildSequence, Tags.rootTag(secondChildSequence)); Tag tagTwo = new Tag(RuleConstants.DIAGNOSIS_TAG_PROBLEM_CONTEXT, new CauseCluster(secondChildSequence), tagOne); Tag tagThree = new Tag(RuleConstants.DIAGNOSIS_TAG_PROBLEM_CAUSE, "Test", tagTwo); Tag tagFour = new Tag(RuleConstants.DIAGNOSIS_TAG_CAUSE_STRUCTURE, causeStructure, tagThree); tagMap.put("D", tagFour); when(sessionContext.getInput()).thenReturn(secondChildSequence); when(sessionContext.getStorage()).thenReturn(storage); when(storage.mapTags(TagState.LEAF)).thenReturn(tagMap); ProblemOccurrenceResultCollector problemInstanceResultCollector = new ProblemOccurrenceResultCollector(); List<ProblemOccurrence> problemOccurrence = problemInstanceResultCollector.collect(sessionContext); assertThat(problemOccurrence, hasSize(0)); }