diff --git a/samples/client/Program.cs b/samples/client/Program.cs new file mode 100644 index 000000000..2129c2d8f --- /dev/null +++ b/samples/client/Program.cs @@ -0,0 +1,30 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; + +namespace client +{ + public class Program + { + public static void Main(string[] args) + { + CreateHostBuilder(args).Build().Run(); + } + + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }); + } +} diff --git a/samples/client/Startup.cs b/samples/client/Startup.cs new file mode 100644 index 000000000..6ae572abe --- /dev/null +++ b/samples/client/Startup.cs @@ -0,0 +1,57 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Net.Http; +using System.Reflection; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; + +namespace client +{ + public class Startup + { + // This method gets called by the runtime. Use this method to add services to the container. + // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 + public void ConfigureServices(IServiceCollection services) + { + } + + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + } + + app.UseRouting(); + + app.UseEndpoints(endpoints => + { + var client = new HttpClient + { + BaseAddress = new Uri("http://localhost:8080") + }; + + endpoints.MapGet("/", async context => + { + var content = await client.GetStringAsync("/"); + + await context.Response.WriteAsync(content); + }); + }); + + Console.WriteLine($"AspNetCore location: {typeof(IWebHostBuilder).GetTypeInfo().Assembly.Location}"); + Console.WriteLine($"AspNetCore version: {typeof(IWebHostBuilder).GetTypeInfo().Assembly.GetCustomAttribute()?.InformationalVersion}"); + + Console.WriteLine($"NETCoreApp location: {typeof(object).GetTypeInfo().Assembly.Location}"); + Console.WriteLine($"NETCoreApp version: {typeof(object).GetTypeInfo().Assembly.GetCustomAttribute()?.InformationalVersion}"); + + } + } +} diff --git a/samples/client/appsettings.Development.json b/samples/client/appsettings.Development.json new file mode 100644 index 000000000..8983e0fc1 --- /dev/null +++ b/samples/client/appsettings.Development.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git a/samples/client/appsettings.json b/samples/client/appsettings.json new file mode 100644 index 000000000..d9d9a9bff --- /dev/null +++ b/samples/client/appsettings.json @@ -0,0 +1,10 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "AllowedHosts": "*" +} diff --git a/samples/client/client.benchmarks.yml b/samples/client/client.benchmarks.yml new file mode 100644 index 000000000..b9385571a --- /dev/null +++ b/samples/client/client.benchmarks.yml @@ -0,0 +1,43 @@ +imports: + - ../../src/Microsoft.Crank.Jobs.Bombardier/bombardier.yml + +jobs: + server: + source: + localFolder: . + project: client.csproj + readyStateText: Application started. + mockserver: + source: + localFolder: mockserver + dockerFile: Dockerfile + dockerImageName: mockserver + dockerContextDirectory: . + port: 8080 + +scenarios: + client: + mockserver: + job: mockserver + application: + job: server + load: + job: bombardier + variables: + serverPort: 5010 + path: / + +profiles: + local: + variables: + serverUri: http://localhost + jobs: + application: + endpoints: + - http://localhost:5010 + load: + endpoints: + - http://localhost:5010 + mockserver: + endpoints: + - http://localhost:5010 diff --git a/samples/client/client.csproj b/samples/client/client.csproj new file mode 100644 index 000000000..4b0ce9661 --- /dev/null +++ b/samples/client/client.csproj @@ -0,0 +1,7 @@ + + + + netcoreapp3.1;netcoreapp5.0 + + + diff --git a/samples/client/mockserver/Dockerfile b/samples/client/mockserver/Dockerfile new file mode 100644 index 000000000..5a13b2731 --- /dev/null +++ b/samples/client/mockserver/Dockerfile @@ -0,0 +1,2 @@ +FROM rodolpheche/wiremock as mockserver +COPY config /home/wiremock diff --git a/samples/client/mockserver/config/mappings/all.json b/samples/client/mockserver/config/mappings/all.json new file mode 100644 index 000000000..ad16d5642 --- /dev/null +++ b/samples/client/mockserver/config/mappings/all.json @@ -0,0 +1,16 @@ +{ + "mappings": [ + { + "request": { + "urlPath": "/", + "method": "GET" + }, + "response": { + "status": 200, + "body": "Hello World!", + "fixedDelayMilliseconds": 20 + }, + "priority": 10 + } + ] +} \ No newline at end of file diff --git a/src/Microsoft.Crank.Agent/Startup.cs b/src/Microsoft.Crank.Agent/Startup.cs index a0d1a7082..74116240f 100644 --- a/src/Microsoft.Crank.Agent/Startup.cs +++ b/src/Microsoft.Crank.Agent/Startup.cs @@ -1681,7 +1681,9 @@ await ProcessUtil.RunAsync("docker", dockerLoadArguments, var command = OperatingSystem == OperatingSystem.Linux ? $"run -d {environmentArguments} {job.Arguments} --label benchmarks --name {containerName} --privileged --network host {imageName} {source.DockerCommand}" - : $"run -d {environmentArguments} {job.Arguments} --label benchmarks --name {containerName} --network SELF --ip {hostname} {imageName} {source.DockerCommand}"; + : string.Equals(hostname, "localhost", StringComparison.OrdinalIgnoreCase) + ? $"run -d {environmentArguments} {job.Arguments} --label benchmarks --name {containerName} -p {job.Port}:{job.Port} {imageName} {source.DockerCommand}" + : $"run -d {environmentArguments} {job.Arguments} --label benchmarks --name {containerName} --network SELF --ip {hostname} {imageName} {source.DockerCommand}"; if (job.Collect && job.CollectStartup) {