Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for metricseventsource HistogramLimitReached(#60752, #61199) #61449

Merged
merged 2 commits into from
Nov 11, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,47 @@ public void EventSourceWorksWithSequentialListeners()
AssertCollectStartStopEventsPresent(events, IntervalSecs, 3);
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))]
[OuterLoop("Slow and has lots of console spew")]
public void EventSourceEnforcesHistogramLimitAndNotMaxTimeSeries()
{
using Meter meter = new Meter("TestMeter17");
Histogram<int> h = meter.CreateHistogram<int>("histogram1");


EventWrittenEventArgs[] events;
// MaxTimeSeries = 3, MaxHistograms = 2
// HistogramLimitReached should be raised when Record(tags: "Color=green"), but TimeSeriesLimitReached should not be raised
using (MetricsEventListener listener = new MetricsEventListener(_output, MetricsEventListener.TimeSeriesValues, IntervalSecs, 3, 2, "TestMeter17"))
{
listener.WaitForCollectionStop(s_waitForEventTimeout, 1);

h.Record(5, new KeyValuePair<string, object?>("Color", "red"));
h.Record(6, new KeyValuePair<string, object?>("Color", "blue"));
h.Record(7, new KeyValuePair<string, object?>("Color", "green"));
h.Record(8, new KeyValuePair<string, object?>("Color", "yellow"));
listener.WaitForCollectionStop(s_waitForEventTimeout, 2);

h.Record(12, new KeyValuePair<string, object?>("Color", "red"));
h.Record(13, new KeyValuePair<string, object?>("Color", "blue"));
h.Record(14, new KeyValuePair<string, object?>("Color", "green"));
h.Record(15, new KeyValuePair<string, object?>("Color", "yellow"));
listener.WaitForCollectionStop(s_waitForEventTimeout, 3);
events = listener.Events.ToArray();
}

AssertBeginInstrumentReportingEventsPresent(events, h);
AssertInitialEnumerationCompleteEventPresent(events);
AssertHistogramEventsPresent(events, meter.Name, h.Name, "Color=red", "", "0.5=5;0.95=5;0.99=5", "0.5=12;0.95=12;0.99=12");
AssertHistogramEventsPresent(events, meter.Name, h.Name, "Color=blue", "", "0.5=6;0.95=6;0.99=6", "0.5=13;0.95=13;0.99=13");
AssertHistogramLimitPresent(events);
AssertTimeSeriesLimitNotPresent(events);
AssertHistogramEventsNotPresent(events, meter.Name, h.Name, "Color=green");
AssertHistogramEventsNotPresent(events, meter.Name, h.Name, "Color=yellow");
AssertCollectStartStopEventsPresent(events, IntervalSecs, 3);
}


private void AssertBeginInstrumentReportingEventsPresent(EventWrittenEventArgs[] events, params Instrument[] expectedInstruments)
{
var beginReportEvents = events.Where(e => e.EventName == "BeginInstrumentReporting").Select(e =>
Expand Down Expand Up @@ -766,6 +807,11 @@ private void AssertTimeSeriesLimitPresent(EventWrittenEventArgs[] events)
Assert.Equal(1, events.Where(e => e.EventName == "TimeSeriesLimitReached").Count());
}

private void AssertTimeSeriesLimitNotPresent(EventWrittenEventArgs[] events)
{
Assert.Equal(0, events.Where(e => e.EventName == "TimeSeriesLimitReached").Count());
}

private void AssertHistogramLimitPresent(EventWrittenEventArgs[] events)
{
Assert.Equal(1, events.Where(e => e.EventName == "HistogramLimitReached").Count());
Expand Down