/** * {@inheritDoc} */ protected void applyAssignment(AgentConfig agentConfiguration, SensorInstrumentationPoint sensorInstrumentationPoint) { // first deal with sensor id MethodSensorTypeConfig methodSensorTypeConfig = getSensorTypeConfigFromConfiguration(agentConfiguration, environment, methodSensorAssignment); long sensorId = methodSensorTypeConfig.getId(); // set to rsc sensorInstrumentationPoint.addSensorId(sensorId, methodSensorTypeConfig.getPriority()); // add all settings sensorInstrumentationPoint.addSettings(methodSensorAssignment.getSettings()); }
@Test public void instrumentationExist() throws Exception { long agentId = 13L; long sensorId = 15L; String sensorClassName = "sensorClassName"; MethodSensorTypeConfig methodSensorTypeConfig = mock(MethodSensorTypeConfig.class); when(methodSensorTypeConfig.getId()).thenReturn(sensorId); when(methodSensorTypeConfig.getPriority()).thenReturn(PriorityEnum.NORMAL); AgentConfig agentConfiguration = mock(AgentConfig.class); when(agentConfiguration.getPlatformId()).thenReturn(agentId); when(agentConfiguration.getMethodSensorTypeConfig(sensorClassName)).thenReturn(methodSensorTypeConfig); Map<String, Object> settings = Collections.<String, Object> singletonMap("key", "value"); when(assignment.getSettings()).thenReturn(settings); IMethodSensorConfig methodSensorConfig = mock(IMethodSensorConfig.class); when(methodSensorConfig.getClassName()).thenReturn(sensorClassName); when(environment.getMethodSensorTypeConfig(Matchers.<Class<? extends IMethodSensorConfig>> any())).thenReturn(methodSensorConfig); SensorInstrumentationPoint rsc = mock(SensorInstrumentationPoint.class); when(rsc.getSensorIds()).thenReturn(new long[] { sensorId }); MethodInstrumentationConfig instrumentationConfig = mock(MethodInstrumentationConfig.class); when(instrumentationConfig.getSensorInstrumentationPoint()).thenReturn(rsc); when(methodType.getMethodInstrumentationConfig()).thenReturn(instrumentationConfig); boolean changed = applier.addInstrumentationPoints(agentConfiguration, classType); // verify results assertThat(changed, is(true)); // verify no interaction verifyZeroInteractions(registrationService); verify(instrumentationConfig, times(0)).setSensorInstrumentationPoint(Matchers.<SensorInstrumentationPoint> any()); verify(methodType, times(0)).setMethodInstrumentationConfig(Matchers.<MethodInstrumentationConfig> any()); }
@Test public void configureMethodSensor() throws Exception { long agentId = 13L; long sensorId = 17L; String sensorName = "sensorName"; String className = "className"; Map<String, Object> parameters = Collections.<String, Object> singletonMap("key", "value"); IMethodSensorConfig methodSensorConfig = mock(IMethodSensorConfig.class); when(methodSensorConfig.getName()).thenReturn(sensorName); when(methodSensorConfig.getClassName()).thenReturn(className); when(methodSensorConfig.getParameters()).thenReturn(parameters); when(methodSensorConfig.getPriority()).thenReturn(PriorityEnum.MAX); when(environment.getMethodSensorConfigs()).thenReturn(Collections.singletonList(methodSensorConfig)); when(registrationService.registerMethodSensorTypeIdent(agentId, className, parameters)).thenReturn(sensorId); AgentConfig agentConfiguration = creator.environmentToConfiguration(environment, agentId); Collection<MethodSensorTypeConfig> sensorTypeConfigs = agentConfiguration.getMethodSensorTypeConfigs(); assertThat(sensorTypeConfigs, hasSize(1)); MethodSensorTypeConfig sensorTypeConfig = sensorTypeConfigs.iterator().next(); assertThat(sensorTypeConfig.getId(), is(sensorId)); assertThat(sensorTypeConfig.getName(), is(sensorName)); assertThat(sensorTypeConfig.getClassName(), is(className)); assertThat(sensorTypeConfig.getParameters(), is(parameters)); assertThat(sensorTypeConfig.getPriority(), is(PriorityEnum.MAX)); verify(registrationService).registerMethodSensorTypeIdent(agentId, className, parameters); verify(registrationService).registerMethodSensorTypeIdent(anyLong(), eq(eisc.getClassName()), eq(eisc.getParameters())); verify(registrationService).registerMethodSensorTypeIdent(anyLong(), eq(closeableHttpAsyncCLient.getClassName()), eq(closeableHttpAsyncCLient.getParameters())); verifyNoMoreInteractions(registrationService); }
when(methodSensorTypeConfig.getPriority()).thenReturn(PriorityEnum.NORMAL);
when(methodSensorTypeConfig.getPriority()).thenReturn(PriorityEnum.NORMAL);
when(methodSensorTypeConfig.getPriority()).thenReturn(PriorityEnum.NORMAL); when(invocSensorTypeConfig.getPriority()).thenReturn(PriorityEnum.INVOC);
@Test public void classLoadingDelegation() throws Exception { long agentId = 13L; long sensorId = 17L; when(environment.isClassLoadingDelegation()).thenReturn(true); ClassLoadingDelegationSensorConfig cldConfig = ClassLoadingDelegationSensorConfig.INSTANCE; when(registrationService.registerMethodSensorTypeIdent(agentId, cldConfig.getClassName(), cldConfig.getParameters())).thenReturn(sensorId); AgentConfig agentConfiguration = creator.environmentToConfiguration(environment, agentId); Collection<MethodSensorTypeConfig> sensorTypeConfigs = agentConfiguration.getSpecialMethodSensorTypeConfigs(); assertThat(sensorTypeConfigs, hasSize(3)); // first element will be class loading config MethodSensorTypeConfig sensorTypeConfig = sensorTypeConfigs.iterator().next(); assertThat(sensorTypeConfig.getId(), is(sensorId)); assertThat(sensorTypeConfig.getName(), is(cldConfig.getName())); assertThat(sensorTypeConfig.getClassName(), is(cldConfig.getClassName())); assertThat(sensorTypeConfig.getParameters(), is(cldConfig.getParameters())); assertThat(sensorTypeConfig.getPriority(), is(cldConfig.getPriority())); verify(registrationService).registerMethodSensorTypeIdent(agentId, cldConfig.getClassName(), cldConfig.getParameters()); verify(registrationService).registerMethodSensorTypeIdent(anyLong(), eq(eisc.getClassName()), eq(eisc.getParameters())); verify(registrationService).registerMethodSensorTypeIdent(anyLong(), eq(closeableHttpAsyncCLient.getClassName()), eq(closeableHttpAsyncCLient.getParameters())); verifyNoMoreInteractions(registrationService); }
when(methodSensorTypeConfig.getPriority()).thenReturn(PriorityEnum.NORMAL); when(invocSensorTypeConfig.getPriority()).thenReturn(PriorityEnum.INVOC);
@Test public void mbeanServerInterceptor() throws Exception { long agentId = 13L; long sensorId = 17L; JmxSensorConfig jmxSensorConfig = mock(JmxSensorConfig.class); when(jmxSensorConfig.isActive()).thenReturn(true); when(environment.getJmxSensorConfig()).thenReturn(jmxSensorConfig); MBeanServerInterceptorSensorConfig msiConfig = MBeanServerInterceptorSensorConfig.INSTANCE; when(registrationService.registerMethodSensorTypeIdent(agentId, msiConfig.getClassName(), msiConfig.getParameters())).thenReturn(sensorId); AgentConfig agentConfiguration = creator.environmentToConfiguration(environment, agentId); Collection<MethodSensorTypeConfig> sensorTypeConfigs = agentConfiguration.getSpecialMethodSensorTypeConfigs(); assertThat(sensorTypeConfigs, hasSize(3)); // first element will be mbean server interceptor config MethodSensorTypeConfig sensorTypeConfig = sensorTypeConfigs.iterator().next(); assertThat(sensorTypeConfig.getId(), is(sensorId)); assertThat(sensorTypeConfig.getName(), is(msiConfig.getName())); assertThat(sensorTypeConfig.getClassName(), is(msiConfig.getClassName())); assertThat(sensorTypeConfig.getParameters(), is(msiConfig.getParameters())); assertThat(sensorTypeConfig.getPriority(), is(msiConfig.getPriority())); verify(registrationService).registerMethodSensorTypeIdent(agentId, msiConfig.getClassName(), msiConfig.getParameters()); // needed because jmx sensor will be also registered verify(registrationService).registerJmxSensorTypeIdent(anyLong(), anyString()); verify(registrationService).registerMethodSensorTypeIdent(anyLong(), eq(eisc.getClassName()), eq(eisc.getParameters())); verify(registrationService).registerMethodSensorTypeIdent(anyLong(), eq(closeableHttpAsyncCLient.getClassName()), eq(closeableHttpAsyncCLient.getParameters())); verifyNoMoreInteractions(registrationService); }
/** * {@inheritDoc} */ @Override protected void applyAssignment(AgentConfig agentConfiguration, SensorInstrumentationPoint registeredSensorConfig) { // call super first super.applyAssignment(agentConfiguration, registeredSensorConfig); // check for invocation starts if (assignment.isStartsInvocation()) { // find the id of invocation sensor and only mark if one is found IMethodSensorConfig invocationSensorConfig = environment.getMethodSensorTypeConfig(InvocationSequenceSensorConfig.class); if (null != invocationSensorConfig) { MethodSensorTypeConfig invocationSensorTypeConfig = agentConfiguration.getMethodSensorTypeConfig(invocationSensorConfig.getClassName()); registeredSensorConfig.addSensorId(invocationSensorTypeConfig.getId(), invocationSensorTypeConfig.getPriority()); registeredSensorConfig.setStartsInvocation(true); } } } }