Skip to content

Commit c3aec3d

Browse files
CopilotTimHessCopilot
authored
Add .NET runtime information to /info actuator endpoint (#1640)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Tim Hess <tim.hess@broadcom.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent ece58a0 commit c3aec3d

4 files changed

Lines changed: 47 additions & 0 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System.Runtime.InteropServices;
6+
7+
namespace Steeltoe.Management.Endpoint.Actuators.Info.Contributors;
8+
9+
internal sealed class RuntimeInfoContributor : IInfoContributor
10+
{
11+
public Task ContributeAsync(InfoBuilder builder, CancellationToken cancellationToken)
12+
{
13+
ArgumentNullException.ThrowIfNull(builder);
14+
15+
builder.WithInfo("runtime", new Dictionary<string, string?>
16+
{
17+
["runtimeName"] = RuntimeInformation.FrameworkDescription,
18+
["runtimeVersion"] = System.Environment.Version.ToString(),
19+
["runtimeIdentifier"] = RuntimeInformation.RuntimeIdentifier,
20+
["processArchitecture"] = RuntimeInformation.ProcessArchitecture.ToString(),
21+
["osArchitecture"] = RuntimeInformation.OSArchitecture.ToString(),
22+
["osDescription"] = RuntimeInformation.OSDescription,
23+
["osVersion"] = System.Environment.OSVersion.ToString()
24+
});
25+
26+
return Task.CompletedTask;
27+
}
28+
}

src/Management/src/Endpoint/Actuators/Info/EndpointServiceCollectionExtensions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ private static void RegisterDefaultInfoContributors(IServiceCollection services)
5454
services.TryAddEnumerable(ServiceDescriptor.Singleton<IInfoContributor, GitInfoContributor>());
5555
services.TryAddEnumerable(ServiceDescriptor.Singleton<IInfoContributor, AppSettingsInfoContributor>());
5656
services.TryAddEnumerable(ServiceDescriptor.Singleton<IInfoContributor, BuildInfoContributor>());
57+
services.TryAddEnumerable(ServiceDescriptor.Singleton<IInfoContributor, RuntimeInfoContributor>());
5758
}
5859

5960
/// <summary>

src/Management/test/Endpoint.Test/Actuators/Info/InfoActuatorTest.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
using System.Net;
66
using System.Reflection;
7+
using System.Runtime.InteropServices;
78
using Microsoft.AspNetCore.Builder;
89
using Microsoft.AspNetCore.TestHost;
910
using Microsoft.Extensions.Configuration;
@@ -33,6 +34,13 @@ public sealed class InfoActuatorTest
3334
private static readonly Assembly SteeltoeAssembly = typeof(IInfoContributor).Assembly;
3435
private static readonly string SteeltoeFileVersion = SteeltoeAssembly.GetCustomAttribute<AssemblyFileVersionAttribute>()!.Version;
3536
private static readonly string SteeltoeProductVersion = SteeltoeAssembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()!.InformationalVersion;
37+
private static readonly string RuntimeName = RuntimeInformation.FrameworkDescription;
38+
private static readonly string RuntimeVersion = System.Environment.Version.ToString();
39+
private static readonly string RuntimeIdentifier = RuntimeInformation.RuntimeIdentifier;
40+
private static readonly string ProcessArchitecture = RuntimeInformation.ProcessArchitecture.ToString();
41+
private static readonly string OSArchitecture = RuntimeInformation.OSArchitecture.ToString();
42+
private static readonly string OSDescription = RuntimeInformation.OSDescription;
43+
private static readonly string OSVersion = System.Environment.OSVersion.ToString();
3644

3745
[Fact]
3846
public async Task Registers_dependent_services()
@@ -184,6 +192,15 @@ public async Task Endpoint_returns_expected_data(HostBuilderType hostBuilderType
184192
},
185193
"build": {
186194
"version": "{{AppAssemblyVersion}}"
195+
},
196+
"runtime": {
197+
"runtimeName": "{{RuntimeName}}",
198+
"runtimeVersion": "{{RuntimeVersion}}",
199+
"runtimeIdentifier": "{{RuntimeIdentifier}}",
200+
"processArchitecture": "{{ProcessArchitecture}}",
201+
"osArchitecture": "{{OSArchitecture}}",
202+
"osDescription": "{{OSDescription}}",
203+
"osVersion": "{{OSVersion}}"
187204
}
188205
}
189206
""");

src/Steeltoe.All.sln.DotSettings

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,7 @@ See the LICENSE file in the project root for more information.&#xD;
604604
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=IO/@EntryIndexedValue">IO</s:String>
605605
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=IP/@EntryIndexedValue">IP</s:String>
606606
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=MQ/@EntryIndexedValue">MQ</s:String>
607+
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=OS/@EntryIndexedValue">OS</s:String>
607608
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=OSX/@EntryIndexedValue">OSX</s:String>
608609
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=UAA/@EntryIndexedValue">UAA</s:String>
609610
<s:Boolean x:Key="/Default/CodeStyle/Naming/CSharpNaming/ApplyAutoDetectedRules/@EntryValue">False</s:Boolean>

0 commit comments

Comments
 (0)