Added Appinsights K8s telemetry initializer

This commit is contained in:
Ramón Tomás 2017-10-11 18:53:26 +02:00
parent a04cef97ef
commit c3e15969b9
26 changed files with 182 additions and 16 deletions

1
.env
View File

@ -24,3 +24,4 @@ ESHOP_PROD_EXTERNAL_DNS_NAME_OR_IP=10.121.122.92
#ESHOP_SERVICE_BUS_USERNAME=<ServiceBusUserName-OnlyUsedIfUsingRabbitMQUnderwindows>
#ESHOP_SERVICE_BUS_PASSWORD=<ServiceBusUserPassword-OnlyUsedIfUsingRabbitMQUnderwindows>
#INSTRUMENTATION_KEY=
#ORCHESTRATOR_TYPE=<k8S/SF>

View File

@ -20,6 +20,7 @@ services:
- EventBusPassword=${ESHOP_SERVICE_BUS_PASSWORD}
- AzureServiceBusEnabled=False
- ApplicationInsights__InstrumentationKey=${INSTRUMENTATION_KEY}
- OrchestratorType=${ORCHESTRATOR_TYPE}
ports:
- "5103:80"
@ -38,6 +39,7 @@ services:
- AzureServiceBusEnabled=False
- AzureStorageEnabled=False
- ApplicationInsights__InstrumentationKey=${INSTRUMENTATION_KEY}
- OrchestratorType=${ORCHESTRATOR_TYPE}
ports:
- "5101:80"
@ -55,6 +57,7 @@ services:
- OrderingApiClient=http://${ESHOP_EXTERNAL_DNS_NAME_OR_IP}:5102
- UseCustomizationData=True
- ApplicationInsights__InstrumentationKey=${INSTRUMENTATION_KEY}
- OrchestratorType=${ORCHESTRATOR_TYPE}
ports:
- "5105:80"
@ -73,6 +76,7 @@ services:
- CheckUpdateTime=30000
- GracePeriodTime=1
- ApplicationInsights__InstrumentationKey=${INSTRUMENTATION_KEY}
- OrchestratorType=${ORCHESTRATOR_TYPE}
ports:
- "5102:80"
@ -95,6 +99,7 @@ services:
- AzureServiceBusEnabled=False
- AzureStorageEnabled=False
- ApplicationInsights__InstrumentationKey=${INSTRUMENTATION_KEY}
- OrchestratorType=${ORCHESTRATOR_TYPE}
ports:
- "5110:80"
@ -116,6 +121,7 @@ services:
- PaymentUrlHC=http://payment.api/hc
- UseCustomizationData=True
- ApplicationInsights__InstrumentationKey=${INSTRUMENTATION_KEY}
- OrchestratorType=${ORCHESTRATOR_TYPE}
ports:
- "5104:80"
@ -137,6 +143,7 @@ services:
- PaymentUrlHC=http://payment.api/hc
- UseCustomizationData=True
- ApplicationInsights__InstrumentationKey=${INSTRUMENTATION_KEY}
- OrchestratorType=${ORCHESTRATOR_TYPE}
ports:
- "5100:80"
@ -154,6 +161,7 @@ services:
- mvc=http://webmvc/hc
- spa=http://webspa/hc
- ApplicationInsights__InstrumentationKey=${INSTRUMENTATION_KEY}
- OrchestratorType=${ORCHESTRATOR_TYPE}
ports:
- "5107:80"
@ -182,6 +190,7 @@ services:
- EventBusPassword=${ESHOP_SERVICE_BUS_PASSWORD}
- AzureServiceBusEnabled=False
- ApplicationInsights__InstrumentationKey=${INSTRUMENTATION_KEY}
- OrchestratorType=${ORCHESTRATOR_TYPE}
ports:
- "5109:80"

View File

@ -25,5 +25,7 @@ data:
keystore: keystore-data
GracePeriodManager_GracePeriodTime: "1"
GracePeriodManager_CheckUpdateTime: "15000"
Instrumentation_Key: ""

View File

