Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions samples/client/Program.cs
Original file line number Diff line number Diff line change
@@ -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<Startup>();
});
}
}
57 changes: 57 additions & 0 deletions samples/client/Startup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Licensed to the .NET Foundation under one or more agreements.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could use the new WebApplicationBuilder model now

// 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}");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not necessary. Results show the version automatically.

Console.WriteLine($"AspNetCore version: {typeof(IWebHostBuilder).GetTypeInfo().Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion}");

Console.WriteLine($"NETCoreApp location: {typeof(object).GetTypeInfo().Assembly.Location}");
Console.WriteLine($"NETCoreApp version: {typeof(object).GetTypeInfo().Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion}");

}
}
}
9 changes: 9 additions & 0 deletions samples/client/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
}
}
10 changes: 10 additions & 0 deletions samples/client/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*"
}
43 changes: 43 additions & 0 deletions samples/client/client.benchmarks.yml
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions samples/client/client.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;netcoreapp5.0</TargetFrameworks>
</PropertyGroup>

</Project>
2 changes: 2 additions & 0 deletions samples/client/mockserver/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FROM rodolpheche/wiremock as mockserver
COPY config /home/wiremock
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be nice to add a 3rd way to add a docker job by specify the docker hub name, or did I miss it?

Copy link
Author

@alefranz alefranz Aug 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could add another property dockerSourceImage, and, when present, instead of doing a docker build, do a docker pull then tagging the image with the dockerImageName so that the rest of the logic stay the same.
What do you think @sebastienros ? would you accept a PR for that?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with the suggestion. Had the same issue myself which required me to create a dumb docker file. dockerImage ? Would allow for name and tag. And change how dockerImageName is constructed when not provided to be sure the tag part is not interfering with the syntax of the command line.

16 changes: 16 additions & 0 deletions samples/client/mockserver/config/mappings/all.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"mappings": [
{
"request": {
"urlPath": "/",
"method": "GET"
},
"response": {
"status": 200,
"body": "Hello World!",
"fixedDelayMilliseconds": 20
},
"priority": 10
}
]
}
4 changes: 3 additions & 1 deletion src/Microsoft.Crank.Agent/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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}";
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to run this to be able to run locally on windows without having to create a network and to be able to map the port.
Not sure however if that Port parameter is the correct parameter.

Maybe there should be a more generic argument to pass parameter to docker while I believe currently you can only specify arguemnts to the container

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can just keep the port:port version on Windows. I used SELF because I was trying to create a faster network interface, but at least if port:port works it's better for now.


if (job.Collect && job.CollectStartup)
{
Expand Down