Skip to content
Merged
Show file tree
Hide file tree
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 @@ -88,12 +88,23 @@ public AggregationManager(

public void Include(string meterName)
{
Include(i => i.Meter.Name == meterName);
Include(i => i.Meter.Name.Equals(meterName, StringComparison.OrdinalIgnoreCase));
}

public void IncludeAll()
{
Include(i => true);
}

public void IncludePrefix(string meterNamePrefix)
{
Include(i => i.Meter.Name.StartsWith(meterNamePrefix, StringComparison.OrdinalIgnoreCase));
}

public void Include(string meterName, string instrumentName)
{
Include(i => i.Meter.Name == meterName && i.Name == instrumentName);
Include(i => i.Meter.Name.Equals(meterName, StringComparison.OrdinalIgnoreCase)
&& i.Name.Equals(instrumentName, StringComparison.OrdinalIgnoreCase));
}

private void Include(Predicate<Instrument> instrumentFilter)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,19 @@ private void ParseSpecs(string? metricsSpecs)
{
_aggregationManager!.Include(spec.MeterName, spec.InstrumentName);
}
else if (spec.MeterName.Length > 0
&& spec.MeterName[spec.MeterName.Length - 1] == '*')
{
if (spec.MeterName.Length == 1)
{
_aggregationManager!.IncludeAll();
}
else
{
_aggregationManager!.IncludePrefix(
spec.MeterName.Substring(0, spec.MeterName.Length - 1));
}
}
else
{
_aggregationManager!.Include(spec.MeterName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,74 @@ public void MultipleListeners_ThreeCounters()
AssertCollectStartStopEventsPresent(events3, IntervalSecs, 2);
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))]
[OuterLoop("Slow and has lots of console spew")]
public void SingleListener_Wildcard()
{
using Meter meter = new Meter("Test.TestMeter1");
Counter<int> c = meter.CreateCounter<int>("counter1");

using Meter meter2 = new Meter("Test.TestMeter2", null, new TagList() { { "Mk1", "Mv1" } }, new object());
Counter<int> c2 = meter2.CreateCounter<int>("counter2");

using Meter meter3 = new Meter("Test.TestMeter3", null, new TagList() { { "MMk1", null }, { "MMk2", null } }, new object());
Counter<int> c3 = meter3.CreateCounter<int>("counter3");

EventWrittenEventArgs[] events;
using (MetricsEventListener listener = new MetricsEventListener(_output, MetricsEventListener.TimeSeriesValues, isShared: true, IntervalSecs, "*"))
{
listener.WaitForCollectionStop(s_waitForEventTimeout, 1);
c.Add(5);
c2.Add(10);
c3.Add(20);
listener.WaitForCollectionStop(s_waitForEventTimeout, 2);
events = listener.Events.ToArray();
}

// Note: Need to exclude System.Runtime metrics any anything else in platform
events = events.Where(e => e.EventName != "BeginInstrumentReporting"
|| (e.Payload[1] as string)?.StartsWith("Test.") == true)
.ToArray();

AssertBeginInstrumentReportingEventsPresent(events, c, c2, c3);
AssertInitialEnumerationCompleteEventPresent(events);
AssertCounterEventsPresent(events, meter.Name, c.Name, "", "", ("5", "5"));
AssertCounterEventsPresent(events, meter2.Name, c2.Name, "", "", ("10", "10"));
AssertCounterEventsPresent(events, meter3.Name, c3.Name, "", "", ("20", "20"));
AssertCollectStartStopEventsPresent(events, IntervalSecs, 2);
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))]
[OuterLoop("Slow and has lots of console spew")]
public void SingleListener_Prefix()
{
using Meter meter = new Meter("Company1.TestMeter1");
Counter<int> c = meter.CreateCounter<int>("counter1");

using Meter meter2 = new Meter("Company1.TestMeter2", null, new TagList() { { "Mk1", "Mv1" } }, new object());
Counter<int> c2 = meter2.CreateCounter<int>("counter2");

using Meter meter3 = new Meter("Company2.TestMeter3", null, new TagList() { { "MMk1", null }, { "MMk2", null } }, new object());
Counter<int> c3 = meter3.CreateCounter<int>("counter3");

EventWrittenEventArgs[] events;
using (MetricsEventListener listener = new MetricsEventListener(_output, MetricsEventListener.TimeSeriesValues, isShared: true, IntervalSecs, "Company1*"))
{
listener.WaitForCollectionStop(s_waitForEventTimeout, 1);
c.Add(5);
c2.Add(10);
c3.Add(20);
listener.WaitForCollectionStop(s_waitForEventTimeout, 2);
events = listener.Events.ToArray();
}

AssertBeginInstrumentReportingEventsPresent(events, c, c2);
AssertInitialEnumerationCompleteEventPresent(events);
AssertCounterEventsPresent(events, meter.Name, c.Name, "", "", ("5", "5"));
AssertCounterEventsPresent(events, meter2.Name, c2.Name, "", "", ("10", "10"));
AssertCollectStartStopEventsPresent(events, IntervalSecs, 2);
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))]
[OuterLoop("Slow and has lots of console spew")]
public void MultipleListeners_OverlappingListeners()
Expand Down Expand Up @@ -1727,7 +1795,7 @@ private static void AssertGenericCounterEventsPresent(string eventName, EventWri
Tags = e.Payload[5].ToString(),
Rate = e.Payload[6].ToString(),
Value = e.Payload[7].ToString(),
InstrumentId = (int)(e.Payload[7]),
InstrumentId = (int)(e.Payload[8]),
}).ToArray();
var filteredEvents = counterEvents.Where(e => e.MeterName == meterName && e.InstrumentName == instrumentName && e.Tags == tags).ToArray();
Assert.True(filteredEvents.Length >= expected.Length);
Expand Down