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
5 changes: 5 additions & 0 deletions .github/workflows/run-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ jobs:
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x
- name: Setup .NET Core 6.0
uses: actions/setup-dotnet@v1
with:
dotnet-version: '6.0.x'
include-prerelease: true
- uses: actions/checkout@v1
# This test constantly passes localy (windows + linux) but fails in the test environment. Don't have the time/ inclination to figure out why this is right now..
- run: dotnet test -c "Debug" --filter Name!=When_blocking_work_is_executed_on_the_thread_pool_then_thread_pool_delays_are_measured
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,30 @@ public class TestHelpers
{
public static EventWrittenEventArgs CreateEventWrittenEventArgs(int eventId, DateTime? timestamp = null, params object[] payload)
{
var args = (EventWrittenEventArgs)typeof(EventWrittenEventArgs).CreateInstance(new []{ typeof(EventSource)}, Flags.NonPublic | Flags.Instance, new object[] { null});
args.SetPropertyValue("EventId", eventId);
EventWrittenEventArgs args;
var bindFlags = Flags.NonPublic | Flags.Instance;

// In .NET 6.0, they changed the signature of these constructors- handle this annoyance
if (typeof(EventWrittenEventArgs).GetConstructors(bindFlags).Any(x => x.GetParameters().Length == 1))
{
args = (EventWrittenEventArgs)typeof(EventWrittenEventArgs).CreateInstance(new[] { typeof(EventSource)}, Flags.NonPublic | Flags.Instance, new object[] { null });
args.SetPropertyValue("EventId", eventId);
}
else
{
args = (EventWrittenEventArgs)typeof(EventWrittenEventArgs).CreateInstance(new[] { typeof(EventSource), typeof(int) }, Flags.NonPublic | Flags.Instance, new object[] { null, eventId });
}

args.SetPropertyValue("Payload", new ReadOnlyCollection<object>(payload));

if (timestamp.HasValue)
{
args.SetPropertyValue("TimeStamp", timestamp.Value);
}

return args;
}

public static EventWrittenEventArgs CreateCounterEventWrittenEventArgs(params (string key, object val)[] payload)
{
var counterPayload = payload.ToDictionary(k => k.key, v => v.val);
Expand All @@ -41,14 +53,11 @@ public static EventAssertion<T> ArrangeEventAssertion<T>(Action<Action<T>> wireU
public class EventAssertion<T>
{
private Action<T> _handler;

public EventAssertion(Action<Action<T>> wireUp)
{
_handler = e =>
{
History.Add(e);
};

_handler = e => { History.Add(e); };

wireUp(_handler);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
<Import Project="../Common.csproj" />

<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;net5.0</TargetFrameworks>
<TargetFrameworks>netcoreapp3.1;net5.0;net6.0</TargetFrameworks>
<IsPackable>false</IsPackable>
<RootNamespace>Prometheus.DotNetRuntime.Tests</RootNamespace>
<Platforms>AnyCPU</Platforms>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>10</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,16 @@ internal static IEnumerable<Type> GetEventParsers(Assembly fromAssembly)
internal static Lazy<Version> CurrentRuntimeVerison = new Lazy<Version>(() =>
{
var split = RuntimeInformation.FrameworkDescription.Split(' ');
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't you use Environment.Version here?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I absolutely should have, thanks for the comment


if (Version.TryParse(split[split.Length - 1], out var version))
if (split.Length < 2)
return null;

var versionPart = split[^1];
// Handle preview version strings, e.g. .NET 6.0.0-preview.7.21377.19.
var hyphenIndex = versionPart.IndexOf('-');
if (hyphenIndex > -1)
versionPart = versionPart.Substring(0, hyphenIndex);

if (Version.TryParse(versionPart, out var version))
return new Version(version.Major, version.Minor);

return null;
Expand Down
2 changes: 0 additions & 2 deletions src/prometheus-net.DotNetRuntime/ListenerRegistration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ public static ListenerRegistration Create<T>(CaptureLevel level, Func<IServicePr
if (!supportedLevels.Contains(eventLevel))
throw new UnsupportedEventParserLevelException(typeof(T), level, supportedLevels);


if (!EventParserTypes.AreEventsSupportedByRuntime(typeof(T)))
throw new UnsupportedEventParserRuntimeException(typeof(T));


return new ListenerRegistration(eventLevel, typeof(T), sp => (object)factory(sp));
}
Expand Down