Skip to content

Commit dc5cd0a

Browse files
committed
Merge remote-tracking branch 'origin/master' into chrisnas/reference_chain
2 parents cc19833 + 4c9508f commit dc5cd0a

13 files changed

Lines changed: 694 additions & 177 deletions

File tree

profiler/src/Demos/Samples.BuggyBits/Program.cs

Lines changed: 10 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
// </copyright>
55
using System;
66
using System.Diagnostics;
7-
using System.Net;
8-
using System.Net.Sockets;
7+
using System.Linq;
98
using System.Threading;
109
using System.Threading.Tasks;
1110
using Datadog.Demos.Util;
1211
using Microsoft.AspNetCore.Hosting;
13-
using Microsoft.Extensions.Configuration;
12+
using Microsoft.AspNetCore.Hosting.Server;
13+
using Microsoft.AspNetCore.Hosting.Server.Features;
1414
using Microsoft.Extensions.Hosting;
1515
using Microsoft.Extensions.Logging;
1616

@@ -56,36 +56,18 @@ public static async Task Main(string[] args)
5656

5757
using (var host = CreateHostBuilder(args).Build())
5858
{
59-
// ASP.NET Core accepts listening url via what is set by Visual Studio
60-
// (from the launchsettings.json). It could be overriden by --Urls
61-
// on the command line
62-
var configuration = host.Services.GetService(typeof(IConfiguration)) as IConfiguration;
63-
var rootUrl = configuration["urls"];
64-
65-
// otherwise, use the default ASP.NET Core value
66-
if (string.IsNullOrEmpty(rootUrl))
67-
{
68-
rootUrl = "http://localhost:5000";
69-
}
70-
71-
// avoid race condition in CI to find an available port
72-
int port = -1;
73-
if (int.TryParse(rootUrl.Substring(rootUrl.LastIndexOf(':') + 1), out port))
74-
{
75-
port = GetValidPort(port, 3);
76-
if (port != -1)
77-
{
78-
rootUrl = rootUrl.Substring(0, rootUrl.LastIndexOf(':') + 1) + port;
79-
}
80-
}
81-
82-
WriteLine($"Listening to {rootUrl}");
83-
8459
var cts = new CancellationTokenSource();
8560
using (var selfInvoker = new SelfInvoker(cts.Token, scenario, nbIdleThreads, _disableLogs))
8661
{
8762
await host.StartAsync();
8863

64+
var server = (IServer)host.Services.GetService(typeof(IServer));
65+
var addressFeature = server.Features.Get<IServerAddressesFeature>();
66+
var rootUrl = addressFeature.Addresses.FirstOrDefault() ?? "http://localhost:5000";
67+
68+
WriteLine($"Listening to {rootUrl}");
69+
Console.WriteLine($"##LISTENING_URL:{rootUrl}##");
70+
8971
WriteLine();
9072
WriteLine($"Started at {DateTime.UtcNow}.");
9173

@@ -161,64 +143,6 @@ public static IHostBuilder CreateHostBuilder(string[] args) =>
161143
}
162144
});
163145

