private void ProcessFailedItems(IList <TRequest> items, PartitionedBlockingCollection <TRequest> collection) { foreach (var item in items) { if (!collection.TryAdd(item)) { _agentHealthReporter.ReportInfiniteTracingSpanEventsDropped(1); } } }
public void RecordDroppedSpans(int countDroppedSpans) { _agentHealthReporter.ReportInfiniteTracingSpanEventsDropped(countDroppedSpans); }
[TestCase(5, 0, 2, 1, 5, "Valid to invalid")] //a new invalid config should prevent restart of the consumer public void Queue_SizeConfigChangeScenarios(int expectedInitialCapacity, int expectedUpdatedCapacity, int expectedShutdownCalls, int expectedStartCalls, int expectedDroppedSpans, string _) { var actualQueue = null as PartitionedBlockingCollection <Span>; var actualStartConsumingCalls = 0; var actualShudownCalls = 0; long actualCountSpansSeen = 0; long actualCountSpansDropped = 0; //Set up Streaming Service that does not dequeue items, that captures a reference to the collection var streamingSvc = GetMockStreamingService(true, true); Mock.Arrange(() => streamingSvc.StartConsumingCollection(Arg.IsAny <PartitionedBlockingCollection <Span> >())) .DoInstead <PartitionedBlockingCollection <Span> >((c) => { actualStartConsumingCalls++; actualQueue = c; }); Mock.Arrange(() => streamingSvc.Shutdown(Arg.IsAny <bool>())) .DoInstead(() => { actualShudownCalls++; }); Mock.Arrange(() => _currentConfiguration.InfiniteTracingQueueSizeSpans).Returns(expectedInitialCapacity); Mock.Arrange(() => _mockAgentHealthReporter.ReportInfiniteTracingSpanEventsDropped(Arg.IsAny <long>())) .DoInstead <long>((countSpans) => { actualCountSpansDropped += countSpans; }); Mock.Arrange(() => _mockAgentHealthReporter.ReportInfiniteTracingSpanEventsSeen(Arg.IsAny <long>())) .DoInstead <long>((countSpans) => { actualCountSpansSeen += countSpans; }); var aggregator = CreateAggregator(streamingSvc); FireAgentConnectedEvent(); var testItems = new List <ISpanEventWireModel>(); //add too many items to the queue w/o servicing it. for (var i = 0; i < expectedInitialCapacity; i++) { testItems.Add(new SpanAttributeValueCollection()); } aggregator.Collect(testItems); var initialQueue = actualQueue; var initialQueueItems = actualQueue?.ToList(); actualQueue = null; Mock.Arrange(() => _currentConfiguration.InfiniteTracingQueueSizeSpans).Returns(expectedUpdatedCapacity); FireAgentConnectedEvent(); var updatedQueue = actualQueue; var updatedQueueItems = actualQueue?.ToList(); actualQueue = null; NrAssert.Multiple ( () => Assert.AreEqual(expectedShutdownCalls, actualShudownCalls), () => Assert.AreEqual(expectedStartCalls, actualStartConsumingCalls) ); // If the INITIAL config was valid, test that the queue is correctly // configured and has the correct items if (expectedInitialCapacity > 0) { var expectedQueueItems = testItems .Take(expectedInitialCapacity) .Select(x => x.Span).ToList(); NrAssert.Multiple ( () => Assert.AreEqual(expectedInitialCapacity, initialQueue.Capacity, $"Initial Queue Size."), () => Assert.AreEqual(expectedInitialCapacity, initialQueueItems.Count), () => CollectionAssert.AreEqual(expectedQueueItems, initialQueueItems, "Initial Queue Items") ); } else { NrAssert.Multiple ( () => Assert.IsNull(initialQueue) ); } // If the UPDATED config was valid, test that the queue is correctly // configured and has the correct items if (expectedUpdatedCapacity > 0) { var expectedQueueItems = testItems .Take(Math.Min(expectedInitialCapacity, expectedUpdatedCapacity)) .Select(x => x.Span).ToList(); NrAssert.Multiple ( () => Assert.AreEqual(expectedUpdatedCapacity, updatedQueue.Capacity, $"Updated Queue Size."), () => Assert.AreEqual(Math.Min(expectedInitialCapacity, expectedUpdatedCapacity), updatedQueueItems.Count), () => CollectionAssert.AreEqual(expectedQueueItems, updatedQueueItems, "Items In updated queue") ); } //If the config sizes are the same, the queue should not have changed NrAssert.Multiple ( () => Assert.IsTrue(expectedInitialCapacity != expectedUpdatedCapacity || initialQueue == updatedQueue), () => Assert.IsTrue(expectedInitialCapacity == expectedUpdatedCapacity || initialQueue != updatedQueue), () => Assert.AreEqual(expectedInitialCapacity, actualCountSpansSeen, "Count Seen Items"), () => Assert.AreEqual(expectedDroppedSpans, actualCountSpansDropped, "Count Dropped") ); }