/** * {@inheritDoc} */ @Override public List<MethodSensorTypeConfig> getMethodSensorTypes() throws StorageException { ensureConfigurationExists(); List<MethodSensorTypeConfig> result = new ArrayList<MethodSensorTypeConfig>(); if (CollectionUtils.isNotEmpty(agentConfiguration.getMethodSensorTypeConfigs())) { result.addAll(agentConfiguration.getMethodSensorTypeConfigs()); } // exception sensor is also method sensor type if (null != agentConfiguration.getExceptionSensorTypeConfig()) { result.add(agentConfiguration.getExceptionSensorTypeConfig()); } // special sensors are also method sensor types if (CollectionUtils.isNotEmpty(agentConfiguration.getSpecialMethodSensorTypeConfigs())) { result.addAll(agentConfiguration.getSpecialMethodSensorTypeConfigs()); } return result; }
/** * {@inheritDoc} */ @Override public StrategyConfig getDisruptorStrategyConfig() throws StorageException { ensureConfigurationExists(); StrategyConfig disruptorStrategy = agentConfiguration.getDisruptorStrategyConfig(); if (null == disruptorStrategy) { throw new StorageException("Disruptor strategy not defined in the agent configuration."); } return disruptorStrategy; } /**
/** * {@inheritDoc} */ @Override public Collection<IMatchPattern> getIgnoreClassesPatterns() throws StorageException { ensureConfigurationExists(); if (CollectionUtils.isNotEmpty(agentConfiguration.getExcludeClassesPatterns())) { return Collections.unmodifiableCollection(agentConfiguration.getExcludeClassesPatterns()); } else { return Collections.emptyList(); } }
@Test public void includesExceptionSensor() throws StorageException { when(agentConfiguration.getMethodSensorTypeConfigs()).thenReturn(null); ExceptionSensorTypeConfig exceptionSensorTypeConfig = mock(ExceptionSensorTypeConfig.class); when(agentConfiguration.getExceptionSensorTypeConfig()).thenReturn(exceptionSensorTypeConfig); List<MethodSensorTypeConfig> methodSensorTypes = configurationStorage.getMethodSensorTypes(); assertThat(methodSensorTypes, hasSize(1)); assertThat(methodSensorTypes, hasItem(exceptionSensorTypeConfig)); }
@Test public void includesSpecialSensors() throws StorageException { when(agentConfiguration.getMethodSensorTypeConfigs()).thenReturn(null); MethodSensorTypeConfig methodSensorTypeConfig = mock(MethodSensorTypeConfig.class); when(agentConfiguration.getSpecialMethodSensorTypeConfigs()).thenReturn(Collections.singletonList(methodSensorTypeConfig)); List<MethodSensorTypeConfig> methodSensorTypes = configurationStorage.getMethodSensorTypes(); assertThat(methodSensorTypes, hasSize(1)); assertThat(methodSensorTypes, hasItem(methodSensorTypeConfig)); } }
/** * {@inheritDoc} */ @Override public ExceptionSensorTypeConfig getExceptionSensorType() throws StorageException { ensureConfigurationExists(); return agentConfiguration.getExceptionSensorTypeConfig(); }
@Test @SuppressWarnings("unchecked") public void successful() throws Exception { List<String> definedIPs = mock(List.class); when(instrumentationManager.register(any(List.class), any(String.class), any(String.class))).thenReturn(agentConfig); when(agentConfig.getPlatformId()).thenReturn(10L); agentService.register(definedIPs, "name", "version"); verify(instrumentationManager).register(definedIPs, "name", "version"); verifyNoMoreInteractions(instrumentationManager, messageProvider); verifyZeroInteractions(messageProvider, definedIPs); } }
@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()); }
when(agentConfiguration.getPlatformId()).thenReturn(agentId); when(agentConfiguration.getExceptionSensorTypeConfig()).thenReturn(exceptionSensorTypeConfig);
/** * {@inheritDoc} */ @Override public List<JmxSensorTypeConfig> getJmxSensorTypes() throws StorageException { ensureConfigurationExists(); List<JmxSensorTypeConfig> result = new ArrayList<JmxSensorTypeConfig>(1); if (null != agentConfiguration.getJmxSensorTypeConfig()) { result.add(agentConfiguration.getJmxSensorTypeConfig()); } return result; }
/** * {@inheritDoc} */ @Override public List<PlatformSensorTypeConfig> getPlatformSensorTypes() throws StorageException { ensureConfigurationExists(); List<PlatformSensorTypeConfig> result = new ArrayList<PlatformSensorTypeConfig>(1); if (CollectionUtils.isNotEmpty(agentConfiguration.getPlatformSensorTypeConfigs())) { result.addAll(agentConfiguration.getPlatformSensorTypeConfigs()); } return result; }
when(agentConfiguration.getPlatformId()).thenReturn(agentId); when(agentConfiguration.getSpecialMethodSensorTypeConfig(sensorClassName)).thenReturn(methodSensorTypeConfig);
@Test public void noSpecialSensors() throws Exception { long agentId = 13L; when(environment.isClassLoadingDelegation()).thenReturn(false); when(environment.getJmxSensorConfig()).thenReturn(null); AgentConfig agentConfiguration = creator.environmentToConfiguration(environment, agentId); Collection<MethodSensorTypeConfig> sensorTypeConfigs = agentConfiguration.getSpecialMethodSensorTypeConfigs(); assertThat(Iterators.get(sensorTypeConfigs.iterator(), 0).getClassName(), is(equalTo(eisc.getClassName()))); assertThat(Iterators.get(sensorTypeConfigs.iterator(), 1).getClassName(), is(equalTo(closeableHttpAsyncCLient.getClassName()))); }
@Test public void notDefined() throws StorageException { when(agentConfiguration.getMethodSensorTypeConfigs()).thenReturn(null); List<MethodSensorTypeConfig> methodSensorTypes = configurationStorage.getMethodSensorTypes(); assertThat(methodSensorTypes, is(empty())); }
/** * {@inheritDoc} */ @Override public AgentEndUserMonitoringConfig getEndUserMonitoringConfig() throws StorageException { ensureConfigurationExists(); return agentConfiguration.getEumConfig(); }
/** * Finds the proper sensor id from the agent configuration and the environment used for the * {@link MethodSensorAssignment}. * * @param agentConfiguration * {@link AgentConfig} * @param environment * {@link Environment} * @param assignment * {@link MethodSensorAssignment} * @return {@link MethodSensorTypeConfig} for the given assignment. */ private MethodSensorTypeConfig getSensorTypeConfigFromConfiguration(AgentConfig agentConfiguration, Environment environment, MethodSensorAssignment assignment) { IMethodSensorConfig methodSensorConfig = environment.getMethodSensorTypeConfig(assignment.getSensorConfigClass()); return agentConfiguration.getMethodSensorTypeConfig(methodSensorConfig.getClassName()); }
/** * {@inheritDoc} */ @Override public boolean isExceptionSensorActivated() throws StorageException { ensureConfigurationExists(); return null != agentConfiguration.getExceptionSensorTypeConfig(); }
/** * Registers method to the registration service. * * @param agentConfiguration * {@link AgentConfig} to read platform id. * @param methodType * {@link MethodType} in question. * @param methodInstrumentationConfig * {@link MethodInstrumentationConfig}. * @return Id of the method. */ private long registerMethod(AgentConfig agentConfiguration, MethodType methodType, MethodInstrumentationConfig methodInstrumentationConfig) { // extract package and class name String fqn = methodInstrumentationConfig.getTargetClassFqn(); int index = fqn.lastIndexOf('.'); String packageName = index >= 0 ? fqn.substring(0, index) : ""; String className = fqn.substring(index + 1); return registrationService.registerMethodIdent(agentConfiguration.getPlatformId(), packageName, className, methodType.getName(), methodType.getParameters(), methodType.getReturnType(), methodType.getModifiers()); }
when(agentConfiguration.getPlatformId()).thenReturn(agentId); when(agentConfiguration.getMethodSensorTypeConfig(sensorClassName)).thenReturn(methodSensorTypeConfig);
when(agentConfiguration.getPlatformId()).thenReturn(agentId); when(agentConfiguration.getExceptionSensorTypeConfig()).thenReturn(exceptionSensorTypeConfig);