HttpInfo httpInfo = httpTimerData.getHttpInfo(); String tag = httpInfo.hasInspectItTaggingHeader() ? httpInfo.getInspectItTaggingHeaderValue() : null; // NOPMD String requestMethod = httpInfo.getRequestMethod();
if (httpTimerData.getHttpInfo().hasInspectItTaggingHeader()) { tags.add(httpTimerData.getHttpInfo().getInspectItTaggingHeaderValue());
/** * {@inheritDoc} */ @Override public List<HttpTimerData> getChartingHttpTimerDataFromDateToDate(Collection<HttpTimerData> templates, Date fromDate, Date toDate, boolean retrieveByTag) { if (CollectionUtils.isNotEmpty(templates)) { StorageIndexQuery query = httpDataQueryFactory.getFindAllHttpTimersQuery(templates.iterator().next(), fromDate, toDate); if (!retrieveByTag) { Set<String> uris = new HashSet<>(); for (HttpTimerData httpTimerData : templates) { if (!HttpInfo.UNDEFINED.equals(httpTimerData.getHttpInfo().getUri())) { uris.add(httpTimerData.getHttpInfo().getUri()); } } query.addIndexingRestriction(IndexQueryRestrictionFactory.isInCollection("uri", uris)); } else { Set<String> tags = new HashSet<>(); for (HttpTimerData httpTimerData : templates) { if (httpTimerData.getHttpInfo().hasInspectItTaggingHeader()) { tags.add(httpTimerData.getHttpInfo().getInspectItTaggingHeaderValue()); } } query.addIndexingRestriction(IndexQueryRestrictionFactory.isInCollection("inspectItTaggingHeaderValue", tags)); } return super.executeQuery(query, TIMESTAMP_COMPARATOR); } else { return Collections.emptyList(); } }
@Test public void noUri() throws Exception { when(cachedDataService.getPlatformIdentForId(PLATFORM_ID)).thenReturn(null); long time = RandomUtils.nextLong(); when(data.getPlatformIdent()).thenReturn(PLATFORM_ID); when(data.getTimeStamp()).thenReturn(new Timestamp(time)); when(data.getHttpInfo()).thenReturn(httpInfo); when(httpInfo.getUri()).thenReturn(null); when(httpInfo.hasInspectItTaggingHeader()).thenReturn(false); when(httpInfo.getInspectItTaggingHeaderValue()).thenReturn(null); Collection<Builder> pointBuilderCol = builder.createBuilders(data); assertThat(pointBuilderCol.size(), is(1)); Builder pointBuilder = pointBuilderCol.iterator().next(); assertThat(getMeasurement(pointBuilder), is(Series.Http.NAME)); assertThat(getTime(pointBuilder), is(time)); assertThat(getPrecision(pointBuilder), is(TimeUnit.MILLISECONDS)); assertThat(getTags(pointBuilder), not(hasKey(Series.Http.TAG_URI))); assertThat(getFields(pointBuilder), hasEntry(Series.Http.FIELD_DURATION, (Object) data.getDuration())); }
@Test public void noTag() throws Exception { when(cachedDataService.getPlatformIdentForId(PLATFORM_ID)).thenReturn(platformIdent); long time = RandomUtils.nextLong(); when(data.getPlatformIdent()).thenReturn(PLATFORM_ID); when(data.getTimeStamp()).thenReturn(new Timestamp(time)); when(data.getHttpInfo()).thenReturn(httpInfo); when(httpInfo.getUri()).thenReturn(URI); when(httpInfo.hasInspectItTaggingHeader()).thenReturn(false); when(httpInfo.getInspectItTaggingHeaderValue()).thenReturn(null); Collection<Builder> pointBuilderCol = builder.createBuilders(data); assertThat(pointBuilderCol.size(), is(1)); Builder pointBuilder = pointBuilderCol.iterator().next(); assertThat(getMeasurement(pointBuilder), is(Series.Http.NAME)); assertThat(getTime(pointBuilder), is(time)); assertThat(getPrecision(pointBuilder), is(TimeUnit.MILLISECONDS)); assertThat(getTags(pointBuilder), not(hasKey(Series.Http.TAG_INSPECTIT_TAGGING_HEADER))); assertThat(getFields(pointBuilder), hasEntry(Series.Http.FIELD_DURATION, (Object) data.getDuration())); }
@Test public void noPlatform() throws Exception { when(cachedDataService.getPlatformIdentForId(PLATFORM_ID)).thenReturn(null); long time = RandomUtils.nextLong(); when(data.getPlatformIdent()).thenReturn(PLATFORM_ID); when(data.getTimeStamp()).thenReturn(new Timestamp(time)); when(data.getHttpInfo()).thenReturn(httpInfo); when(httpInfo.getUri()).thenReturn(URI); when(httpInfo.hasInspectItTaggingHeader()).thenReturn(true); when(httpInfo.getInspectItTaggingHeaderValue()).thenReturn(TAG); Collection<Builder> pointBuilderCol = builder.createBuilders(data); assertThat(pointBuilderCol.size(), is(1)); Builder pointBuilder = pointBuilderCol.iterator().next(); assertThat(getMeasurement(pointBuilder), is(Series.Http.NAME)); assertThat(getTime(pointBuilder), is(time)); assertThat(getPrecision(pointBuilder), is(TimeUnit.MILLISECONDS)); assertThat(getTags(pointBuilder), hasEntry(Series.TAG_AGENT_ID, String.valueOf(PLATFORM_ID))); assertThat(getTags(pointBuilder), not(hasKey(Series.TAG_AGENT_NAME))); assertThat(getFields(pointBuilder), hasEntry(Series.Http.FIELD_DURATION, (Object) data.getDuration())); }
@Test public void happyPath() throws Exception { when(cachedDataService.getPlatformIdentForId(PLATFORM_ID)).thenReturn(platformIdent); long time = RandomUtils.nextLong(); when(data.getPlatformIdent()).thenReturn(PLATFORM_ID); when(data.getTimeStamp()).thenReturn(new Timestamp(time)); when(data.getDuration()).thenReturn(RandomUtils.nextDouble()); when(data.getHttpInfo()).thenReturn(httpInfo); when(httpInfo.getUri()).thenReturn(URI); when(httpInfo.hasInspectItTaggingHeader()).thenReturn(true); when(httpInfo.getInspectItTaggingHeaderValue()).thenReturn(TAG); Collection<Builder> pointBuilderCol = builder.createBuilders(data); assertThat(pointBuilderCol.size(), is(1)); Builder pointBuilder = pointBuilderCol.iterator().next(); assertThat(getMeasurement(pointBuilder), is(Series.Http.NAME)); assertThat(getTime(pointBuilder), is(time)); assertThat(getPrecision(pointBuilder), is(TimeUnit.MILLISECONDS)); assertThat(getTags(pointBuilder), hasEntry(Series.TAG_AGENT_ID, String.valueOf(PLATFORM_ID))); assertThat(getTags(pointBuilder), hasEntry(Series.TAG_AGENT_NAME, String.valueOf(AGENT_NAME))); assertThat(getTags(pointBuilder), hasEntry(Series.Http.TAG_URI, String.valueOf(URI))); assertThat(getTags(pointBuilder), hasEntry(Series.Http.TAG_INSPECTIT_TAGGING_HEADER, String.valueOf(TAG))); assertThat(getFields(pointBuilder), hasEntry(Series.Http.FIELD_DURATION, (Object) data.getDuration())); }
/** * {@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()); } }
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 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); } } }
@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))); }
HttpTimerData result = output.get(0); assertThat(result.getHttpInfo().getUri(), is(equalTo(HttpInfo.UNDEFINED))); assertThat(result.getHttpInfo().hasInspectItTaggingHeader(), is(equalTo(true))); assertThat(result.getHttpInfo().getInspectItTaggingHeaderValue(), is(equalTo("tag1"))); assertThat(result.getDuration(), is(equalTo(600d)));