@ -32,11 +32,18 @@ spec:
configMapKeyRef:
name: externalcfg
key: UseAzureServiceBus
- name: ApplicationInsights__InstrumentationKey
valueFrom:
configMapKeyRef:
name: externalcfg
key: Instrumentation_Key
- name: IdentityUrl
valueFrom:
configMapKeyRef:
name: urls
key: IdentityUrl
- name: OrchestratorType
value: 'K8S'
ports:
- containerPort: 80
readinessProbe:
@ -95,6 +102,13 @@ spec:
configMapKeyRef:
name: externalcfg
key: CatalogBus
- name: ApplicationInsights__InstrumentationKey
valueFrom:
configMapKeyRef:
name: externalcfg
key: Instrumentation_Key
- name: OrchestratorType
value: 'K8S'
ports:
- containerPort: 80
readinessProbe:
@ -133,7 +147,7 @@ spec:
env:
- name: PATH_BASE
value: /identity
- name: ConnectionStrings__DefaultConnection
- name: ConnectionString
valueFrom:
configMapKeyRef:
name: externalcfg
@ -174,7 +188,14 @@ spec:
valueFrom:
configMapKeyRef:
name: urls
key: OrderingApiClient
key: OrderingApiClient
- name: ApplicationInsights__InstrumentationKey
valueFrom:
configMapKeyRef:
name: externalcfg
key: Instrumentation_Key
- name: OrchestratorType
value: 'K8S'
ports:
- containerPort: 80
readinessProbe:
@ -242,7 +263,14 @@ spec:
valueFrom:
configMapKeyRef:
name: externalcfg
key: GracePeriodManager_GracePeriodTime
key: GracePeriodManager_GracePeriodTime
- name: ApplicationInsights__InstrumentationKey
valueFrom:
configMapKeyRef:
name: externalcfg
key: Instrumentation_Key
- name: OrchestratorType
value: 'K8S'
ports:
- containerPort: 80
readinessProbe:
@ -310,7 +338,14 @@ spec:
valueFrom:
configMapKeyRef:
name: urls
key: IdentityUrl
key: IdentityUrl
- name: ApplicationInsights__InstrumentationKey
valueFrom:
configMapKeyRef:
name: externalcfg
key: Instrumentation_Key
- name: OrchestratorType
value: 'K8S'
ports:
- containerPort: 80
readinessProbe:
@ -388,7 +423,14 @@ spec:
valueFrom:
configMapKeyRef:
name: urls
key: Marketing_PicBaseUrl
key: Marketing_PicBaseUrl
- name: ApplicationInsights__InstrumentationKey
valueFrom:
configMapKeyRef:
name: externalcfg
key: Instrumentation_Key
- name: OrchestratorType
value: 'K8S'
ports:
- containerPort: 80
readinessProbe:
@ -437,6 +479,13 @@ spec:
configMapKeyRef:
name: externalcfg
key: PaymentBus
- name: ApplicationInsights__InstrumentationKey
valueFrom:
configMapKeyRef:
name: externalcfg
key: Instrumentation_Key
- name: OrchestratorType
value: 'K8S'
ports:
- containerPort: 80
readinessProbe:
@ -546,7 +595,14 @@ spec:
valueFrom:
configMapKeyRef:
name: urls
key: PaymentHealthCheckUrl
key: PaymentHealthCheckUrl
- name: ApplicationInsights__InstrumentationKey
valueFrom:
configMapKeyRef:
name: externalcfg
key: Instrumentation_Key
- name: OrchestratorType
value: 'K8S'
ports:
- containerPort: 80
readinessProbe:
@ -629,7 +685,14 @@ spec:
valueFrom:
configMapKeyRef:
name: urls
key: PaymentHealthCheckUrl
key: PaymentHealthCheckUrl
- name: ApplicationInsights__InstrumentationKey
valueFrom:
configMapKeyRef:
name: externalcfg
key: Instrumentation_Key
- name: OrchestratorType
value: 'K8S'
ports:
- containerPort: 80
imagePullSecrets:
@ -726,6 +789,13 @@ spec:
configMapKeyRef:
name: urls
key: PaymentHealthCheckUrl
- name: ApplicationInsights__InstrumentationKey
valueFrom:
configMapKeyRef:
name: externalcfg
key: Instrumentation_Key
- name: OrchestratorType
value: 'K8S'
ports:
- containerPort: 80
readinessProbe:

View File

@ -17,6 +17,8 @@
<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.1.1" />
<PackageReference Include="Microsoft.ApplicationInsights.DependencyCollector" Version="2.4.1" />
<PackageReference Include="Microsoft.ApplicationInsights.Kubernetes" Version="1.0.0-beta1" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="4.1.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="1.0.0" />

View File

@ -34,6 +34,7 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API
builder.AddConsole();
builder.AddDebug();
})
.UseApplicationInsights()
.Build();
}
}

View File

