From 36e31d39e4ef867fadbb3a4191f82565af3cb5b0 Mon Sep 17 00:00:00 2001 From: Saar Shen Date: Fri, 7 Jun 2019 15:53:00 -0700 Subject: [PATCH] Dev/saars/dev f5 env (#186) * Add a webapi for F5 into debugging * Add a workspace * Fix a small thing in MultipleKeys example * Add tasks to build examples * Remove launch.json for product code * Update F5 WebApi project --- .vscode/tasks.json | 55 --------------- dev/.vscode/launch.json | 24 +++++++ dev/.vscode/tasks.json | 20 ++++++ dev/F5WebApi/Controllers/ValuesController.cs | 45 ++++++++++++ dev/F5WebApi/F5WebApi.csproj | 17 +++++ dev/F5WebApi/Program.cs | 17 +++++ dev/F5WebApi/Properties/launchSettings.json | 30 ++++++++ dev/F5WebApi/Startup.cs | 59 ++++++++++++++++ dev/F5WebApi/appsettings.Development.json | 9 +++ dev/F5WebApi/appsettings.json | 9 +++ {.vscode => examples/.vscode}/launch.json | 7 +- examples/.vscode/tasks.json | 70 +++++++++++++++++++ examples/MultipleIKeys/Startup.cs | 13 ++-- .../WindowsContainer/AspNetCoreNano.csproj | 1 + examples/WindowsContainer/NuGet.config | 8 --- solution.code-workspace | 32 +++++++++ src/.vscode/tasks.json | 13 ---- {src => tests}/.vscode/launch.json | 7 +- tests/.vscode/tasks.json | 28 ++++++++ 19 files changed, 374 insertions(+), 90 deletions(-) delete mode 100644 .vscode/tasks.json create mode 100644 dev/.vscode/launch.json create mode 100644 dev/.vscode/tasks.json create mode 100644 dev/F5WebApi/Controllers/ValuesController.cs create mode 100644 dev/F5WebApi/F5WebApi.csproj create mode 100644 dev/F5WebApi/Program.cs create mode 100644 dev/F5WebApi/Properties/launchSettings.json create mode 100644 dev/F5WebApi/Startup.cs create mode 100644 dev/F5WebApi/appsettings.Development.json create mode 100644 dev/F5WebApi/appsettings.json rename {.vscode => examples/.vscode}/launch.json (77%) create mode 100644 examples/.vscode/tasks.json delete mode 100644 examples/WindowsContainer/NuGet.config create mode 100644 solution.code-workspace rename {src => tests}/.vscode/launch.json (77%) create mode 100644 tests/.vscode/tasks.json diff --git a/.vscode/tasks.json b/.vscode/tasks.json deleted file mode 100644 index d5968cb1..00000000 --- a/.vscode/tasks.json +++ /dev/null @@ -1,55 +0,0 @@ -{ - "version": "2.0.0", - "tasks": [ - { - "label": "Build Debug", - "command": "${workspaceFolder}/build/Build.cmd", - "type": "shell", - "group": "build", - "problemMatcher": "$msCompile" - }, - { - "label": "Build Release", - "command": "${workspaceFolder}/build/Build.cmd", - "type": "shell", - "group": "build", - "args": [ - "Release", - ], - "problemMatcher": "$msCompile", - }, - { - "label": "ReBuild Debug", - "command": "${workspaceFolder}/build/Build.cmd", - "type": "shell", - "group": "build", - "args": [ - "Debug", - "True", - ], - "problemMatcher": "$msCompile" - }, - { - "label": "ReBuild Release", - "command": "${workspaceFolder}/build/Build.cmd", - "type": "shell", - "group": "build", - "args": [ - "Release", - "True", - ], - "problemMatcher": "$msCompile", - }, - { - "label": "Run Unit Tests", - "command": "dotnet", - "type": "process", - "group": "test", - "args": [ - "test", - "${workspaceFolder}/tests/UnitTests" - ], - "problemMatcher": "$msCompile" - } - ] -} \ No newline at end of file diff --git a/dev/.vscode/launch.json b/dev/.vscode/launch.json new file mode 100644 index 00000000..068ec5d8 --- /dev/null +++ b/dev/.vscode/launch.json @@ -0,0 +1,24 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": ".NET Core Launch - F5 WebApi", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "Build F5 WebApi", + "program": "${workspaceFolder}/F5WebApi/bin/Debug/netcoreapp2.2/F5WebApi.dll", + "args": [], + "cwd": "${workspaceFolder}/F5WebApi", + "stopAtEntry": false, + "launchBrowser": { + "enabled": true + }, + "env": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + ] +} \ No newline at end of file diff --git a/dev/.vscode/tasks.json b/dev/.vscode/tasks.json new file mode 100644 index 00000000..3b6471f4 --- /dev/null +++ b/dev/.vscode/tasks.json @@ -0,0 +1,20 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + { + "label": "Build F5 WebApi", + "command": "dotnet build", + "type": "shell", + "group": "build", + "presentation": { + "reveal": "always" + }, + "options": { + "cwd": "${workspaceFolder}/F5WebApi" + }, + "problemMatcher": "$msCompile" + } + ] +} \ No newline at end of file diff --git a/dev/F5WebApi/Controllers/ValuesController.cs b/dev/F5WebApi/Controllers/ValuesController.cs new file mode 100644 index 00000000..9f04ec8d --- /dev/null +++ b/dev/F5WebApi/Controllers/ValuesController.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; + +namespace F5WebApi.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class ValuesController : ControllerBase + { + // GET api/values + [HttpGet] + public ActionResult> Get() + { + return new string[] { "value1", "value2" }; + } + + // GET api/values/5 + [HttpGet("{id}")] + public ActionResult Get(int id) + { + return "value"; + } + + // POST api/values + [HttpPost] + public void Post([FromBody] string value) + { + } + + // PUT api/values/5 + [HttpPut("{id}")] + public void Put(int id, [FromBody] string value) + { + } + + // DELETE api/values/5 + [HttpDelete("{id}")] + public void Delete(int id) + { + } + } +} diff --git a/dev/F5WebApi/F5WebApi.csproj b/dev/F5WebApi/F5WebApi.csproj new file mode 100644 index 00000000..e3f77211 --- /dev/null +++ b/dev/F5WebApi/F5WebApi.csproj @@ -0,0 +1,17 @@ + + + + netcoreapp2.2 + InProcess + + + + + + + + + + + + diff --git a/dev/F5WebApi/Program.cs b/dev/F5WebApi/Program.cs new file mode 100644 index 00000000..9e9e8267 --- /dev/null +++ b/dev/F5WebApi/Program.cs @@ -0,0 +1,17 @@ +using Microsoft.AspNetCore; +using Microsoft.AspNetCore.Hosting; + +namespace F5WebApi +{ + public class Program + { + public static void Main(string[] args) + { + CreateHostBuilder(args).Build().Run(); + } + + public static IWebHostBuilder CreateHostBuilder(string[] args) => + WebHost.CreateDefaultBuilder(args) + .UseStartup(); + } +} diff --git a/dev/F5WebApi/Properties/launchSettings.json b/dev/F5WebApi/Properties/launchSettings.json new file mode 100644 index 00000000..f333625e --- /dev/null +++ b/dev/F5WebApi/Properties/launchSettings.json @@ -0,0 +1,30 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:31345", + "sslPort": 44371 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "api/values", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "F5WebApi": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "api/values", + "applicationUrl": "https://localhost:5001;http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} \ No newline at end of file diff --git a/dev/F5WebApi/Startup.cs b/dev/F5WebApi/Startup.cs new file mode 100644 index 00000000..81f2565b --- /dev/null +++ b/dev/F5WebApi/Startup.cs @@ -0,0 +1,59 @@ +using System.Diagnostics; +using Microsoft.ApplicationInsights.Kubernetes.Debugging; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; + +namespace F5WebApi +{ + public class Startup + { + public Startup(IConfiguration configuration) + { + Configuration = configuration; + } + + public IConfiguration Configuration { get; } + + // This method gets called by the runtime. Use this method to add services to the container. + public void ConfigureServices(IServiceCollection services) + { + // To use this project for F5 debugging, follow these steps: + + // Output the diagnostic source logs to the console. + var observer = new ApplicationInsightsKubernetesDiagnosticObserver(DiagnosticLogLevel.Trace); + ApplicationInsightsKubernetesDiagnosticSource.Instance.Observable.SubscribeWithAdapter(observer); + + // Step 1. Set iKey in the parameter below. + services.AddApplicationInsightsTelemetry("your-instrumentation-key"); + + // Step 2. Call proper overloads of AddApplicationInsightsKubernetesEnricher. + services.AddApplicationInsightsKubernetesEnricher(applyOptions: null, + kubernetesServiceCollectionBuilder: KubernetesDebuggingServiceCollectionBuilderFactory.Instance.Create(), + detectKubernetes: () => true); + // Step 3. Set a break point and press F5. + // ~ + + services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); + } + + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app, IHostingEnvironment env) + { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + } + else + { + // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. + app.UseHsts(); + } + + app.UseHttpsRedirection(); + app.UseMvc(); + } + } +} diff --git a/dev/F5WebApi/appsettings.Development.json b/dev/F5WebApi/appsettings.Development.json new file mode 100644 index 00000000..e203e940 --- /dev/null +++ b/dev/F5WebApi/appsettings.Development.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Debug", + "System": "Information", + "Microsoft": "Information" + } + } +} diff --git a/dev/F5WebApi/appsettings.json b/dev/F5WebApi/appsettings.json new file mode 100644 index 00000000..7cb5ac81 --- /dev/null +++ b/dev/F5WebApi/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "AllowedHosts": "*" +} diff --git a/.vscode/launch.json b/examples/.vscode/launch.json similarity index 77% rename from .vscode/launch.json rename to examples/.vscode/launch.json index 6ebab05d..d2853675 100644 --- a/.vscode/launch.json +++ b/examples/.vscode/launch.json @@ -10,13 +10,12 @@ "request": "launch", "preLaunchTask": "build", // If you have changed target frameworks, make sure to update the program path. - "program": "${workspaceFolder}/tests/UnitTests/bin/Debug/netcoreapp2.0/Microsoft.ApplicationInsights.Kubernetes.UnitTests.dll", + "program": "${workspaceFolder}/BasicConsoleAppILogger/bin/Debug/netcoreapp2.2/BasicConsoleAppILogger.dll", "args": [], - "cwd": "${workspaceFolder}/tests/UnitTests", + "cwd": "${workspaceFolder}/BasicConsoleAppILogger", // For more information about the 'console' field, see https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window "console": "internalConsole", - "stopAtEntry": false, - "internalConsoleOptions": "openOnSessionStart" + "stopAtEntry": false }, { "name": ".NET Core Attach", diff --git a/examples/.vscode/tasks.json b/examples/.vscode/tasks.json new file mode 100644 index 00000000..803a067c --- /dev/null +++ b/examples/.vscode/tasks.json @@ -0,0 +1,70 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "Build Example - BasicConsoleApp", + "command": "dotnet", + "type": "shell", + "group": "build", + "problemMatcher": "$msCompile", + "args": [ + "build" + ], + "options": { + "cwd": "${workspaceFolder}/BasicConsoleApp/src/" + } + }, + { + "label": "Build Example - BasicUsage_clr21_RBAC", + "command": "dotnet", + "type": "shell", + "group": "build", + "problemMatcher": "$msCompile", + "args": [ + "build" + ], + "options": { + "cwd": "${workspaceFolder}/BasicUsage_clr21_RBAC/app/" + } + }, + { + "label": "Build Example - MultipleIKeys", + "command": "dotnet", + "type": "shell", + "group": "build", + "problemMatcher": "$msCompile", + "args": [ + "build" + ], + "options": { + "cwd": "${workspaceFolder}/MultipleIKeys/" + } + }, + { + "label": "Build Example - ZeroUserCodeLightup", + "command": "dotnet", + "type": "shell", + "group": "build", + "problemMatcher": "$msCompile", + "args": [ + "build" + ], + "options": { + "cwd": "${workspaceFolder}/ZeroUserCodeLightup/" + } + }, + { + "label": "Build Example - WindowsContainer", + "command": "dotnet", + "type": "shell", + "group": "build", + "problemMatcher": "$msCompile", + "args": [ + "build" + ], + "options": { + "cwd": "${workspaceFolder}/WindowsContainer/" + } + }, + ] +} \ No newline at end of file diff --git a/examples/MultipleIKeys/Startup.cs b/examples/MultipleIKeys/Startup.cs index 7b4a5c24..073f4c67 100644 --- a/examples/MultipleIKeys/Startup.cs +++ b/examples/MultipleIKeys/Startup.cs @@ -39,15 +39,16 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env) app.UseExceptionHandler("/Home/Error"); } - // uService_prototype - TelemetryConfiguration aiConfig = new TelemetryConfiguration("8e9838a3-ad63-4d30-96f7-2f0a505bc0f6", app.ApplicationServices.GetService()); - aiConfig.AddApplicationInsightsKubernetesEnricher(); + // Application Insights 1 + TelemetryConfiguration aiConfig = new TelemetryConfiguration("your iKey 1", app.ApplicationServices.GetService()); + aiConfig.AddApplicationInsightsKubernetesEnricher(applyOptions: null); TelemetryClient client = new TelemetryClient(aiConfig); // Invoking the constructor for the TelemetryInitializer client.TrackEvent("Hello"); - // saarsfun01 - TelemetryConfiguration aiConfig2 = new TelemetryConfiguration("5789ad10-8b39-4f8a-88dc-632d1342d5e0", app.ApplicationServices.GetService()); - aiConfig2.AddApplicationInsightsKubernetesEnricher(); + + // Application Insights 2 + TelemetryConfiguration aiConfig2 = new TelemetryConfiguration("your iKey 2", app.ApplicationServices.GetService()); + aiConfig2.AddApplicationInsightsKubernetesEnricher(applyOptions: null); TelemetryClient client2 = new TelemetryClient(aiConfig2); var _forget = ThrowAnotherHelloAsync(client, client2); diff --git a/examples/WindowsContainer/AspNetCoreNano.csproj b/examples/WindowsContainer/AspNetCoreNano.csproj index dd0c9804..923f6f95 100644 --- a/examples/WindowsContainer/AspNetCoreNano.csproj +++ b/examples/WindowsContainer/AspNetCoreNano.csproj @@ -6,6 +6,7 @@ + diff --git a/examples/WindowsContainer/NuGet.config b/examples/WindowsContainer/NuGet.config deleted file mode 100644 index 710d9f1a..00000000 --- a/examples/WindowsContainer/NuGet.config +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - diff --git a/solution.code-workspace b/solution.code-workspace new file mode 100644 index 00000000..086b77c2 --- /dev/null +++ b/solution.code-workspace @@ -0,0 +1,32 @@ +{ + "folders": [ + { + // Source code for Application Insights for Kubernetes + "name": "Product", + "path": "./src", + }, + { + // Enables F5 to debug the code + "name": "Debugging", + "path": "./dev", + }, + { + // Tests + "name": "Tests", + "path": "./tests", + }, + { + // Examples + "name": "Examples", + "path": "./examples", + }, + ], + "settings": { + "files.exclude": { + "**/.classpath": true, + "**/.project": true, + "**/.settings": true, + "**/.factorypath": true + }, + } +} \ No newline at end of file diff --git a/src/.vscode/tasks.json b/src/.vscode/tasks.json index 9d206e49..094f73e5 100644 --- a/src/.vscode/tasks.json +++ b/src/.vscode/tasks.json @@ -39,19 +39,6 @@ "True", ], "problemMatcher": "$msCompile", - }, - { - "label": "Run Unit Tests", - "command": "dotnet", - "type": "process", - "group": "test", - "options": { - "cwd": "${workspaceFolder}/../tests/UnitTests" - }, - "args": [ - "test" - ], - "problemMatcher": "$msCompile" } ] } \ No newline at end of file diff --git a/src/.vscode/launch.json b/tests/.vscode/launch.json similarity index 77% rename from src/.vscode/launch.json rename to tests/.vscode/launch.json index 6ebab05d..ff9d8b49 100644 --- a/src/.vscode/launch.json +++ b/tests/.vscode/launch.json @@ -10,13 +10,12 @@ "request": "launch", "preLaunchTask": "build", // If you have changed target frameworks, make sure to update the program path. - "program": "${workspaceFolder}/tests/UnitTests/bin/Debug/netcoreapp2.0/Microsoft.ApplicationInsights.Kubernetes.UnitTests.dll", + "program": "${workspaceFolder}/UnitTests/bin/Debug/netcoreapp2.0/Microsoft.ApplicationInsights.Kubernetes.UnitTests.dll", "args": [], - "cwd": "${workspaceFolder}/tests/UnitTests", + "cwd": "${workspaceFolder}/UnitTests", // For more information about the 'console' field, see https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window "console": "internalConsole", - "stopAtEntry": false, - "internalConsoleOptions": "openOnSessionStart" + "stopAtEntry": false }, { "name": ".NET Core Attach", diff --git a/tests/.vscode/tasks.json b/tests/.vscode/tasks.json new file mode 100644 index 00000000..eca89fa1 --- /dev/null +++ b/tests/.vscode/tasks.json @@ -0,0 +1,28 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "Build Unit tests", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/UnitTests/UnitTests.csproj" + ], + "problemMatcher": "$tsc" + }, + { + "label": "Run Unit Tests", + "command": "dotnet", + "type": "process", + "group": "test", + "options": { + "cwd": "${workspaceFolder}/UnitTests" + }, + "args": [ + "test" + ], + "problemMatcher": "$msCompile" + } + ] +} \ No newline at end of file