Skip to content

Commit c3e1596

Browse files
committed
Added Appinsights K8s telemetry initializer
1 parent a04cef9 commit c3e1596

26 files changed

Lines changed: 182 additions & 16 deletions

File tree

.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ ESHOP_PROD_EXTERNAL_DNS_NAME_OR_IP=10.121.122.92
2424
#ESHOP_SERVICE_BUS_USERNAME=<ServiceBusUserName-OnlyUsedIfUsingRabbitMQUnderwindows>
2525
#ESHOP_SERVICE_BUS_PASSWORD=<ServiceBusUserPassword-OnlyUsedIfUsingRabbitMQUnderwindows>
2626
#INSTRUMENTATION_KEY=
27+
#ORCHESTRATOR_TYPE=<k8S/SF>

docker-compose.override.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ services:
2020
- EventBusPassword=${ESHOP_SERVICE_BUS_PASSWORD}
2121
- AzureServiceBusEnabled=False
2222
- ApplicationInsights__InstrumentationKey=${INSTRUMENTATION_KEY}
23+
- OrchestratorType=${ORCHESTRATOR_TYPE}
2324
ports:
2425
- "5103:80"
2526

@@ -38,6 +39,7 @@ services:
3839
- AzureServiceBusEnabled=False
3940
- AzureStorageEnabled=False
4041
- ApplicationInsights__InstrumentationKey=${INSTRUMENTATION_KEY}
42+
- OrchestratorType=${ORCHESTRATOR_TYPE}
4143
ports:
4244
- "5101:80"
4345

@@ -55,6 +57,7 @@ services:
5557
- OrderingApiClient=http://${ESHOP_EXTERNAL_DNS_NAME_OR_IP}:5102
5658
- UseCustomizationData=True
5759
- ApplicationInsights__InstrumentationKey=${INSTRUMENTATION_KEY}
60+
- OrchestratorType=${ORCHESTRATOR_TYPE}
5861
ports:
5962
- "5105:80"
6063

@@ -73,6 +76,7 @@ services:
7376
- CheckUpdateTime=30000
7477
- GracePeriodTime=1
7578
- ApplicationInsights__InstrumentationKey=${INSTRUMENTATION_KEY}
79+
- OrchestratorType=${ORCHESTRATOR_TYPE}
7680
ports:
7781
- "5102:80"
7882

@@ -95,6 +99,7 @@ services:
9599
- AzureServiceBusEnabled=False
96100
- AzureStorageEnabled=False
97101
- ApplicationInsights__InstrumentationKey=${INSTRUMENTATION_KEY}
102+
- OrchestratorType=${ORCHESTRATOR_TYPE}
98103
ports:
99104
- "5110:80"
100105

@@ -116,6 +121,7 @@ services:
116121
- PaymentUrlHC=http://payment.api/hc
117122
- UseCustomizationData=True
118123
- ApplicationInsights__InstrumentationKey=${INSTRUMENTATION_KEY}
124+
- OrchestratorType=${ORCHESTRATOR_TYPE}
119125
ports:
120126
- "5104:80"
121127

@@ -137,6 +143,7 @@ services:
137143
- PaymentUrlHC=http://payment.api/hc
138144
- UseCustomizationData=True
139145
- ApplicationInsights__InstrumentationKey=${INSTRUMENTATION_KEY}
146+
- OrchestratorType=${ORCHESTRATOR_TYPE}
140147
ports:
141148
- "5100:80"
142149

@@ -154,6 +161,7 @@ services:
154161
- mvc=http://webmvc/hc
155162
- spa=http://webspa/hc
156163
- ApplicationInsights__InstrumentationKey=${INSTRUMENTATION_KEY}
164+
- OrchestratorType=${ORCHESTRATOR_TYPE}
157165
ports:
158166
- "5107:80"
159167

@@ -182,6 +190,7 @@ services:
182190
- EventBusPassword=${ESHOP_SERVICE_BUS_PASSWORD}
183191
- AzureServiceBusEnabled=False
184192
- ApplicationInsights__InstrumentationKey=${INSTRUMENTATION_KEY}
193+
- OrchestratorType=${ORCHESTRATOR_TYPE}
185194
ports:
186195
- "5109:80"
187196

k8s/conf_local.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,7 @@ data:
2525
keystore: keystore-data
2626
GracePeriodManager_GracePeriodTime: "1"
2727
GracePeriodManager_CheckUpdateTime: "15000"
28+
Instrumentation_Key: ""
29+
2830

2931

k8s/deployments.yaml

