/** * Initializes a new instance of the HttpRequestTelemetry class with the given name, * time stamp, duration, HTTP response code and success property values. * @param name A user-friendly name for the request. * @param timestamp The time of the request. * @param duration The duration, in milliseconds, of the request processing. * @param responseCode The HTTP response code. * @param success 'true' if the request was a success, 'false' otherwise. */ public RequestTelemetry(String name, Date timestamp, long duration, String responseCode, boolean success) { this(name, timestamp, new Duration(duration), responseCode, success); }
@Override public boolean equals(Object other) { if (this == other) { return true; } if (!(other instanceof Duration)) { return false; } Duration that = (Duration)other; return this.days == that.getDays() && this.hours == that.getHours() && this.minutes == that.getMinutes() && this.seconds == that.getSeconds() && this.milliseconds == that.getMilliseconds(); }
@Test public void testTotalMilliseconds() { Duration duration = new Duration(1, 1, 1, 1, 1); // 90061001 ms is 1 day, 1 hour, 1 minute, 1 sec and 1 milliseconds. Assert.assertEquals(90061001, duration.getTotalMilliseconds()); }
/** * Gets the page view duration. * @return The page view duration. */ public long getDuration() { return data.getDuration().getTotalMilliseconds(); }
private void addRequest(RequestTelemetry requestTelemetry) { Counters counters = this.counters.get(); if (counters == null) { return; } counters.requestsAndDurations.addAndGet(Counters.encodeCountAndDuration(1, requestTelemetry.getDuration().getMilliseconds())); if (!requestTelemetry.isSuccess()) { counters.unsuccessfulRequests.incrementAndGet(); } } }
@Override public boolean process(Telemetry telemetry) { if (telemetry == null) { return true; } if (!hasBlocked && minimumDurationInMS <= 0) { return true; } if (telemetry instanceof RequestTelemetry) { RequestTelemetry requestTelemetry = (RequestTelemetry) telemetry; String responseCode = requestTelemetry.getResponseCode(); if (exactBadResponseCodes.contains(requestTelemetry.getResponseCode())) { return false; } int asInt = Integer.valueOf(responseCode); for (FromTo fromTo : ignoredResponseCodeRange) { if (fromTo.from <= asInt && fromTo.to >= asInt) { return false; } } Duration requestDuration = requestTelemetry.getDuration(); if (requestDuration != null && requestDuration.getTotalMilliseconds() < minimumDurationInMS) { return false; } if (LocalStringsUtils.isNullOrEmpty(requestTelemetry.getResponseCode())) { return true; } } return true; }
/** * success=true * @return */ public Runnable getTrackDependency() { return customCases.getTrackDependency("AiTestDependency", "TestCommand1", new Duration(789L), true); }
private static void verify(Duration duration, long expectedDays, int expectedHours, int expectedMinutes, int expectedSeconds, int expectedMilliseconds, String expectedString) { assertEquals(expectedString, duration.toString()); assertEquals(expectedDays, duration.getDays()); assertEquals(expectedHours, duration.getHours()); assertEquals(expectedMinutes, duration.getMinutes()); assertEquals(expectedSeconds, duration.getSeconds()); assertEquals(expectedMilliseconds, duration.getMilliseconds()); }
@Override public Duration deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { final String value = json.getAsString(); final int firstDot = value.indexOf('.'); final boolean hasDays = firstDot > -1 && firstDot < value.indexOf(':'); final String[] parts = value.split("[:.]"); // [days.]hours:minutes:seconds[.milliseconds] final long[] conversionFactor = new long[]{86400000, 3600000, 60000, 1000, 1}; int conversionIndex = hasDays ? 0 : 1; long duration = 0; for (int i = 0; i < parts.length; i++) { String part = (conversionIndex == conversionFactor.length-1) ? parts[i].substring(0,3) : parts[i]; duration += Long.parseLong(part) * conversionFactor[conversionIndex++]; } return new Duration(duration); } }
/** * Sets the page view duration. * @param duration The page view duration. */ public void setDuration(long duration) { data.setDuration(new Duration(duration)); }
@Test(expected = IllegalArgumentException.class) public void testNovValidNegativeSeconds() { new Duration(0, 0, 0, -60, 0); }
@Test(expected = IllegalArgumentException.class) public void testNovValidPositiveMinutes() { new Duration(0, 0, -60, 0, 0); }
@Test(expected = IllegalArgumentException.class) public void testNovValidPositiveMilliseconds() { new Duration(0, 0, 0, 0, 1000); }
@Test(expected = IllegalArgumentException.class) public void testNovValidNegativeHours() { new Duration(0, -24, 0, 0, 0); }
@Test(expected = IllegalArgumentException.class) public void testNovValidPositiveHours() { new Duration(0, 24, 0, 0, 0); }
@Test(expected = IllegalArgumentException.class) public void testNovValidNegativeMinutes() { new Duration(0, 0, -60, 0, 0); }
@Test(expected = IllegalArgumentException.class) public void testNovValidPositiveSeconds() { new Duration(0, 0, 0, 60, 0); }
@Test(expected = IllegalArgumentException.class) public void testNovValidNegativeMilliseconds() { new Duration(0, 0, 0, 0, -1); }
private void sendInstrumentationTelemetry(MethodData methodData, Throwable throwable) { long durationInMilliSeconds = nanoToMilliseconds(methodData.interval); RemoteDependencyTelemetry telemetry = new RemoteDependencyTelemetry(methodData.name, null, new Duration(durationInMilliSeconds), throwable == null); telemetry.setType(methodData.type); Date dependencyStartDate = new Date(System.currentTimeMillis() - durationInMilliSeconds); telemetry.setTimestamp(dependencyStartDate); InternalLogger.INSTANCE.trace("Sending RDD event for '%s'", methodData.name); telemetryClient.track(telemetry); if (throwable != null) { ExceptionTelemetry exceptionTelemetry = new ExceptionTelemetry(throwable); telemetryClient.track(exceptionTelemetry); } }