@ -65,6 +65,12 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API
services.Configure<BasketSettings>(Configuration);
if(Configuration.GetValue<string>("OrchestratorType").Equals("K8S"))
{
// Enable K8s telemetry initializer
services.EnableKubernetes();
}
//By connecting here we are making sure that our service
//cannot start until redis is ready. This might slow down startup,
//but given that there is a delay on resolving the ip address
@ -203,8 +209,8 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API
// prevent from mapping "sub" claim to nameidentifier.
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
var identityUrl = Configuration.GetValue<string>("IdentityUrl");
var identityUrl = Configuration.GetValue<string>("IdentityUrl");
services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;

View File

@ -36,6 +36,8 @@
<ItemGroup>
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="4.1.0" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.1.1" />
<PackageReference Include="Microsoft.ApplicationInsights.DependencyCollector" Version="2.4.1" />
<PackageReference Include="Microsoft.ApplicationInsights.Kubernetes" Version="1.0.0-beta1" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="1.0.0" />
<PackageReference Include="System.IO.Compression.ZipFile" Version="4.3.0" />

View File

@ -32,6 +32,7 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseApplicationInsights()
.UseHealthChecks("/hc")
.UseContentRoot(Directory.GetCurrentDirectory())
.UseWebRoot("Pics")
@ -44,8 +45,7 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API
builder.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
builder.AddConsole();
builder.AddDebug();
})
.UseApplicationInsights()
})
.Build();
}
}

View File

