for (CauseCluster cluster : causeClusters) { double exclusiveDurationSum = 0.0; for (InvocationSequenceData invocation : cluster.getCauseInvocations()) { exclusiveDurationSum += DiagnosisHelper.getExclusiveDuration(invocation);
/** * In case there is just one cause invocation then the parent of the problem context is the * cause invocation, otherwise a new instance of CauseCluster will be created with the only * invocation in the list. * * @param causeInvocation * Invocation to get the parent of it if is the only one itself it has no parent. * @return Returns the CauseCluster. */ private CauseCluster getCauseCluster(InvocationSequenceData causeInvocation) { if ((causeInvocation.getParentSequence() != null) && !(causeInvocation.equals(globalContext))) { CauseCluster causeCluster = new CauseCluster(causeInvocation.getParentSequence()); causeCluster.getCauseInvocations().clear(); causeCluster.getCauseInvocations().add(causeInvocation); return causeCluster; } else { return new CauseCluster(causeInvocation); } }
/** * Creates a new cluster from the passed list of {@link #CauseCluster}. Sets the * <code>commonContext</code> to the parent of the new cluster. The parent subsumes all * {@link InvocationSequenceData} the cluster currently holds. * * @param clustersToMerge * List with clusters this cluster is merged with. * */ public CauseCluster(List<CauseCluster> clustersToMerge) { if ((clustersToMerge == null) || (clustersToMerge.isEmpty())) { throw new IllegalArgumentException("Clusters are not allowed to be null or empty!"); } int distanceToParent = clustersToMerge.get(0).getDistanceToNextCluster(); InvocationSequenceData parent = clustersToMerge.get(0).getCommonContext(); for (int i = 0; (i < distanceToParent) && (parent.getParentSequence() != null); i++) { parent = parent.getParentSequence(); } commonContext = parent; for (CauseCluster cluster : clustersToMerge) { causeInvocations.addAll(cluster.getCauseInvocations()); } }
/** * Rule execution. * * @return DIAGNOSIS_TAG_PROBLEM_CAUSE */ @Action(resultTag = RuleConstants.DIAGNOSIS_TAG_PROBLEM_CAUSE) public AggregatedDiagnosisData action() { causeCandidates = problemContext.getCauseInvocations(); int causeCandidatesChecked = getRootCauses(); threeSigmaApproach(causeCandidatesChecked); return rootCause; }
@Test public void rootCauseMustBeNotNullWhenMethodIdentIsEqualAndTheInvocationHasTimerData() { double highDuration = RANDOM.nextDouble() + 1000; List<InvocationSequenceData> nestedSequences = new ArrayList<InvocationSequenceData>(); InvocationSequenceData firstChildSequenceData = new InvocationSequenceData(DEF_DATE, PLATFORM_IDENT, SENSOR_TYPE_IDENT, METHOD_IDENT_EQUAL); TimerData timerData = new TimerData(new Timestamp(System.currentTimeMillis()), 10L, 20L, 30L); timerData.calculateExclusiveMin(RANDOM.nextDouble()); timerData.setExclusiveDuration(RANDOM.nextDouble()); firstChildSequenceData.setTimerData(timerData); InvocationSequenceData secondChildSequenceData = new InvocationSequenceData(DEF_DATE, PLATFORM_IDENT, SENSOR_TYPE_IDENT, METHOD_IDENT_EQUAL); timerData.calculateExclusiveMin(RANDOM.nextDouble()); timerData.setExclusiveDuration(RANDOM.nextDouble()); secondChildSequenceData.setTimerData(timerData); nestedSequences.add(firstChildSequenceData); nestedSequences.add(secondChildSequenceData); when(problemContext.getCommonContext()).thenReturn(commonContext); when(commonContext.getMethodIdent()).thenReturn(1L); when(commonContext.getDuration()).thenReturn(highDuration); when(problemContext.getCauseInvocations()).thenReturn(nestedSequences); AggregatedDiagnosisData rootCause = problemCauseRule.action(); assertThat("The returned root cause rule must not be null", rootCause, notNullValue()); }
@Test public void rootCauseMustHaveTwoElementsInRawInvocationSequence() { List<InvocationSequenceData> nestedSequences = new ArrayList<InvocationSequenceData>(); InvocationSequenceData firstChildSequenceData = new InvocationSequenceData(DEF_DATE, PLATFORM_IDENT, SENSOR_TYPE_IDENT, METHOD_IDENT_EQUAL); TimerData timerData = new TimerData(new Timestamp(System.currentTimeMillis()), 10L, 20L, 30L); TimerData firstTimerData = timerData; firstTimerData.setExclusiveDuration(2000); firstTimerData.setDuration(2000); firstChildSequenceData.setTimerData(firstTimerData); InvocationSequenceData secondChildSequenceData = new InvocationSequenceData(DEF_DATE, PLATFORM_IDENT, SENSOR_TYPE_IDENT, METHOD_IDENT_EQUAL); TimerData secondTimerData = timerData; secondTimerData.setExclusiveDuration(100); secondTimerData.setDuration(100); secondChildSequenceData.setTimerData(secondTimerData); nestedSequences.add(firstChildSequenceData); nestedSequences.add(secondChildSequenceData); when(problemContext.getCommonContext()).thenReturn(commonContext); when(commonContext.getMethodIdent()).thenReturn(METHOD_IDENT_EQUAL); when(commonContext.getDuration()).thenReturn(3100.0); when(problemContext.getCauseInvocations()).thenReturn(nestedSequences); AggregatedDiagnosisData rootCause = problemCauseRule.action(); assertThat("Raw invocation sequence must have two elements", rootCause.getRawInvocationsSequenceElements(), hasSize(2)); }
when(commonContext.getMethodIdent()).thenReturn(firstMethod.getMethodIdent()); when(commonContext.getTimerData()).thenReturn(firstMethod.getTimerData()); when(problemContext.getCauseInvocations()).thenReturn(detectedProblemContext.getNestedSequences()); when(commonContext.getDuration()).thenReturn(firstMethod.getDuration());
@Test public void isReturningTheProperValue() { long methodIdent = 108L; InvocationSequenceData root = new InvocationSequenceData(DEF_DATE, 10, 10, methodIdent); InvocationSequenceData firstInvocationSequenceData = new InvocationSequenceData(DEF_DATE, 10, 10, methodIdent); firstInvocationSequenceData.setParentSequence(root); InvocationSequenceData secondInvocationSequenceData = new InvocationSequenceData(DEF_DATE, 10, 10, methodIdent); secondInvocationSequenceData.setParentSequence(root); root.getNestedSequences().add(firstInvocationSequenceData); root.getNestedSequences().add(secondInvocationSequenceData); CauseCluster one = new CauseCluster(firstInvocationSequenceData); CauseCluster two = new CauseCluster(secondInvocationSequenceData); one.setDistanceToNextCluster(1); one.setDepthOfCommonContext(1); two.setDistanceToNextCluster(1); two.setDepthOfCommonContext(1); List<CauseCluster> clustersToMerge = new ArrayList<CauseCluster>(); clustersToMerge.add(one); clustersToMerge.add(two); CauseCluster merged = new CauseCluster(clustersToMerge); assertThat("The returned problemContext must have size 2", merged.getCauseInvocations().size(), is(2)); assertThat("The returned problemContext must be the root one element", merged.getCommonContext(), is(root)); }
when(commonContext.getMethodIdent()).thenReturn(firstMethod.getMethodIdent()); when(commonContext.getTimerData()).thenReturn(firstMethod.getTimerData()); when(problemContext.getCauseInvocations()).thenReturn(detectedProblemContext.getNestedSequences()); when(commonContext.getDuration()).thenReturn(firstMethod.getDuration());
@Test public void wrongGlobalContextResultsInWrongCommonContext() { long methodIdent = 108L; InvocationSequenceData root = new InvocationSequenceData(DEF_DATE, 10, 10, methodIdent); InvocationSequenceData firstInvocationSequenceData = new InvocationSequenceData(DEF_DATE, 10, 10, methodIdent); firstInvocationSequenceData.setParentSequence(root); InvocationSequenceData secondInvocationSequenceData = new InvocationSequenceData(DEF_DATE, 10, 10, methodIdent); secondInvocationSequenceData.setParentSequence(root); root.getNestedSequences().add(firstInvocationSequenceData); root.getNestedSequences().add(secondInvocationSequenceData); CauseCluster one = new CauseCluster(root); CauseCluster two = new CauseCluster(secondInvocationSequenceData); one.setDistanceToNextCluster(1); one.setDepthOfCommonContext(1); two.setDistanceToNextCluster(1); two.setDepthOfCommonContext(1); List<CauseCluster> clustersToMerge = new ArrayList<CauseCluster>(); clustersToMerge.add(one); clustersToMerge.add(two); CauseCluster merged = new CauseCluster(clustersToMerge); assertThat("The returned problemContext must has size 2", merged.getCauseInvocations().size(), is(2)); assertThat("The returned root cause rule must not be null", merged.getCommonContext(), not(nullValue())); }
when(commonContext.getDuration()).thenReturn(firstMethod.getDuration()); when(commonContext.getSqlStatementData()).thenReturn(timerDataSql); when(problemContext.getCauseInvocations()).thenReturn(detectedProblemContext.getNestedSequences());
when(commonContext.getMethodIdent()).thenReturn(currentProblemContext.getMethodIdent()); when(commonContext.getDuration()).thenReturn(currentProblemContext.getDuration()); when(problemContext.getCauseInvocations()).thenReturn(currentProblemContext.getNestedSequences());