/** * Creates list with clusters. For each InvocationSequenceData in the Time Wasting Operation a * cluster is build initially. * * @return Returns a list of causeCluster. */ private List<CauseCluster> populateCauseCluster() { List<InvocationSequenceData> causeInvocations = timeWastingOperation.getRawInvocationsSequenceElements(); List<CauseCluster> causeClusters = new LinkedList<>(); for (InvocationSequenceData invocation : causeInvocations) { causeClusters.add(new CauseCluster(invocation)); } return causeClusters; }
/** * Rule execution. * * The exclusive times of all InvocationSequenceData in the Time Wasting Operation are summed * up. The InvocationSequenceData are clustered until there is a cluster with a significant high * exclusive time. * * @return DIAGNOSIS_TAG_PROBLEM_CONTEXT */ @Action(resultTag = RuleConstants.DIAGNOSIS_TAG_PROBLEM_CONTEXT) public CauseCluster action() { List<InvocationSequenceData> causeInvocations = timeWastingOperation.getRawInvocationsSequenceElements(); if (causeInvocations.size() > 1) { return getSignificantCluster(populateCauseCluster()); } else if (causeInvocations.size() == 1) { return getCauseCluster(causeInvocations.get(0)); } else { throw new RuntimeException("TimeWastingOperation has no elements"); } }
@Test public void problemContextMustBeGlobalContext() { Timestamp currentTime = new Timestamp(System.currentTimeMillis()); List<InvocationSequenceData> rawInvocations = new ArrayList<InvocationSequenceData>(); TimerData timerData = new TimerData(currentTime, 10L, 20L, 30L); timerData.calculateExclusiveMin(RANDOM.nextDouble()); timerData.setExclusiveDuration(RANDOM.nextDouble()); when(globalContext.getTimerData()).thenReturn(timerData); rawInvocations.add(globalContext); when(timeWastingOperation.getRawInvocationsSequenceElements()).thenReturn(rawInvocations); CauseCluster problemContext = problemContextRule.action(); assertThat("The returned problemContext must be the most significant cluster context", problemContext.getCommonContext(), is(globalContext)); }
@Test public void problemContextMustBeTheSameInvocationIfItIsTheOnlyOneAndIsTheInvoker() { long methodIdent = 108L; Timestamp defDate = new Timestamp(new Date().getTime()); long platformIdent = RANDOM.nextLong(); long sensorTypeIdent = RANDOM.nextLong(); InvocationSequenceData parentSequence = new InvocationSequenceData(defDate, platformIdent, sensorTypeIdent, methodIdent); InvocationSequenceData childSequence = new InvocationSequenceData(defDate, platformIdent, sensorTypeIdent, methodIdent); List<InvocationSequenceData> rawInvocations = new ArrayList<InvocationSequenceData>(); parentSequence.getNestedSequences().add(childSequence); rawInvocations.add(parentSequence); when(timeWastingOperation.getRawInvocationsSequenceElements()).thenReturn(rawInvocations); CauseCluster problemContext = problemContextRule.action(); assertThat("The returned problemContext must be the invoker", problemContext.getCommonContext(), is(parentSequence)); }
double[] durations = new double[rootCause.size()]; int i = 0; for (InvocationSequenceData invocation : rootCause.getRawInvocationsSequenceElements()) { durations[i] = DiagnosisHelper.getExclusiveDuration(invocation); i++;
@Test public void problemContextMustBeTheProperInvocationIfThereOneAndIsTheInvokerWithAParentSequence() { long methodIdent = 108L; Timestamp defDate = new Timestamp(new Date().getTime()); long platformIdent = RANDOM.nextLong(); long sensorTypeIdent = RANDOM.nextLong(); InvocationSequenceData parentSequence = new InvocationSequenceData(defDate, platformIdent, sensorTypeIdent, methodIdent); InvocationSequenceData childSequence = new InvocationSequenceData(defDate, platformIdent, sensorTypeIdent, methodIdent); List<InvocationSequenceData> rawInvocations = new ArrayList<InvocationSequenceData>(); childSequence.setParentSequence(parentSequence); rawInvocations.add(childSequence); when(timeWastingOperation.getRawInvocationsSequenceElements()).thenReturn(rawInvocations); CauseCluster problemContext = problemContextRule.action(); assertThat("The returned problemContext must be the invoker", problemContext.getCommonContext(), is(childSequence.getParentSequence())); }
/** * Checks that the sequenceData have all the mandatory attributes. * * @param AggregatedDiagnosisInvocationData * Sequence data to check if has all the mandatory data. */ private void isAValidAggregatedDiagnosisData(AggregatedDiagnosisData AggregatedDiagnosisInvocationData) { for (InvocationSequenceData aggregatedSequence : AggregatedDiagnosisInvocationData.getRawInvocationsSequenceElements()) { assertThat("The aggregated sequence cannot be null", aggregatedSequence, notNullValue()); assertThat("Duration of the aggregated sequence cannot be null", aggregatedSequence.getDuration(), notNullValue()); assertThat("Start time of the aggregated cannot be null", aggregatedSequence.getStart(), notNullValue()); assertThat("End time of the aggregated cannot be null", aggregatedSequence.getEnd(), notNullValue()); assertThat("Child count of the aggregated sequence cannot be null", aggregatedSequence.getChildCount(), notNullValue()); assertThat("ApplicationId of the aggregated sequence cannot be null", aggregatedSequence.getApplicationId(), notNullValue()); assertThat("Business transaction id of the aggregated sequence cannot be null", aggregatedSequence.getBusinessTransactionId(), notNullValue()); } }
@Test public void causeTypeIsRecursiveIfThereIsNotTimerData() { Timestamp defDate = new Timestamp(new Date().getTime()); Random random = new Random(); long platformIdent = random.nextLong(); long sensorTypeIdent = random.nextLong(); long methodIdentEqual = new Long(108); long methodIdentDiff = random.nextLong(); InvocationSequenceData childSequence = new InvocationSequenceData(defDate, platformIdent, sensorTypeIdent, methodIdentDiff); InvocationSequenceData parentSequence = new InvocationSequenceData(defDate, platformIdent, sensorTypeIdent, methodIdentDiff); InvocationSequenceData grandParentSequence = new InvocationSequenceData(defDate, platformIdent, sensorTypeIdent, methodIdentDiff); parentSequence.setParentSequence(grandParentSequence); List<InvocationSequenceData> rawInvocations = new ArrayList<>(); rawInvocations.add(new InvocationSequenceData()); rawInvocations.add(childSequence); when(problemContext.getCommonContext()).thenReturn(commonContext); when(commonContext.getParentSequence()).thenReturn(parentSequence); when(rootCause.getRawInvocationsSequenceElements()).thenReturn(rawInvocations); when(rootCause.getMethodIdent()).thenReturn(methodIdentEqual); CauseStructure causeStructure = causeStructureRule.action(); assertThat("The returned cause type must be iterative", causeStructure.getCauseType(), is(CauseType.ITERATIVE)); } }
@Test public void causeTypeMustBeIterativeWhenTheChildInvocationsOfTheRootCauseAreIterativeAndHasAHttpTimerData() { Timestamp defDate = new Timestamp(new Date().getTime()); Timestamp currentTime = new Timestamp(System.currentTimeMillis()); HttpTimerData timerDataHttp = new HttpTimerData(currentTime, 10L, 20L, 30L); AggregatedDiagnosisTimerData aggregatedTimerDataHttp = new AggregatedDiagnosisTimerData(timerDataHttp); Random random = new Random(); long platformIdent = random.nextLong(); long sensorTypeIdent = random.nextLong(); long methodIdentEqual = new Long(108); long methodIdentDiff = random.nextLong(); InvocationSequenceData childSequence = new InvocationSequenceData(defDate, platformIdent, sensorTypeIdent, methodIdentDiff); childSequence.setTimerData(timerDataHttp); InvocationSequenceData parentSequence = new InvocationSequenceData(defDate, platformIdent, sensorTypeIdent, methodIdentDiff); parentSequence.setTimerData(timerDataHttp); InvocationSequenceData grandParentSequence = new InvocationSequenceData(defDate, platformIdent, sensorTypeIdent, methodIdentDiff); grandParentSequence.setTimerData(timerDataHttp); parentSequence.setParentSequence(grandParentSequence); List<InvocationSequenceData> rawInvocations = new ArrayList<>(); rawInvocations.add(new InvocationSequenceData()); rawInvocations.add(childSequence); when(problemContext.getCommonContext()).thenReturn(commonContext); when(commonContext.getParentSequence()).thenReturn(parentSequence); when(commonContext.getTimerData()).thenReturn(timerDataHttp); when(rootCause.getRawInvocationsSequenceElements()).thenReturn(rawInvocations); when(rootCause.getMethodIdent()).thenReturn(methodIdentEqual); when(rootCause.getAggregatedDiagnosisTimerData()).thenReturn(aggregatedTimerDataHttp); CauseStructure causeStructure = causeStructureRule.action(); assertThat("The returned cause type must be iterative", causeStructure.getCauseType(), is(CauseType.ITERATIVE)); }
@Test public void causeTypeMustBeIterativeWhenTheChildInvocationsOfTheRootCauseAreIterativeAndHasARegularTimerData() { Timestamp defDate = new Timestamp(new Date().getTime()); Timestamp currentTime = new Timestamp(System.currentTimeMillis()); TimerData timerData = new TimerData(currentTime, 10L, 20L, 30L); AggregatedDiagnosisTimerData aggregatedTimerData = new AggregatedDiagnosisTimerData(timerData); Random random = new Random(); long platformIdent = random.nextLong(); long sensorTypeIdent = random.nextLong(); long methodIdentEqual = new Long(108); long methodIdentDiff = random.nextLong(); InvocationSequenceData childSequence = new InvocationSequenceData(defDate, platformIdent, sensorTypeIdent, methodIdentDiff); childSequence.setTimerData(timerData); InvocationSequenceData parentSequence = new InvocationSequenceData(defDate, platformIdent, sensorTypeIdent, methodIdentDiff); parentSequence.setTimerData(timerData); InvocationSequenceData grandParentSequence = new InvocationSequenceData(defDate, platformIdent, sensorTypeIdent, methodIdentDiff); grandParentSequence.setTimerData(timerData); parentSequence.setParentSequence(grandParentSequence); List<InvocationSequenceData> rawInvocations = new ArrayList<>(); rawInvocations.add(new InvocationSequenceData()); rawInvocations.add(childSequence); when(problemContext.getCommonContext()).thenReturn(commonContext); when(commonContext.getParentSequence()).thenReturn(parentSequence); when(commonContext.getTimerData()).thenReturn(timerData); when(rootCause.getRawInvocationsSequenceElements()).thenReturn(rawInvocations); when(rootCause.getMethodIdent()).thenReturn(methodIdentEqual); when(rootCause.getAggregatedDiagnosisTimerData()).thenReturn(aggregatedTimerData); CauseStructure causeStructure = causeStructureRule.action(); assertThat("The returned cause type must be iterative", causeStructure.getCauseType(), is(CauseType.ITERATIVE)); }
@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.getTimerData()).thenReturn(timerDataSql); when(commonContext.getSqlStatementData()).thenReturn(timerDataSql); when(rootCause.getRawInvocationsSequenceElements()).thenReturn(rawInvocations); when(rootCause.getMethodIdent()).thenReturn(methodIdentEqual); when(rootCause.getAggregatedDiagnosisTimerData()).thenReturn(aggregatedTimerDataSql);
rawInvocationsSignificant.add(significantContextChildWithParent); rawInvocationsSignificant.add(secondSignificantContextChildWithParent); when(timeWastingOperation.getRawInvocationsSequenceElements()).thenReturn(rawInvocationsSignificant); TimerData timeWastingOperationTimerData = new TimerData(new Timestamp(System.currentTimeMillis()), 10L, 20L, 30L); timeWastingOperationTimerData.calculateExclusiveMin(1);
AggregatedDiagnosisTimerData aggregatedDiagnosisTimerData = new AggregatedDiagnosisTimerData(timeWastingOperationTimerData); when(timeWastingOperation.getAggregatedDiagnosisTimerData()).thenReturn(aggregatedDiagnosisTimerData); when(timeWastingOperation.getRawInvocationsSequenceElements()).thenReturn(expectedProblemContext.getNestedSequences()); when(globalContext.getNestedSequences()).thenReturn(rootInvocation.getNestedSequences());
assertThat("Raw invocation sequence must have three elements", rootCause.getRawInvocationsSequenceElements(), hasSize(3));
significantCluster.setParentSequence(parentSequence); secondSequence.setParentSequence(parentSequence); when(timeWastingOperation.getRawInvocationsSequenceElements()).thenReturn(parentSequence.getNestedSequences()); TimerData timeWastingOperationTimerData = new TimerData(new Timestamp(System.currentTimeMillis()), 10L, 20L, 30L); timeWastingOperationTimerData.calculateExclusiveMin(1);
AggregatedDiagnosisTimerData aggregatedDiagnosisTimerData = new AggregatedDiagnosisTimerData(timeWastingOperationTimerData); when(timeWastingOperation.getAggregatedDiagnosisTimerData()).thenReturn(aggregatedDiagnosisTimerData); when(timeWastingOperation.getRawInvocationsSequenceElements()).thenReturn(expectedProblemContext.getNestedSequences()); when(globalContext.getNestedSequences()).thenReturn(rootInvocation.getNestedSequences());