@ -13,7 +13,6 @@
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBusServiceBus;
using Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF;
using Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF.Services;
using Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure;
using Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationEvents.EventHandling;
@ -43,6 +42,12 @@
services.AddApplicationInsightsTelemetry(Configuration);
if (Configuration.GetValue<string>("OrchestratorType").Equals("K8S"))
{
// Enable K8s telemetry initializer
services.EnableKubernetes();
}
services.AddHealthChecks(checks =>
{
var minutes = 1;

View File

@ -17,6 +17,8 @@
<ItemGroup>
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="4.1.0" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.1.1" />
<PackageReference Include="Microsoft.ApplicationInsights.DependencyCollector" Version="2.4.1" />
<PackageReference Include="Microsoft.ApplicationInsights.Kubernetes" Version="1.0.0-beta1" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="IdentityServer4.AspNetIdentity" Version="2.0.0-rc1" />
<PackageReference Include="IdentityServer4.EntityFramework" Version="2.0.0-rc1" />

View File

@ -33,6 +33,12 @@ namespace Microsoft.eShopOnContainers.Services.Identity.API
{
services.AddApplicationInsightsTelemetry(Configuration);
if (Configuration.GetValue<string>("OrchestratorType").Equals("K8S"))
{
// Enable K8s telemetry initializer
services.EnableKubernetes();
}
// Add framework services.
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration["ConnectionString"],

View File

@ -12,6 +12,8 @@
<ItemGroup>
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="4.1.0" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.1.1" />
<PackageReference Include="Microsoft.ApplicationInsights.DependencyCollector" Version="2.4.1" />
<PackageReference Include="Microsoft.ApplicationInsights.Kubernetes" Version="1.0.0-beta1" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="mongocsharpdriver" Version="2.4.4" />
<PackageReference Include="MongoDB.Bson" Version="2.4.4" />

View File

@ -39,6 +39,12 @@ namespace Microsoft.eShopOnContainers.Services.Locations.API
{
services.AddApplicationInsightsTelemetry(Configuration);
if (Configuration.GetValue<string>("OrchestratorType").Equals("K8S"))
{
// Enable K8s telemetry initializer
services.EnableKubernetes();
}
services.AddMvc(options =>
{
options.Filters.Add(typeof(HttpGlobalExceptionFilter));

View File

@ -22,6 +22,8 @@
<ItemGroup>
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="4.1.0" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.1.1" />
<PackageReference Include="Microsoft.ApplicationInsights.DependencyCollector" Version="2.4.1" />
<PackageReference Include="Microsoft.ApplicationInsights.Kubernetes" Version="1.0.0-beta1" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="mongocsharpdriver" Version="2.4.4" />
<PackageReference Include="MongoDB.Bson" Version="2.4.4" />

View File

@ -46,6 +46,12 @@
{
services.AddApplicationInsightsTelemetry(Configuration);
if (Configuration.GetValue<string>("OrchestratorType").Equals("K8S"))
{
// Enable K8s telemetry initializer
services.EnableKubernetes();
}
// Add framework services.
services.AddMvc(options =>
{
@ -200,7 +206,7 @@
ConfigureEventBus(app);
}
private void ConfigureAuthService(IServiceCollection services)
private void ConfigureAuthService(IServiceCollection services, ILoggerFactory loggerFactory)
{
// prevent from mapping "sub" claim to nameidentifier.
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();

View File

@ -38,6 +38,8 @@
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="3.0.0" />
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="4.1.0" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.1.1" />
<PackageReference Include="Microsoft.ApplicationInsights.DependencyCollector" Version="2.4.1" />
<PackageReference Include="Microsoft.ApplicationInsights.Kubernetes" Version="1.0.0-beta1" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="MediatR" Version="3.0.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="1.0.0" />

View File

@ -47,7 +47,13 @@
public IServiceProvider ConfigureServices(IServiceCollection services)
{
services.AddApplicationInsightsTelemetry(Configuration);
if (Configuration.GetValue<string>("OrchestratorType").Equals("K8S"))
{
// Enable K8s telemetry initializer
services.EnableKubernetes();
}
// Add framework services.
services.AddMvc(options =>
{

View File

@ -9,6 +9,8 @@
<ItemGroup>
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="4.1.0" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.1.1" />
<PackageReference Include="Microsoft.ApplicationInsights.DependencyCollector" Version="2.4.1" />
<PackageReference Include="Microsoft.ApplicationInsights.Kubernetes" Version="1.0.0-beta1" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="1.0.0" />
</ItemGroup>

View File

@ -32,9 +32,16 @@ namespace Payment.API
// This method gets called by the runtime. Use this method to add services to the container.
public IServiceProvider ConfigureServices(IServiceCollection services)
{
services.AddApplicationInsightsTelemetry(Configuration);
services.Configure<PaymentSettings>(Configuration);
if (Configuration.GetValue<string>("OrchestratorType").Equals("K8S"))
{
// Enable K8s telemetry initializer
services.EnableKubernetes();
}
if (Configuration.GetValue<bool>("AzureServiceBusEnabled"))
{
services.AddSingleton<IServiceBusPersisterConnection>(sp =>
@ -84,8 +91,11 @@ namespace Payment.API
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddAzureWebAppDiagnostics();
loggerFactory.AddApplicationInsights(app.ApplicationServices, LogLevel.Trace);
var pathBase = Configuration["PATH_BASE"];
if (!string.IsNullOrEmpty(pathBase))
{

View File

@ -33,6 +33,12 @@ namespace Microsoft.eShopOnContainers.WebMVC
{
services.AddApplicationInsightsTelemetry(Configuration);
if (Configuration.GetValue<string>("OrchestratorType").Equals("K8S"))
{
// Enable K8s telemetry initializer
services.EnableKubernetes();
}
services.AddMvc();
services.AddSession();

View File

@ -37,6 +37,8 @@
<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.1.1" />
<PackageReference Include="Microsoft.ApplicationInsights.DependencyCollector" Version="2.4.1" />
<PackageReference Include="Microsoft.ApplicationInsights.Kubernetes" Version="1.0.0-beta1" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Fabric.MSBuild" Version="1.6.1" />
</ItemGroup>

View File

@ -38,6 +38,12 @@ namespace eShopConContainers.WebSPA
{
services.AddApplicationInsightsTelemetry(Configuration);
if (Configuration.GetValue<string>("OrchestratorType").Equals("K8S"))
{
// Enable K8s telemetry initializer
services.EnableKubernetes();
}
services.AddHealthChecks(checks =>
{
var minutes = 1;

View File

@ -28,6 +28,8 @@
<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.1.1" />
<PackageReference Include="Microsoft.ApplicationInsights.DependencyCollector" Version="2.4.1" />
<PackageReference Include="Microsoft.ApplicationInsights.Kubernetes" Version="1.0.0-beta1" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
</ItemGroup>

View File

@ -25,6 +25,12 @@ namespace WebStatus
{
services.AddApplicationInsightsTelemetry(Configuration);
if (Configuration.GetValue<string>("OrchestratorType").Equals("K8S"))
{
// Enable K8s telemetry initializer
services.EnableKubernetes();
}
services.AddOptions();
// Add framework services.

View File

@ -6,6 +6,8 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.1.1" />
<PackageReference Include="Microsoft.ApplicationInsights.DependencyCollector" Version="2.4.1" />
<PackageReference Include="Microsoft.ApplicationInsights.Kubernetes" Version="1.0.0-beta1" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
</ItemGroup>
<ItemGroup>