Skip to content
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.

using System.Runtime.InteropServices;

namespace Steeltoe.Management.Endpoint.Actuators.Info.Contributors;

internal sealed class RuntimeInfoContributor : IInfoContributor
{
public Task ContributeAsync(InfoBuilder builder, CancellationToken cancellationToken)
{
ArgumentNullException.ThrowIfNull(builder);

builder.WithInfo("runtime", new Dictionary<string, string?>
{
["runtimeName"] = RuntimeInformation.FrameworkDescription,
["runtimeVersion"] = System.Environment.Version.ToString(),
["runtimeIdentifier"] = RuntimeInformation.RuntimeIdentifier,
["processArchitecture"] = RuntimeInformation.ProcessArchitecture.ToString(),
["osArchitecture"] = RuntimeInformation.OSArchitecture.ToString(),
["osDescription"] = RuntimeInformation.OSDescription,
["osVersion"] = System.Environment.OSVersion.ToString()
});

return Task.CompletedTask;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ private static void RegisterDefaultInfoContributors(IServiceCollection services)
services.TryAddEnumerable(ServiceDescriptor.Singleton<IInfoContributor, GitInfoContributor>());
services.TryAddEnumerable(ServiceDescriptor.Singleton<IInfoContributor, AppSettingsInfoContributor>());
services.TryAddEnumerable(ServiceDescriptor.Singleton<IInfoContributor, BuildInfoContributor>());
services.TryAddEnumerable(ServiceDescriptor.Singleton<IInfoContributor, RuntimeInfoContributor>());
Comment thread
bart-vmware marked this conversation as resolved.
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System.Net;
using System.Reflection;
using System.Runtime.InteropServices;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.TestHost;
using Microsoft.Extensions.Configuration;
Expand Down Expand Up @@ -33,6 +34,13 @@ public sealed class InfoActuatorTest
private static readonly Assembly SteeltoeAssembly = typeof(IInfoContributor).Assembly;
private static readonly string SteeltoeFileVersion = SteeltoeAssembly.GetCustomAttribute<AssemblyFileVersionAttribute>()!.Version;
private static readonly string SteeltoeProductVersion = SteeltoeAssembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()!.InformationalVersion;
private static readonly string RuntimeName = RuntimeInformation.FrameworkDescription;
private static readonly string RuntimeVersion = System.Environment.Version.ToString();
private static readonly string RuntimeIdentifier = RuntimeInformation.RuntimeIdentifier;
private static readonly string ProcessArchitecture = RuntimeInformation.ProcessArchitecture.ToString();
private static readonly string OSArchitecture = RuntimeInformation.OSArchitecture.ToString();
private static readonly string OSDescription = RuntimeInformation.OSDescription;
private static readonly string OSVersion = System.Environment.OSVersion.ToString();

[Fact]
public async Task Registers_dependent_services()
Expand Down Expand Up @@ -184,6 +192,15 @@ public async Task Endpoint_returns_expected_data(HostBuilderType hostBuilderType
},
"build": {
"version": "{{AppAssemblyVersion}}"
},
"runtime": {
"runtimeName": "{{RuntimeName}}",
"runtimeVersion": "{{RuntimeVersion}}",
"runtimeIdentifier": "{{RuntimeIdentifier}}",
"processArchitecture": "{{ProcessArchitecture}}",
"osArchitecture": "{{OSArchitecture}}",
"osDescription": "{{OSDescription}}",
"osVersion": "{{OSVersion}}"
}
}
""");
Expand Down
1 change: 1 addition & 0 deletions src/Steeltoe.All.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,7 @@ See the LICENSE file in the project root for more information.&#xD;
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=IO/@EntryIndexedValue">IO</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=IP/@EntryIndexedValue">IP</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=MQ/@EntryIndexedValue">MQ</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=OS/@EntryIndexedValue">OS</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=OSX/@EntryIndexedValue">OSX</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=UAA/@EntryIndexedValue">UAA</s:String>
<s:Boolean x:Key="/Default/CodeStyle/Naming/CSharpNaming/ApplyAutoDetectedRules/@EntryValue">False</s:Boolean>
Expand Down