/** * {@inheritDoc} */ @Override protected void addTags(HttpTimerData data, Builder builder) { super.addTags(data, builder); HttpInfo httpInfo = data.getHttpInfo(); if (null != httpInfo.getUri()) { builder.tag(Series.Http.TAG_URI, httpInfo.getUri()); } if (httpInfo.hasInspectItTaggingHeader()) { builder.tag(Series.Http.TAG_INSPECTIT_TAGGING_HEADER, httpInfo.getInspectItTaggingHeaderValue()); } }
/** * {@inheritDoc} */ @Override public IAggregatedData<HttpTimerData> getClone(HttpTimerData httpData) { AggregatedHttpTimerData clone = new AggregatedHttpTimerData(); clone.setPlatformIdent(httpData.getPlatformIdent()); clone.setSensorTypeIdent(httpData.getSensorTypeIdent()); clone.setMethodIdent(httpData.getMethodIdent()); clone.setCharting(httpData.isCharting()); if (uriBased) { clone.getHttpInfo().setUri(httpData.getHttpInfo().getUri()); } else { // Aggregation based on Usecase. We reset the URI so that we can easily know // that use case aggregation is used. clone.getHttpInfo().setUri(HttpInfo.UNDEFINED); clone.getHttpInfo().setInspectItTaggingHeaderValue(httpData.getHttpInfo().getInspectItTaggingHeaderValue()); } clone.getHttpInfo().setRequestMethod(httpData.getHttpInfo().getRequestMethod()); return clone; }
String uri = httpInfo.isUriDefined() ? httpInfo.getUri() : null; // NOPMD String tag = httpInfo.hasInspectItTaggingHeader() ? httpInfo.getInspectItTaggingHeaderValue() : null; // NOPMD String requestMethod = httpInfo.getRequestMethod(); return (HttpInfo) httpInfoList.get(0); } else { return new HttpInfo(uri, requestMethod, tag);
/** * {@inheritDoc} */ @Override public Object getAggregationKey(HttpTimerData httpData) { final int prime = 31; int result = 0; if (uriBased) { result = (prime * result) + ((httpData.getHttpInfo().getUri() == null) ? 0 : httpData.getHttpInfo().getUri().hashCode()); } else { result = (prime * result) + ((httpData.getHttpInfo().getInspectItTaggingHeaderValue() == null) ? 0 : httpData.getHttpInfo().getInspectItTaggingHeaderValue().hashCode()); } if (includeRequestMethod) { result = (prime * result) + ((httpData.getHttpInfo().getRequestMethod() == null) ? 0 : httpData.getHttpInfo().getRequestMethod().hashCode()); } return result; }
/** * Finds matching template for the given {@link HttpTimerData} by tag value. * * @param httpTimerData * Data to find matching template. * @param templates * List of templates to search. * @return Matching template of <code>null</code> if one can not be found. */ private HttpTimerData findTemplateForTagData(HttpTimerData httpTimerData, List<HttpTimerData> templates) { for (HttpTimerData template : templates) { if (Objects.equals(template.getHttpInfo().getInspectItTaggingHeaderValue(), httpTimerData.getHttpInfo().getInspectItTaggingHeaderValue())) { if (HttpTimerData.REQUEST_METHOD_MULTIPLE.equals(template.getHttpInfo().getRequestMethod()) || Objects.equals(template.getHttpInfo().getRequestMethod(), httpTimerData.getHttpInfo().getRequestMethod())) { return template; } } } return null; }
@Test public void aggregationURI() { final HttpTimerData data = new HttpTimerData(); data.getHttpInfo().setUri("URI"); data.getHttpInfo().setRequestMethod("GET"); data.setDuration(100d); data.setCpuDuration(10d); data.calculateCpuMin(10d); data.calculateCpuMax(10d); data.setCpuDuration(10d); final HttpTimerData data2 = new HttpTimerData(); data2.getHttpInfo().setUri("URI"); data2.getHttpInfo().setRequestMethod("POST"); data2.setDuration(500d); data2.calculateCpuMin(20d); data2.calculateCpuMax(20d); data2.setCpuDuration(20d); final List<HttpTimerData> input = new ArrayList<>(); Collections.addAll(input, data, data2); AggregationPerformer<HttpTimerData> aggregationPerformer = new AggregationPerformer<>(new HttpTimerDataAggregator(true, false)); aggregationPerformer.processCollection(input); final List<HttpTimerData> output = aggregationPerformer.getResultList(); assertThat(output, is(notNullValue())); assertThat(output.size(), is(equalTo(1))); HttpTimerData result = output.get(0); assertThat(result.getHttpInfo().getUri(), is(equalTo("URI"))); assertThat(result.getHttpInfo().hasInspectItTaggingHeader(), is(equalTo(false))); assertThat(result.getDuration(), is(equalTo(600d))); assertThat(result.getCpuDuration(), is(equalTo(30d))); }
String scheme = httpTimerData.getHttpInfo().getScheme(); boolean usedHTTPS = StringUtils.isNotEmpty(scheme) && "https".equalsIgnoreCase(scheme); if ((null != httpTimerData.getHttpInfo().getServerPort()) && (httpTimerData.getHttpInfo().getServerPort() > 0)) { portDescription = String.valueOf(httpTimerData.getHttpInfo().getServerPort()); } else { portDescription = NOT_AVAILABLE; table.addContentRow("Method:", null, new DetailsCellContent[] { new DetailsCellContent(StringUtils.defaultString(httpTimerData.getHttpInfo().getRequestMethod(), NOT_AVAILABLE)) }); table.addContentRow("Server Name:", null, new DetailsCellContent[] { new DetailsCellContent(StringUtils.defaultString(httpTimerData.getHttpInfo().getServerName(), NOT_AVAILABLE)) }); table.addContentRow("Port:", null, new DetailsCellContent[] { new DetailsCellContent(portDescription) }); table.addContentRow("URI:", null, new DetailsCellContent[] { new DetailsCellContent(StringUtils.defaultString(httpTimerData.getHttpInfo().getUri())) }); table.addContentRow("Query String:", null, new DetailsCellContent[] { new DetailsCellContent(StringUtils.defaultString(httpTimerData.getHttpInfo().getQueryString(), NOT_AVAILABLE)) }); if (httpTimerData.getHttpInfo().hasInspectItTaggingHeader()) { table.addContentRow("Tag Value:", null, new DetailsCellContent[] { new DetailsCellContent(httpTimerData.getHttpInfo().getInspectItTaggingHeaderValue()) });
/** * {@inheritDoc} */ @Override public String toString() { String sup = super.toString(); return sup + "HttpTimerData [uri=" + (null != httpInfo ? httpInfo.getUri() : HttpInfo.UNDEFINED) + ", parameters=" + parameters + ", attributes=" + attributes + ", headers=" + headers + "]"; } }
/** * Finds matching template for the given {@link HttpTimerData} by uri. * * @param httpTimerData * Data to find matching template. * @param templates * List of templates to search. * @param checkOnlyUri * If matching should be done only by uri. * @return Matching template of <code>null</code> if one can not be found. */ private HttpTimerData findTemplateForUriData(HttpTimerData httpTimerData, List<HttpTimerData> templates, boolean checkOnlyUri) { for (HttpTimerData template : templates) { if (Objects.equals(template.getHttpInfo().getUri(), httpTimerData.getHttpInfo().getUri())) { if (!checkOnlyUri && HttpTimerData.REQUEST_METHOD_MULTIPLE.equals(template.getHttpInfo().getRequestMethod())) { return template; } else if (Objects.equals(template.getHttpInfo().getRequestMethod(), httpTimerData.getHttpInfo().getRequestMethod())) { return template; } } } return null; }
data.getHttpInfo().setUri(extractor.getRequestUri(servletRequestClass, httpServletRequest)); data.getHttpInfo().setRequestMethod(extractor.getRequestMethod(servletRequestClass, httpServletRequest)); data.getHttpInfo().setScheme(extractor.getScheme(servletRequestClass, httpServletRequest)); data.getHttpInfo().setServerName(extractor.getServerName(servletRequestClass, httpServletRequest)); data.getHttpInfo().setServerPort(extractor.getServerPort(servletRequestClass, httpServletRequest)); data.getHttpInfo().setQueryString(extractor.getQueryString(servletRequestClass, httpServletRequest)); data.setHeaders(extractor.getHeaders(servletRequestClass, httpServletRequest));
@Test public void retrieveURL() { HttpInfo httpInfo = new HttpInfo(); httpInfo.setScheme("http"); httpInfo.setServerName("localhost"); httpInfo.setServerPort(8080); httpInfo.setUri("/test/uri"); httpInfo.setQueryString("test=true"); doReturn(httpTimerData).when(invocationSequenceData).getTimerData(); doReturn(httpInfo).when(httpTimerData).getHttpInfo(); String[] values = valueSource.getStringValues(invocationSequenceData, cachedDataService); assertThat(values, hasItemInArray("http://localhost:8080/test/uri?test=true")); }
@Test public void aggregationWithInspectITHeaderTwoDifferent() { final HttpTimerData data = new HttpTimerData(); Map<String, String> map1 = new HashMap<>(); MapUtils.putAll(map1, new String[][] { { HttpTimerData.INSPECTIT_TAGGING_HEADER, "tag1" } }); data.setHeaders(map1); data.getHttpInfo().setUri("URI"); data.getHttpInfo().setRequestMethod("GET"); final HttpTimerData data2 = new HttpTimerData(); Map<String, String> map2 = new HashMap<>(); MapUtils.putAll(map2, new String[][] { { HttpTimerData.INSPECTIT_TAGGING_HEADER, "tag2" } }); data2.setHeaders(map2); data2.getHttpInfo().setUri("URI"); data2.getHttpInfo().setRequestMethod("GET"); final List<HttpTimerData> input = new ArrayList<>(); Collections.addAll(input, data, data2); AggregationPerformer<HttpTimerData> aggregationPerformer = new AggregationPerformer<>(new HttpTimerDataAggregator(false, false)); aggregationPerformer.processCollection(input); final List<HttpTimerData> output = aggregationPerformer.getResultList(); assertThat(output, is(notNullValue())); assertThat(output.size(), is(equalTo(2))); }
@Test private void musteReturnAnObjectWithAPairLongStringIfTheTimerDataHasHttpTimerData() { InvocationSequenceData invocationSequenceData = new InvocationSequenceData(new Timestamp(10L), 10L, 20L, 108L); HttpTimerData timerData = new HttpTimerData(new Timestamp(10), 10, 10, 108L); HttpInfo httpInfo = new HttpInfo("URI", "requestMethod", "headerValue"); timerData.setHttpInfo(httpInfo); invocationSequenceData.setTimerData(timerData); Pair<Long, String> aggregationKey = (Pair<Long, String>) DiagnosisDataAggregator.getInstance().getAggregationKey(invocationSequenceData); assertThat("The string of the pair must be the sql data", aggregationKey.getSecond(), is(timerData.getHttpInfo().getUri())); }
if (!HttpInfo.UNDEFINED.equals(timerData.getHttpInfo().getUri())) { return "URI: " + timerData.getHttpInfo().getUri(); } else { return "Usecase: " + timerData.getHttpInfo().getInspectItTaggingHeaderValue();
/** * {@inheritDoc} */ @Override public void aggregate(IAggregatedData<HttpTimerData> aggregatedObject, HttpTimerData objectToAdd) { if (!uriBased) { if (!objectToAdd.getHttpInfo().hasInspectItTaggingHeader()) { // use case aggregation for elements that do not have any tagged value does not // make sense, thus we ignore these. return; } } aggregatedObject.aggregate(objectToAdd); if (!includeRequestMethod) { // If we have different request methods, we set the request method to "multiple" if (!objectToAdd.getHttpInfo().getRequestMethod().equals(aggregatedObject.getData().getHttpInfo().getRequestMethod()) && !aggregatedObject.getData().getHttpInfo().getRequestMethod().equals(HttpTimerData.REQUEST_METHOD_MULTIPLE)) { aggregatedObject.getData().getHttpInfo().setRequestMethod(HttpTimerData.REQUEST_METHOD_MULTIPLE); } } }
SearchCriteria wrong = new SearchCriteria("halB"); httpData.getHttpInfo().setInspectItTaggingHeaderValue("blaha"); searchCriteria.setCaseSensitive(false); assertThat(SearchFactory.isSearchCompatible(httpData, searchCriteria, repositoryDefinition), is(equalTo(true))); assertThat(SearchFactory.isSearchCompatible(httpData, wrong, repositoryDefinition), is(equalTo(false))); httpData.getHttpInfo().setInspectItTaggingHeaderValue(""); httpData.getHttpInfo().setUri("ablah"); searchCriteria.setCaseSensitive(false); assertThat(SearchFactory.isSearchCompatible(httpData, searchCriteria, repositoryDefinition), is(equalTo(true))); assertThat(SearchFactory.isSearchCompatible(httpData, wrong, repositoryDefinition), is(equalTo(false))); httpData.getHttpInfo().setUri(""); httpData.getHttpInfo().setRequestMethod("ablaha"); searchCriteria.setCaseSensitive(false); assertThat(SearchFactory.isSearchCompatible(httpData, searchCriteria, repositoryDefinition), is(equalTo(true))); httpData.getHttpInfo().setRequestMethod(""); httpData.setAttributes(map); searchCriteria.setCaseSensitive(false);
if (!httpTimerData.getHttpInfo().isUriDefined()) { throw new IllegalArgumentException("URI is not defined for the given HttpTimerData."); Matcher matcher = pattern.matcher(httpTimerData.getHttpInfo().getUri()); String result = ""; if (null != regExTemplate) {
case URL: if (InvocationSequenceDataHelper.hasHttpTimerData(o1) && InvocationSequenceDataHelper.hasHttpTimerData(o2)) { String uri1 = ((HttpTimerData) o1.getTimerData()).getHttpInfo().getUrl(); String uri2 = ((HttpTimerData) o2.getTimerData()).getHttpInfo().getUrl(); return ObjectUtils.compare(uri1, uri2); } else if (InvocationSequenceDataHelper.hasHttpTimerData(o1)) { case USE_CASE: if (InvocationSequenceDataHelper.hasHttpTimerData(o1) && InvocationSequenceDataHelper.hasHttpTimerData(o2)) { String useCase1 = ((HttpTimerData) o1.getTimerData()).getHttpInfo().getInspectItTaggingHeaderValue(); String useCase2 = ((HttpTimerData) o2.getTimerData()).getHttpInfo().getInspectItTaggingHeaderValue(); return ObjectUtils.compare(useCase1, useCase2); } else if (InvocationSequenceDataHelper.hasHttpTimerData(o1)) {
@Test public void retrieveRequestMethod() { HttpInfo httpInfo = new HttpInfo(); httpInfo.setRequestMethod("POST"); doReturn(httpTimerData).when(invocationSequenceData).getTimerData(); doReturn(httpInfo).when(httpTimerData).getHttpInfo(); String[] values = valueSource.getStringValues(invocationSequenceData, cachedDataService); assertThat(values, hasItemInArray("POST")); }
/** * Checks if this data has the inspectIT tagging header set. * * @return if this data has the inspectIT tagging header set. */ public boolean hasInspectItTaggingHeader() { return null != getInspectItTaggingHeaderValue(); }