164-
public static int GetOpenPort()
165-
{
166-
TcpListener tcpListener = null;
167-
try
168-
{
169-
tcpListener = new TcpListener(IPAddress.Loopback, 0);
170-
tcpListener.Start();
171-
var port = ((IPEndPoint)tcpListener.LocalEndpoint).Port;
172-
return port;
173-
}
174-
finally
175-
{
176-
tcpListener?.Stop();
177-
}
178-
}
179-
180-
private static int GetValidPort(int initialPort, int retries)
181-
{
182-
var port = initialPort;
183-
bool isPortValid = false;
184-
while (true)
185-
{
186-
// seems like we can't reuse a listener if it fails to start,
187-
// so create a new listener each time we retry
188-
var listener = new HttpListener();
189-
listener.Prefixes.Add($"http://127.0.0.1:{port}/");
190-
listener.Prefixes.Add($"http://localhost:{port}/");
191-
192-
try
193-
{
194-
listener.Start();
195-
196-
// success
197-
isPortValid = true;
198-
break;
199-
}
200-
catch (HttpListenerException) when (retries > 0)
201-
{
202-
// only catch the exception if there are retries left
203-
port = GetOpenPort();
204-
retries--;
205-
}
206-
finally
207-
{
208-
listener.Close();
209-
}
210-
}
211-
212-
if (isPortValid)
213-
{
214-
return port;
215-
}
216-
else
217-
{
218-
return -1; // no valid port found
219-
}
220-
}
221-
222146
private static void ParseCommandLine(string[] args, out bool disableLogs, out TimeSpan timeout, out int iterations, out Scenario scenario, out int nbIdleThreads)
223147
{
224148
// by default, need interactive action to exit and string.Concat scenario

profiler/src/Demos/Samples.HttpRequest/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
// send the requests
7777
var client = new System.Net.Http.HttpClient();
7878
var baseUrl = app.Urls.First();
79+
Console.WriteLine($"##LISTENING_URL:{baseUrl}##");
7980
for (int iteration = 0; iteration < iterations; iteration++)
8081
{
8182
var url = BuildUrl($"{baseUrl}/endpoint", code, redirections, requestDuration, responseDuration, output);

profiler/src/Demos/Samples.Website-AspNetCore01/Program.cs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55

66
using System;
77
using System.Diagnostics;
8+
using System.Linq;
89
using System.Threading;
910
using System.Threading.Tasks;
1011
using Datadog.Demos.Util;
1112
using Microsoft.AspNetCore.Hosting;
12-
using Microsoft.Extensions.Configuration;
13+
using Microsoft.AspNetCore.Hosting.Server;
14+
using Microsoft.AspNetCore.Hosting.Server.Features;
1315
using Microsoft.Extensions.Hosting;
1416

1517
namespace Samples.Website_AspNetCore01
@@ -46,20 +48,6 @@ public static async Task Main(string[] args)
4648
WriteLine($"host built in {sw.ElapsedMilliseconds} ms");
4749
sw.Restart();
4850

49-
// ASP.NET Core accepts listening url via what is set by Visual Studio
50-
// (from the launchsettings.json). It could be overriden by --Urls
51-
// on the command line
52-
var configuration = host.Services.GetService(typeof(IConfiguration)) as IConfiguration;
53-
var rootUrl = configuration["Urls"];
54-
55-
// otherwise, use the default ASP.NET Core value
56-
if (string.IsNullOrEmpty(rootUrl))
57-
{
58-
rootUrl = "http://localhost:5000";
59-
}
60-
61-
WriteLine($"Listening to {rootUrl}");
62-
6351
var cts = new CancellationTokenSource();
6452
using (var selfInvoker = new SelfInvoker(cts.Token))
6553
{
@@ -72,6 +60,13 @@ public static async Task Main(string[] args)
7260
sw.Stop();
7361
WriteLine($"host started in {sw.ElapsedMilliseconds} ms");
7462

63+
var server = (IServer)host.Services.GetService(typeof(IServer));
64+
var addressFeature = server.Features.Get<IServerAddressesFeature>();
65+
var rootUrl = addressFeature.Addresses.FirstOrDefault() ?? "http://localhost:5000";
66+
67+
WriteLine($"Listening to {rootUrl}");
68+
Console.WriteLine($"##LISTENING_URL:{rootUrl}##");
69+
7570
WriteLine();
7671
WriteLine($"Started at {DateTime.UtcNow}.");
7772

profiler/test/Datadog.Profiler.IntegrationTests/Helpers/TestApplicationRunner.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Collections.Specialized;
88
using System.Diagnostics;
99
using System.IO;
10+
using System.Text.RegularExpressions;
1011
using Xunit;
1112
using Xunit.Abstractions;
1213
using Xunit.Sdk;
@@ -151,10 +152,7 @@ private string GetApplicationPath()
151152
throw new Exception($"Unable to find executing assembly at {applicationPath}");
152153
}
153154

154-
// Look for a free open port to pass to the ASP.NET Core applications
155-
// that accept --urls on their command line
156-
_appListenerPort = $"http://localhost:{TcpPortProvider.GetOpenPort()}";
157-
var arguments = $"--timeout {TestDurationInSeconds} --urls {_appListenerPort}";
155+
var arguments = $"--timeout {TestDurationInSeconds} --urls http://127.0.0.1:0";
158156
if (!string.IsNullOrEmpty(_commandLine))
159157
{
160158
arguments += $" {_commandLine}";
@@ -195,6 +193,7 @@ private void RunTest(MockDatadogAgent agent)
195193
var standardOutput = processHelper.StandardOutput;
196194
var errorOutput = processHelper.ErrorOutput;
197195
ProcessOutput = standardOutput;
196+
_appListenerPort = ParseListeningUrl(standardOutput);
198197

199198
if (!ranToCompletion)
200199
{
@@ -247,6 +246,17 @@ private void RunTest(MockDatadogAgent agent)
247246
}
248247
}
249248

249+
private static string ParseListeningUrl(string output)
250+
{
251+
if (output is null)
252+
{
253+
return null;
254+
}
255+
256+
var match = Regex.Match(output, @"##LISTENING_URL:(.+?)##");
257+
return match.Success ? match.Groups[1].Value : null;
258+
}
259+
250260
private void SetEnvironmentVariables(StringDictionary environmentVariables, MockDatadogAgent agent)
251261
{
252262
Environment.PopulateEnvironmentVariables(environmentVariables, agent, ProfilingExportsIntervalInSeconds, ServiceName);

tracer/src/Datadog.Trace.Tools.dd_dotnet/CreatedumpCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ private static unsafe int ResolveManagedCallstack(int threadId, IntPtr context,
300300
resolvedFrame->IsSuspicious = IsMethodSuspicious(frame.Method);
301301

302302
var assemblyName = frame.Method.Type.Module.AssemblyName;
303-
var methodName = ShouldRedactFrame(assemblyName) ? "REDACTED" : $"{frame.Method.Type}.{frame.Method.Name}";
303+
var methodName = $"{frame.Method.Type}.{frame.Method.Name}";
304304
symbolName = $"{Path.GetFileName(assemblyName)}!{methodName}";
305305
}
306306
else

0 commit comments

Comments
 (0)