Skip to content

Commit aec1d6c

Browse files
link04Ganesh Jangirtonyredondo
authored
Maximo/hotfix patch 3.26.2 (#7518)
## Summary of changes Trying to release fixes for telemetry and Statsd: - #7503 - #7507 - #7512 --------- Co-authored-by: Ganesh Jangir <[email protected]> Co-authored-by: Tony Redondo <[email protected]>
1 parent 7c695d2 commit aec1d6c

File tree

11 files changed

+94
-9
lines changed

11 files changed

+94
-9
lines changed

tracer/build/_build/Build.Shared.Steps.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,15 @@ partial class Build
166166
var buildDirectory = NativeBuildDirectory + "_" + finalArchs.Replace(';', '_');
167167
EnsureExistingDirectory(buildDirectory);
168168

169-
var envVariables = new Dictionary<string, string> { ["CMAKE_OSX_ARCHITECTURES"] = finalArchs };
169+
var envVariables = new Dictionary<string, string>
170+
{
171+
["HOME"] = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
172+
["PATH"] = Environment.GetEnvironmentVariable("PATH"),
173+
["CMAKE_OSX_ARCHITECTURES"] = finalArchs,
174+
["CMAKE_MAKE_PROGRAM"] = "make",
175+
["CMAKE_CXX_COMPILER"] = "clang++",
176+
["CMAKE_C_COMPILER"] = "clang",
177+
};
170178

171179
// Build native
172180
CMake.Value(

tracer/build/_build/Build.Steps.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,12 @@ bool RequiresThoroughTesting()
356356

357357
var envVariables = new Dictionary<string, string>
358358
{
359+
["HOME"] = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
360+
["PATH"] = Environment.GetEnvironmentVariable("PATH"),
359361
["CMAKE_OSX_ARCHITECTURES"] = finalArchs,
360-
["PATH"] = Environment.GetEnvironmentVariable("PATH")
362+
["CMAKE_MAKE_PROGRAM"] = "make",
363+
["CMAKE_CXX_COMPILER"] = "clang++",
364+
["CMAKE_C_COMPILER"] = "clang",
361365
};
362366

363367
// Build native

tracer/src/Datadog.Trace/RuntimeMetrics/AzureAppServicePerformanceCounters.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#if NETFRAMEWORK
77

88
using System;
9+
using System.Threading;
910
using Datadog.Trace.Logging;
1011
using Datadog.Trace.Util;
1112
using Datadog.Trace.Vendors.Newtonsoft.Json;
@@ -19,7 +20,7 @@ internal class AzureAppServicePerformanceCounters : IRuntimeMetricsListener
1920
private const string GarbageCollectionMetrics = $"{MetricsNames.Gen0HeapSize}, {MetricsNames.Gen1HeapSize}, {MetricsNames.Gen2HeapSize}, {MetricsNames.LohSize}, {MetricsNames.Gen0CollectionsCount}, {MetricsNames.Gen1CollectionsCount}, {MetricsNames.Gen2CollectionsCount}";
2021

2122
private static readonly IDatadogLogger Log = DatadogLogging.GetLoggerFor<AzureAppServicePerformanceCounters>();
22-
private readonly IDogStatsd _statsd;
23+
private IDogStatsd _statsd;
2324

2425
private int? _previousGen0Count;
2526
private int? _previousGen1Count;
@@ -70,6 +71,11 @@ public void Refresh()
7071
Log.Debug("Sent the following metrics to the DD agent: {Metrics}", GarbageCollectionMetrics);
7172
}
7273

74+
public void UpdateStatsd(IDogStatsd statsd)
75+
{
76+
Interlocked.Exchange(ref _statsd, statsd);
77+
}
78+
7379
private class PerformanceCountersValue
7480
{
7581
[JsonProperty("gen0HeapSize")]

tracer/src/Datadog.Trace/RuntimeMetrics/IRuntimeMetricsListener.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44
// </copyright>
55

66
using System;
7+
using Datadog.Trace.Vendors.StatsdClient;
78

89
namespace Datadog.Trace.RuntimeMetrics
910
{
1011
internal interface IRuntimeMetricsListener : IDisposable
1112
{
1213
void Refresh();
14+
15+
void UpdateStatsd(IDogStatsd statsd);
1316
}
1417
}

tracer/src/Datadog.Trace/RuntimeMetrics/MemoryMappedCounters.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System;
99
using System.IO.MemoryMappedFiles;
1010
using System.Runtime.InteropServices;
11+
using System.Threading;
1112
using Datadog.Trace.Logging;
1213
using Datadog.Trace.Util;
1314
using Datadog.Trace.Vendors.StatsdClient;
@@ -20,9 +21,10 @@ internal class MemoryMappedCounters : IRuntimeMetricsListener
2021

2122
private static readonly IDatadogLogger Log = DatadogLogging.GetLoggerFor<MemoryMappedCounters>();
2223

23-
private readonly IDogStatsd _statsd;
2424
private readonly int _processId;
2525

26+
private IDogStatsd _statsd;
27+
2628
private int? _previousGen0Count;
2729
private int? _previousGen1Count;
2830
private int? _previousGen2Count;
@@ -172,6 +174,11 @@ public void Refresh()
172174
Log.Debug("Sent the following metrics to the DD agent: {Metrics}", GarbageCollectionMetrics);
173175
}
174176

177+
public void UpdateStatsd(IDogStatsd statsd)
178+
{
179+
Interlocked.Exchange(ref _statsd, statsd);
180+
}
181+
175182
[StructLayout(LayoutKind.Sequential)]
176183
private readonly struct TRICOUNT
177184
{

tracer/src/Datadog.Trace/RuntimeMetrics/PerformanceCountersListener.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System;
88
using System.Diagnostics;
99
using System.Linq;
10+
using System.Threading;
1011
using System.Threading.Tasks;
1112
using Datadog.Trace.Logging;
1213
using Datadog.Trace.Util;
@@ -23,10 +24,11 @@ internal class PerformanceCountersListener : IRuntimeMetricsListener
2324

2425
private static readonly IDatadogLogger Log = DatadogLogging.GetLoggerFor<PerformanceCountersListener>();
2526

26-
private readonly IDogStatsd _statsd;
2727
private readonly string _processName;
2828
private readonly int _processId;
2929

30+
private IDogStatsd _statsd;
31+
3032
private string _instanceName;
3133
private PerformanceCounterCategory _memoryCategory;
3234
private bool _fullInstanceName;
@@ -114,6 +116,11 @@ public void Refresh()
114116
Log.Debug("Sent the following metrics to the DD agent: {Metrics}", GarbageCollectionMetrics);
115117
}
116118

119+
public void UpdateStatsd(IDogStatsd statsd)
120+
{
121+
Interlocked.Exchange(ref _statsd, statsd);
122+
}
123+
117124
protected virtual void InitializePerformanceCounters()
118125
{
119126
try

tracer/src/Datadog.Trace/RuntimeMetrics/RuntimeEventListener.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ internal class RuntimeEventListener : EventListener, IRuntimeMetricsListener
3737

3838
private static readonly IReadOnlyDictionary<string, string> MetricsMapping;
3939

40-
private readonly IDogStatsd _statsd;
41-
4240
private readonly Timing _contentionTime = new Timing();
4341

4442
private readonly string _delayInSeconds;
4543

44+
private IDogStatsd _statsd;
45+
4646
private long _contentionCount;
4747

4848
private DateTime? _gcStart;
@@ -81,6 +81,11 @@ public void Refresh()
8181
Log.Debug("Sent the following metrics to the DD agent: {Metrics}", ThreadStatsMetrics);
8282
}
8383

84+
public void UpdateStatsd(IDogStatsd statsd)
85+
{
86+
Interlocked.Exchange(ref _statsd, statsd);
87+
}
88+
8489
protected override void OnEventWritten(EventWrittenEventArgs eventData)
8590
{
8691
if (_statsd == null)

tracer/src/Datadog.Trace/RuntimeMetrics/RuntimeMetricsWriter.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ public void Dispose()
161161
internal void UpdateStatsd(IDogStatsd statsd)
162162
{
163163
Interlocked.Exchange(ref _statsd, statsd);
164+
_listener?.UpdateStatsd(statsd);
164165
}
165166

166167
internal void PushEvents()

tracer/src/Datadog.Trace/TracerManagerFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ internal static IApi GetApi(TracerSettings settings, IDogStatsd statsd, Action<D
408408
{
409409
telemetryClientConfiguration = new TelemetryClientConfiguration
410410
{
411-
Interval = (ulong)telemetrySettings.HeartbeatInterval.Milliseconds,
411+
Interval = (ulong)telemetrySettings.HeartbeatInterval.TotalMilliseconds,
412412
RuntimeId = new CharSlice(Tracer.RuntimeId),
413413
DebugEnabled = telemetrySettings.DebugEnabled
414414
};

tracer/test/Datadog.Trace.Tests/RuntimeMetrics/RuntimeEventListenerTests.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,51 @@ public void PushEventCounters()
115115
counter.Dispose();
116116
}
117117
}
118+
119+
[Fact]
120+
public void UpdateStatsdOnReinitialization()
121+
{
122+
// Arrange - Create ASP.NET Core EventSource and counters (similar to PushEventCounters test)
123+
var eventSource = new EventSource("Microsoft.AspNetCore.Hosting");
124+
var mutex = new ManualResetEventSlim();
125+
126+
Func<double> callback = () =>
127+
{
128+
mutex.Set();
129+
return 0.0;
130+
};
131+
132+
var counters = new List<DiagnosticCounter>
133+
{
134+
new PollingCounter("current-requests", eventSource, () => 1.0),
135+
new PollingCounter("total-requests", eventSource, () => 4.0),
136+
new PollingCounter("total-connections", eventSource, () => 32.0),
137+
// This counter sets the mutex, so it needs to be created last
138+
new PollingCounter("Dummy", eventSource, callback)
139+
};
140+
141+
var originalStatsd = new Mock<IDogStatsd>();
142+
var newStatsd = new Mock<IDogStatsd>();
143+
144+
using var listener = new RuntimeEventListener(originalStatsd.Object, TimeSpan.FromSeconds(1));
145+
using var writer = new RuntimeMetricsWriter(originalStatsd.Object, TimeSpan.FromSeconds(1), false);
146+
147+
mutex.Wait();
148+
149+
writer.UpdateStatsd(newStatsd.Object);
150+
151+
mutex.Reset();
152+
mutex.Wait();
153+
154+
newStatsd.Verify(s => s.Gauge(MetricsNames.AspNetCoreCurrentRequests, 1.0, 1, null), Times.AtLeastOnce);
155+
newStatsd.Verify(s => s.Gauge(MetricsNames.AspNetCoreTotalRequests, 4.0, 1, null), Times.AtLeastOnce);
156+
newStatsd.Verify(s => s.Gauge(MetricsNames.AspNetCoreTotalConnections, 32.0, 1, null), Times.AtLeastOnce);
157+
158+
foreach (var counter in counters)
159+
{
160+
counter.Dispose();
161+
}
162+
}
118163
}
119164
}
120165
#endif

0 commit comments

Comments
 (0)