PerformanceMonitoringAspect { @Around(value = "execution(* com.autonomy.aci.client.transport.AciHttpClient.executeAction(..)) && args(serverDetails, parameters)", argNames = "joinPoint,serverDetails,parameters") public Object monitorIdolRequestPerformance( final ProceedingJoinPoint joinPoint, final AciServerDetails serverDetails, final Collection<? extends AciParameter> parameters) throws Throwable { final StringBuilder metricNameBuilder = new StringBuilder(metricType) .append(IDOL_REQUEST_METRIC_NAME_PREFIX) .append(sanitiseMetricNameComponent(serverDetails.getHost())) .append(METRIC_NAME_SEPARATOR) .append(serverDetails.getPort()) .append(METRIC_NAME_SEPARATOR); final Map<String, String> parameterMap = parameters.stream() .filter(parameter -> !QueryParams.SecurityInfo.name().equalsIgnoreCase(parameter.getName()) && StringUtils.isNotEmpty(parameter.getValue())) .collect(Collectors.toMap(AciParameter::getName, AciParameter::getValue)); final Collection<String> parameterKeyValueStrings = parameterMap.entrySet().stream() .map(e -> e.getKey() + NAME_VALUE_SEPARATOR + sanitiseMetricNameComponent(tweakParameterValueInMetricName(e.getKey(), e.getValue()))) .sorted() .collect(Collectors.toList()); metricNameBuilder.append(String.join(PARAMETER_SEPARATOR, parameterKeyValueStrings)); return Arrays.stream(UserActions.values()).anyMatch(a -> a.name().equalsIgnoreCase(parameterMap.get(ActionParams.Action.name()))) ? joinPoint.proceed() : monitorMethodPerformance(joinPoint, sanitiseMetricName(metricNameBuilder.toString())); } @Autowired  PerformanceMonitoringAspect(final GaugeService gaugeService,
                                       @Value(FIND_METRICS_TYPE_PROPERTY) final String metricType); @Around("@within(idolService)") Object monitorServiceMethodPerformance(final ProceedingJoinPoint joinPoint, final IdolService idolService); @Around(value = "execution(* com.autonomy.aci.client.transport.AciHttpClient.executeAction(..)) && args(serverDetails, parameters)", argNames = "joinPoint,serverDetails,parameters") Object monitorIdolRequestPerformance(
            final ProceedingJoinPoint joinPoint,
            final AciServerDetails serverDetails,
            final Collection<? extends AciParameter> parameters);  }
@SuppressWarnings("resource") @Test public void monitorIdolRequestPerformance() throws IOException, AciHttpException { final Set<AciParameter> parameters = new AciParameters(QueryActions.Query.name()); final String text = "*"; parameters.add(new AciParameter(QueryParams.Text.name(), text)); final String database = "Test"; parameters.add(new AciParameter(QueryParams.DatabaseMatch.name(), database)); final String host = "localhost"; final int port = 5678; aciHttpClient.executeAction(new AciServerDetails(host, port), parameters); final String expectedMetricName = metricType + IDOL_REQUEST_METRIC_NAME_PREFIX + host + METRIC_NAME_SEPARATOR + port + METRIC_NAME_SEPARATOR + ActionParams.Action.name() + NAME_VALUE_SEPARATOR + QueryActions.Query.name() + PARAMETER_SEPARATOR + QueryParams.DatabaseMatch.name() + NAME_VALUE_SEPARATOR + database + PARAMETER_SEPARATOR + QueryParams.Text.name() + NAME_VALUE_SEPARATOR + text; verify(gaugeService).submit(eq(expectedMetricName), anyDouble()); }