public void MetricAggregationByInstanceIsScopedToLogicalEndpoint() { var processingTimeStore = new ProcessingTimeStore(); var endpointRegistry = new EndpointRegistry(); var apiController = CreateConroller(processingTimeStore, endpointRegistry); var instanceAId = new EndpointInstanceId("EndpointA", "instance"); var instanceBId = new EndpointInstanceId("EndpointB", "instance"); endpointRegistry.Record(instanceAId); endpointRegistry.Record(instanceBId); var period = HistoryPeriod.FromMinutes(DiagramApiController.DefaultHistory); var now = DateTime.UtcNow.Subtract(new TimeSpan(period.IntervalSize.Ticks * period.DelayedIntervals)); var dataA = new RawMessage.Entry { DateTicks = now.Ticks, Value = 5 }; var dataB = new RawMessage.Entry { DateTicks = now.Ticks, Value = 10 }; processingTimeStore.Store(new[] { dataA }, instanceAId, EndpointMessageType.Unknown(instanceAId.EndpointName)); processingTimeStore.Store(new[] { dataB }, instanceBId, EndpointMessageType.Unknown(instanceBId.EndpointName)); var result = apiController.GetSingleEndpointMetrics(instanceAId.EndpointName); var contentResult = result as OkNegotiatedContentResult <MonitoredEndpointDetails>; var model = contentResult.Content; Assert.AreEqual(5, model.Instances[0].Metrics["ProcessingTime"].Average); }
public async Task MetricAggregationByInstanceIsScopedToLogicalEndpoint() { var processingTimeStore = new ProcessingTimeStore(); var endpointRegistry = new EndpointRegistry(); var queryAction = CreateQuery(processingTimeStore, endpointRegistry); var instanceAId = new EndpointInstanceId("EndpointA", "instance"); var instanceBId = new EndpointInstanceId("EndpointB", "instance"); endpointRegistry.Record(instanceAId); endpointRegistry.Record(instanceBId); var period = HistoryPeriod.FromMinutes(MonitoredEndpointsModule.DefaultHistory); var now = DateTime.UtcNow.Subtract(new TimeSpan(period.IntervalSize.Ticks * period.DelayedIntervals)); var dataA = new RawMessage.Entry { DateTicks = now.Ticks, Value = 5 }; var dataB = new RawMessage.Entry { DateTicks = now.Ticks, Value = 10 }; processingTimeStore.Store(new[] { dataA }, instanceAId, EndpointMessageType.Unknown(instanceAId.EndpointName)); processingTimeStore.Store(new[] { dataB }, instanceBId, EndpointMessageType.Unknown(instanceBId.EndpointName)); var result = await queryAction(new { instanceAId.EndpointName }.ToDynamic(), new CancellationToken()); var model = (MonitoredEndpointDetails)result.NegotiationContext.DefaultModel; Assert.AreEqual(5, model.Instances[0].Metrics["ProcessingTime"].Average); }
public async Task GetMonitoredEndpointsQueryTest(int numberOfEndpoints, int numberOfInstances, int sendReportEvery, int numberOfEntriesInReport, int queryEveryInMilliseconds, int numberOfQueries) { var instances = BuildInstances(numberOfEndpoints, numberOfInstances); foreach (var instance in instances) { endpointRegistry.Record(instance); } var source = new CancellationTokenSource(); var reporters = new[] { BuildReporters(sendReportEvery, numberOfEntriesInReport, instances, source, (e, i) => criticalTimeStore.Store(e, i, EndpointMessageType.Unknown(i.EndpointName))), BuildReporters(sendReportEvery, numberOfEntriesInReport, instances, source, (e, i) => processingTimeStore.Store(e, i, EndpointMessageType.Unknown(i.EndpointName))), BuildReporters(sendReportEvery, numberOfEntriesInReport, instances, source, (e, i) => retriesStore.Store(e, i, EndpointMessageType.Unknown(i.EndpointName))), BuildReporters(sendReportEvery, numberOfEntriesInReport, instances, source, (e, i) => queueLengthProvider.Process(i, new TaggedLongValueOccurrence { Entries = e, TagValue = string.Empty })) }.SelectMany(i => i).ToArray(); var histogram = CreateTimeHistogram(); for (var i = 0; i < numberOfQueries; i++) { var start = Stopwatch.GetTimestamp(); await GetMonitoredEndpoints().ConfigureAwait(false); var elapsed = Stopwatch.GetTimestamp() - start; histogram.RecordValue(elapsed); await Task.Delay(queryEveryInMilliseconds); } source.Cancel(); await Task.WhenAll(reporters).ConfigureAwait(false); var reportFinalHistogram = MergeHistograms(reporters); Report("Querying", histogram, TimeSpan.FromMilliseconds(150)); Report("Reporters", reportFinalHistogram, TimeSpan.FromMilliseconds(20)); }
public void ValidateIfConnectivityMathIsCorrect() { var endpointName = "Endpoint"; var instanceIds = new[] { "a", "b", "c" }; var instances = instanceIds.Select(instanceId => new EndpointInstanceId(endpointName, instanceId)).ToArray(); Array.ForEach(instances, instance => endpointRegistry.Record(instance)); var period = HistoryPeriod.FromMinutes(DiagramApiController.DefaultHistory); // 5 minutes, 5 second period var now = DateTime.UtcNow; var timestamp = now.Subtract(new TimeSpan(period.IntervalSize.Ticks * period.DelayedIntervals)); // now - 5 seconds var samples = new[] { new RawMessage.Entry { DateTicks = timestamp.Ticks, Value = 5 }, new RawMessage.Entry { DateTicks = timestamp.Ticks, Value = 10 } }; var connected = instances.Take(2).ToArray(); Array.ForEach(connected, instance => activityTracker.Record(instance, now)); Array.ForEach(connected, instance => processingTimeStore.Store(samples, instance, EndpointMessageType.Unknown(instance.EndpointName))); var result = apiController.GetAllEndpointsMetrics(); var contentResult = result as OkNegotiatedContentResult <MonitoredEndpoint[]>; var model = contentResult.Content; var item = model[0]; Assert.AreEqual(3, item.EndpointInstanceIds.Length, nameof(item.EndpointInstanceIds)); Assert.AreEqual(2, item.ConnectedCount, nameof(item.ConnectedCount)); Assert.AreEqual(1, item.DisconnectedCount, nameof(item.DisconnectedCount)); }