Lines changed: 77 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,18 @@ spec:
3232
configMapKeyRef:
3333
name: externalcfg
3434
key: UseAzureServiceBus
35+
- name: ApplicationInsights__InstrumentationKey
36+
valueFrom:
37+
configMapKeyRef:
38+
name: externalcfg
39+
key: Instrumentation_Key
3540
- name: IdentityUrl
3641
valueFrom:
3742
configMapKeyRef:
3843
name: urls
3944
key: IdentityUrl
45+
- name: OrchestratorType
46+
value: 'K8S'
4047
ports:
4148
- containerPort: 80
4249
readinessProbe:
@@ -95,6 +102,13 @@ spec:
95102
configMapKeyRef:
96103
name: externalcfg
97104
key: CatalogBus
105+
- name: ApplicationInsights__InstrumentationKey
106+
valueFrom:
107+
configMapKeyRef:
108+
name: externalcfg
109+
key: Instrumentation_Key
110+
- name: OrchestratorType
111+
value: 'K8S'
98112
ports:
99113
- containerPort: 80
100114
readinessProbe:
@@ -133,7 +147,7 @@ spec:
133147
env:
134148
- name: PATH_BASE
135149
value: /identity
136-
- name: ConnectionStrings__DefaultConnection
150+
- name: ConnectionString
137151
valueFrom:
138152
configMapKeyRef:
139153
name: externalcfg
@@ -174,7 +188,14 @@ spec:
174188
valueFrom:
175189
configMapKeyRef:
176190
name: urls
177-
key: OrderingApiClient
191+
key: OrderingApiClient
192+
- name: ApplicationInsights__InstrumentationKey
193+
valueFrom:
194+
configMapKeyRef:
195+
name: externalcfg
196+
key: Instrumentation_Key
197+
- name: OrchestratorType
198+
value: 'K8S'
178199
ports:
179200
- containerPort: 80
180201
readinessProbe:
@@ -242,7 +263,14 @@ spec:
242263
valueFrom:
243264
configMapKeyRef:
244265
name: externalcfg
245-
key: GracePeriodManager_GracePeriodTime
266+
key: GracePeriodManager_GracePeriodTime
267+
- name: ApplicationInsights__InstrumentationKey
268+
valueFrom:
269+
configMapKeyRef:
270+
name: externalcfg
271+
key: Instrumentation_Key
272+
- name: OrchestratorType
273+
value: 'K8S'
246274
ports:
247275
- containerPort: 80
248276
readinessProbe:
@@ -310,7 +338,14 @@ spec:
310338
valueFrom:
311339
configMapKeyRef:
312340
name: urls
313-
key: IdentityUrl
341+
key: IdentityUrl
342+
- name: ApplicationInsights__InstrumentationKey
343+
valueFrom:
344+
configMapKeyRef:
345+
name: externalcfg
346+
key: Instrumentation_Key
347+
- name: OrchestratorType
348+
value: 'K8S'
314349
ports:
315350
- containerPort: 80
316351
readinessProbe:
@@ -388,7 +423,14 @@ spec:
388423
valueFrom:
389424
configMapKeyRef:
390425
name: urls
391-
key: Marketing_PicBaseUrl
426+
key: Marketing_PicBaseUrl
427+
- name: ApplicationInsights__InstrumentationKey
428+
valueFrom:
429+
configMapKeyRef:
430+
name: externalcfg
431+
key: Instrumentation_Key
432+
- name: OrchestratorType
433+
value: 'K8S'
392434
ports:
393435
- containerPort: 80
394436
readinessProbe:
@@ -437,6 +479,13 @@ spec:
437479
configMapKeyRef:
438480
name: externalcfg
439481
key: PaymentBus
482+
- name: ApplicationInsights__InstrumentationKey
483+
valueFrom:
484+
configMapKeyRef:
485+
name: externalcfg
486+
key: Instrumentation_Key
487+
- name: OrchestratorType
488+
value: 'K8S'
440489
ports:
441490
- containerPort: 80
442491
readinessProbe:
@@ -546,7 +595,14 @@ spec:
546595
valueFrom:
547596
configMapKeyRef:
548597
name: urls
549-
key: PaymentHealthCheckUrl
598+
key: PaymentHealthCheckUrl
599+
- name: ApplicationInsights__InstrumentationKey
600+
valueFrom:
601+
configMapKeyRef:
602+
name: externalcfg
603+
key: Instrumentation_Key
604+
- name: OrchestratorType
605+
value: 'K8S'
550606
ports:
551607
- containerPort: 80
552608
readinessProbe:
@@ -629,7 +685,14 @@ spec:
629685
valueFrom:
630686
configMapKeyRef:
631687
name: urls
632-
key: PaymentHealthCheckUrl
688+
key: PaymentHealthCheckUrl
689+
- name: ApplicationInsights__InstrumentationKey
690+
valueFrom:
691+
configMapKeyRef:
692+
name: externalcfg
693+
key: Instrumentation_Key
694+
- name: OrchestratorType
695+
value: 'K8S'
633696
ports:
634697
- containerPort: 80
635698
imagePullSecrets:
@@ -726,6 +789,13 @@ spec:
726789
configMapKeyRef:
727790
name: urls
728791
key: PaymentHealthCheckUrl
792+
- name: ApplicationInsights__InstrumentationKey
793+
valueFrom:
794+
configMapKeyRef:
795+
name: externalcfg
796+
key: Instrumentation_Key
797+
- name: OrchestratorType
798+
value: 'K8S'
729799
ports:
730800
- containerPort: 80
731801
readinessProbe:

src/Services/Basket/Basket.API/Basket.API.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
<ItemGroup>
1919
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.1.1" />
20+
<PackageReference Include="Microsoft.ApplicationInsights.DependencyCollector" Version="2.4.1" />
21+
<PackageReference Include="Microsoft.ApplicationInsights.Kubernetes" Version="1.0.0-beta1" />
2022
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
2123
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="4.1.0" />
2224
<PackageReference Include="Swashbuckle.AspNetCore" Version="1.0.0" />

src/Services/Basket/Basket.API/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public static IWebHost BuildWebHost(string[] args) =>
3434
builder.AddConsole();
3535
builder.AddDebug();
3636
})
37+
.UseApplicationInsights()
3738
.Build();
3839
}
3940
}

src/Services/Basket/Basket.API/Startup.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ public IServiceProvider ConfigureServices(IServiceCollection services)
6565

6666
services.Configure<BasketSettings>(Configuration);
6767

68+
if(Configuration.GetValue<string>("OrchestratorType").Equals("K8S"))
69+
{
70+
// Enable K8s telemetry initializer
71+
services.EnableKubernetes();
72+
}
73+
6874
//By connecting here we are making sure that our service
6975
//cannot start until redis is ready. This might slow down startup,
7076
//but given that there is a delay on resolving the ip address
@@ -203,8 +209,8 @@ private void ConfigureAuthService(IServiceCollection services)
203209
// prevent from mapping "sub" claim to nameidentifier.
204210
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
205211

206-
var identityUrl = Configuration.GetValue<string>("IdentityUrl");
207-
212+
var identityUrl = Configuration.GetValue<string>("IdentityUrl");
213+
208214
services.AddAuthentication(options =>
209215
{
210216
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;

src/Services/Catalog/Catalog.API/Catalog.API.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
<ItemGroup>
3737
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="4.1.0" />
3838
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.1.1" />
39+
<PackageReference Include="Microsoft.ApplicationInsights.DependencyCollector" Version="2.4.1" />
40+
<PackageReference Include="Microsoft.ApplicationInsights.Kubernetes" Version="1.0.0-beta1" />
3941
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
4042
<PackageReference Include="Swashbuckle.AspNetCore" Version="1.0.0" />
4143
<PackageReference Include="System.IO.Compression.ZipFile" Version="4.3.0" />

src/Services/Catalog/Catalog.API/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public static void Main(string[] args)
3232
public static IWebHost BuildWebHost(string[] args) =>
3333
WebHost.CreateDefaultBuilder(args)
3434
.UseStartup<Startup>()
35+
.UseApplicationInsights()
3536
.UseHealthChecks("/hc")
3637
.UseContentRoot(Directory.GetCurrentDirectory())
3738
.UseWebRoot("Pics")
@@ -44,8 +45,7 @@ public static IWebHost BuildWebHost(string[] args) =>
4445
builder.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
4546
builder.AddConsole();
4647
builder.AddDebug();
47-
})
48-
.UseApplicationInsights()
48+
})
4949
.Build();
5050
}
5151
}

src/Services/Catalog/Catalog.API/Startup.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
1414
using Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ;
1515
using Microsoft.eShopOnContainers.BuildingBlocks.EventBusServiceBus;
16-
using Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF;
1716
using Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF.Services;
1817
using Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure;
1918
using Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationEvents.EventHandling;
@@ -43,6 +42,12 @@ public IServiceProvider ConfigureServices(IServiceCollection services)
4342

4443
services.AddApplicationInsightsTelemetry(Configuration);
4544

45+
if (Configuration.GetValue<string>("OrchestratorType").Equals("K8S"))
46+
{
47+
// Enable K8s telemetry initializer
48+
services.EnableKubernetes();
49+
}
50+
4651
services.AddHealthChecks(checks =>
4752
{
4853
var minutes = 1;

0 commit comments

Comments
 (0)