public void QuickPulseServiceClientFillsInSampleWeightWhenSubmittingToService() { // ARRANGE var now = DateTimeOffset.UtcNow; var serviceClient = new QuickPulseServiceClient(this.serviceEndpoint, string.Empty, string.Empty, string.Empty, string.Empty, new Clock()); var sample1 = new QuickPulseDataSample( new QuickPulseDataAccumulator { AIRequestCountAndDurationInTicks = QuickPulseDataAccumulator.EncodeCountAndDuration(3, 10000), StartTimestamp = now, EndTimestamp = now.AddSeconds(1) }, new Dictionary <string, Tuple <PerformanceCounterData, float> >()); var sample2 = new QuickPulseDataSample( new QuickPulseDataAccumulator { AIDependencyCallCountAndDurationInTicks = QuickPulseDataAccumulator.EncodeCountAndDuration(4, 10000), StartTimestamp = now, EndTimestamp = now.AddSeconds(1) }, new Dictionary <string, Tuple <PerformanceCounterData, float> >()); // ACT serviceClient.SubmitSamples(new[] { sample1, sample2 }, string.Empty); // ASSERT this.listener.Stop(); Assert.AreEqual(3, this.samples[0].Item2.Metrics.Single(m => m.Name == @"\ApplicationInsights\Request Duration").Weight); Assert.AreEqual(4, this.samples[1].Item2.Metrics.Single(m => m.Name == @"\ApplicationInsights\Dependency Call Duration").Weight); }
public void QuickPulseDataAccumulatorEncodesCountAndDurationOverflowDuration() { // ARRANGE // ACTt long encodedValue = QuickPulseDataAccumulator.EncodeCountAndDuration(MaxCount, MaxDuration + 1); Tuple <long, long> decodedValues = QuickPulseDataAccumulator.DecodeCountAndDuration(encodedValue); // ASSERT Assert.AreEqual(0, decodedValues.Item1); Assert.AreEqual(0, decodedValues.Item2); }
public void QuickPulseDataAccumulatorEncodesCountAndDuration() { // ARRANGE long count = 42; long duration = 102; // ACT long encodedValue = QuickPulseDataAccumulator.EncodeCountAndDuration(count, duration); Tuple <long, long> decodedValues = QuickPulseDataAccumulator.DecodeCountAndDuration(encodedValue); // ASSERT Assert.AreEqual(count, decodedValues.Item1); Assert.AreEqual(duration, decodedValues.Item2); }
private void UpdateRequestAggregates(RequestTelemetry requestTelemetry) { long requestCountAndDurationInTicks = QuickPulseDataAccumulator.EncodeCountAndDuration(1, requestTelemetry.Duration.Ticks); Interlocked.Add(ref this.dataAccumulatorManager.CurrentDataAccumulator.AIRequestCountAndDurationInTicks, requestCountAndDurationInTicks); if (requestTelemetry.Success == true) { Interlocked.Increment(ref this.dataAccumulatorManager.CurrentDataAccumulator.AIRequestSuccessCount); } else { Interlocked.Increment(ref this.dataAccumulatorManager.CurrentDataAccumulator.AIRequestFailureCount); } }
public void QuickPulseDataSampleCalculatesAIRpsCorrectly() { // ARRANGE var accumulator = new QuickPulseDataAccumulator { StartTimestamp = DateTimeOffset.UtcNow, EndTimestamp = DateTimeOffset.UtcNow.AddSeconds(2), AIRequestCountAndDurationInTicks = QuickPulseDataAccumulator.EncodeCountAndDuration(10, 0) }; // ACT var dataSample = new QuickPulseDataSample(accumulator, this.dummyDictionary); // ASSERT Assert.AreEqual(10.0 / 2, dataSample.AIRequestsPerSecond); }
private void UpdateDependencyAggregates(DependencyTelemetry dependencyTelemetry) { long dependencyCallCountAndDurationInTicks = QuickPulseDataAccumulator.EncodeCountAndDuration(1, dependencyTelemetry.Duration.Ticks); Interlocked.Add( ref this.dataAccumulatorManager.CurrentDataAccumulator.AIDependencyCallCountAndDurationInTicks, dependencyCallCountAndDurationInTicks); if (dependencyTelemetry.Success == true) { Interlocked.Increment(ref this.dataAccumulatorManager.CurrentDataAccumulator.AIDependencyCallSuccessCount); } else if (dependencyTelemetry.Success == false) { Interlocked.Increment(ref this.dataAccumulatorManager.CurrentDataAccumulator.AIDependencyCallFailureCount); } }
public void QuickPulseDataSampleCalculatesAIRequestDurationAveCorrectly() { // ARRANGE var accumulator = new QuickPulseDataAccumulator { StartTimestamp = DateTimeOffset.UtcNow, EndTimestamp = DateTimeOffset.UtcNow.AddSeconds(2), AIRequestCountAndDurationInTicks = QuickPulseDataAccumulator.EncodeCountAndDuration(10, TimeSpan.FromSeconds(5).Ticks) }; // ACT var dataSample = new QuickPulseDataSample(accumulator, this.dummyDictionary); // ASSERT Assert.AreEqual(TimeSpan.FromSeconds(5).TotalMilliseconds / 10.0, dataSample.AIRequestDurationAveInMs); }
public void QuickPulseDataSampleCalculatesAIDependencyCallDurationAveWhenDependencyCallCountIsZeroCorrectly() { // ARRANGE var accumulator = new QuickPulseDataAccumulator { StartTimestamp = DateTimeOffset.UtcNow, EndTimestamp = DateTimeOffset.UtcNow.AddSeconds(2), AIDependencyCallCountAndDurationInTicks = QuickPulseDataAccumulator.EncodeCountAndDuration(0, TimeSpan.FromSeconds(5).Ticks) }; // ACT var dataSample = new QuickPulseDataSample(accumulator, this.dummyDictionary); // ASSERT Assert.AreEqual(0.0, dataSample.AIDependencyCallDurationAveInMs); }
public void QuickPulseDataSampleCalculatesAIDependencyCallDurationAveWhenDependencyCallCountIsZeroCorrectly() { // ARRANGE var accumulator = new QuickPulseDataAccumulator(new CollectionConfiguration(EmptyCollectionConfigurationInfo, out this.errors, new ClockMock())) { StartTimestamp = this.now, EndTimestamp = this.now.AddSeconds(2), AIDependencyCallCountAndDurationInTicks = QuickPulseDataAccumulator.EncodeCountAndDuration(0, TimeSpan.FromSeconds(5).Ticks) }; // ACT var dataSample = new QuickPulseDataSample(accumulator, this.dummyDictionary, this.dummyTopCpu, false); // ASSERT Assert.AreEqual(0.0, dataSample.AIDependencyCallDurationAveInMs); }
public void QuickPulseDataSampleCalculatesAIRpsCorrectly() { // ARRANGE var accumulator = new QuickPulseDataAccumulator(new CollectionConfiguration(EmptyCollectionConfigurationInfo, out this.errors, new ClockMock())) { StartTimestamp = this.now, EndTimestamp = this.now.AddSeconds(2), AIRequestCountAndDurationInTicks = QuickPulseDataAccumulator.EncodeCountAndDuration(10, 0) }; // ACT var dataSample = new QuickPulseDataSample(accumulator, this.dummyDictionary, this.dummyTopCpu, false); // ASSERT Assert.AreEqual(10.0 / 2, dataSample.AIRequestsPerSecond); }
public void QuickPulseDataSampleCalculatesAIRequestDurationAveWhenRequestCountIsZeroCorrectly() { // ARRANGE var accumulator = new QuickPulseDataAccumulator { StartTimestamp = this.now, EndTimestamp = this.now.AddSeconds(2), AIRequestCountAndDurationInTicks = QuickPulseDataAccumulator.EncodeCountAndDuration(0, TimeSpan.FromSeconds(5).Ticks) }; // ACT var dataSample = new QuickPulseDataSample(accumulator, this.dummyDictionary, this.dummyTopCpu, false); // ASSERT Assert.AreEqual(0.0, dataSample.AIRequestDurationAveInMs); }
public void QuickPulseDataSampleCalculatesAIDependencyCallsPerSecondCorrectly() { // ARRANGE var accumulator = new QuickPulseDataAccumulator { StartTimestamp = this.now, EndTimestamp = this.now.AddSeconds(2), AIDependencyCallCountAndDurationInTicks = QuickPulseDataAccumulator.EncodeCountAndDuration(10, 0) }; // ACT var dataSample = new QuickPulseDataSample(accumulator, this.dummyDictionary, this.dummyTopCpu, false); // ASSERT Assert.AreEqual(10.0 / 2, dataSample.AIDependencyCallsPerSecond); }
/// <summary> /// Intercepts telemetry items and updates QuickPulse data when needed. /// </summary> /// <param name="telemetry">Telemetry item being tracked by AI.</param> /// <remarks>This method is performance critical since every AI telemetry item goes through it.</remarks> public void Process(ITelemetry telemetry) { bool letItemThrough = true; try { // filter out QPS requests from dependencies even when we're not collecting (for Pings) var dependencyCall = telemetry as DependencyTelemetry; if (this.serviceEndpoint != null && dependencyCall != null && !string.IsNullOrWhiteSpace(dependencyCall.Name)) { if (dependencyCall.Name.IndexOf(this.serviceEndpoint.Host, StringComparison.OrdinalIgnoreCase) >= 0) { // this is an HTTP request to QuickPulse service, we don't want to let it through letItemThrough = false; return; } } if (!this.isCollecting || this.dataAccumulatorManager == null) { return; } // only process items that are going to the instrumentation key that our module is initialized with if (this.config != null && !string.IsNullOrWhiteSpace(this.config.InstrumentationKey) && telemetry.Context != null && string.Equals(telemetry.Context.InstrumentationKey, this.config.InstrumentationKey, StringComparison.OrdinalIgnoreCase)) { var request = telemetry as RequestTelemetry; var exception = telemetry as ExceptionTelemetry; if (request != null) { bool success = IsRequestSuccessful(request); long requestCountAndDurationInTicks = QuickPulseDataAccumulator.EncodeCountAndDuration(1, request.Duration.Ticks); Interlocked.Add(ref this.dataAccumulatorManager.CurrentDataAccumulator.AIRequestCountAndDurationInTicks, requestCountAndDurationInTicks); if (success) { Interlocked.Increment(ref this.dataAccumulatorManager.CurrentDataAccumulator.AIRequestSuccessCount); } else { Interlocked.Increment(ref this.dataAccumulatorManager.CurrentDataAccumulator.AIRequestFailureCount); } } else if (dependencyCall != null) { long dependencyCallCountAndDurationInTicks = QuickPulseDataAccumulator.EncodeCountAndDuration(1, dependencyCall.Duration.Ticks); Interlocked.Add(ref this.dataAccumulatorManager.CurrentDataAccumulator.AIDependencyCallCountAndDurationInTicks, dependencyCallCountAndDurationInTicks); if (dependencyCall.Success == true) { Interlocked.Increment(ref this.dataAccumulatorManager.CurrentDataAccumulator.AIDependencyCallSuccessCount); } else if (dependencyCall.Success == false) { Interlocked.Increment(ref this.dataAccumulatorManager.CurrentDataAccumulator.AIDependencyCallFailureCount); } } else if (exception != null) { Interlocked.Increment(ref this.dataAccumulatorManager.CurrentDataAccumulator.AIExceptionCount); } } } catch (Exception e) { // whatever happened up there - we don't want to interrupt the chain of processors QuickPulseEventSource.Log.UnknownErrorEvent(e.ToInvariantString()); } finally { if (letItemThrough) { this.Next.Process(telemetry); } } }