Skip to content

Commit 525202f

Browse files
authored
Add docker support (#6)
Add quick run section
1 parent bf03d1e commit 525202f

23 files changed

+522
-80
lines changed

.dockerignore

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
**/.classpath
2+
**/.dockerignore
3+
**/.env
4+
**/.git
5+
**/.gitignore
6+
**/.project
7+
**/.settings
8+
**/.toolstarget
9+
**/.vs
10+
**/.vscode
11+
**/*.*proj.user
12+
**/*.dbmdl
13+
**/*.jfm
14+
**/azds.yaml
15+
**/bin
16+
**/charts
17+
**/docker-compose*
18+
**/Dockerfile*
19+
**/node_modules
20+
**/npm-debug.log
21+
**/obj
22+
**/secrets.dev.yaml
23+
**/values.dev.yaml
24+
LICENSE
25+
README.md

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,4 +350,6 @@ MigrationBackup/
350350
.ionide/
351351

352352
# development json files
353-
appsettings.Development.json
353+
appsettings.Development.json
354+
355+
.env

DotNetObservabilitySample.sln

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
1-
21
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 15
4-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample.RabbitMQProcessor", "src\Sample.RabbitMQProcessor\Sample.RabbitMQProcessor.csproj", "{B2900141-0E8C-46EE-908E-F98218960804}"
2+
# Visual Studio Version 16
3+
VisualStudioVersion = 16.0.29613.14
4+
MinimumVisualStudioVersion = 10.0.40219.1
5+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sample.RabbitMQProcessor", "src\Sample.RabbitMQProcessor\Sample.RabbitMQProcessor.csproj", "{B2900141-0E8C-46EE-908E-F98218960804}"
56
EndProject
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample.Common", "src\Sample.Common\Sample.Common.csproj", "{39CCAC82-947E-4229-85C1-C34D3B569BE4}"
7+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sample.Common", "src\Sample.Common\Sample.Common.csproj", "{39CCAC82-947E-4229-85C1-C34D3B569BE4}"
78
EndProject
8-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample.TimeApi", "src\Sample.TimeApi\Sample.TimeApi.csproj", "{883EB697-F742-422B-ADC9-3A89C00B5424}"
9+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sample.TimeApi", "src\Sample.TimeApi\Sample.TimeApi.csproj", "{883EB697-F742-422B-ADC9-3A89C00B5424}"
910
EndProject
10-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample.MainApi", "src\Sample.MainApi\Sample.MainApi.csproj", "{4EA49E72-7529-4CFD-8942-0086BC0E43F4}"
11+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sample.MainApi", "src\Sample.MainApi\Sample.MainApi.csproj", "{4EA49E72-7529-4CFD-8942-0086BC0E43F4}"
12+
EndProject
13+
Project("{E53339B2-1760-4266-BCC7-CA923CBCF16C}") = "docker-compose", "docker-compose.dcproj", "{D9851614-526F-43C3-B9E2-F93B0F0E1448}"
1114
EndProject
1215
Global
1316
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1417
Debug|Any CPU = Debug|Any CPU
1518
Release|Any CPU = Release|Any CPU
1619
EndGlobalSection
1720
GlobalSection(ProjectConfigurationPlatforms) = postSolution
18-
{00932BD9-CCB8-40FE-A27C-4DE896BDD127}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
19-
{00932BD9-CCB8-40FE-A27C-4DE896BDD127}.Debug|Any CPU.Build.0 = Debug|Any CPU
20-
{00932BD9-CCB8-40FE-A27C-4DE896BDD127}.Release|Any CPU.ActiveCfg = Release|Any CPU
21-
{00932BD9-CCB8-40FE-A27C-4DE896BDD127}.Release|Any CPU.Build.0 = Release|Any CPU
2221
{B2900141-0E8C-46EE-908E-F98218960804}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
2322
{B2900141-0E8C-46EE-908E-F98218960804}.Debug|Any CPU.Build.0 = Debug|Any CPU
2423
{B2900141-0E8C-46EE-908E-F98218960804}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -35,8 +34,16 @@ Global
3534
{4EA49E72-7529-4CFD-8942-0086BC0E43F4}.Debug|Any CPU.Build.0 = Debug|Any CPU
3635
{4EA49E72-7529-4CFD-8942-0086BC0E43F4}.Release|Any CPU.ActiveCfg = Release|Any CPU
3736
{4EA49E72-7529-4CFD-8942-0086BC0E43F4}.Release|Any CPU.Build.0 = Release|Any CPU
37+
{D9851614-526F-43C3-B9E2-F93B0F0E1448}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
38+
{D9851614-526F-43C3-B9E2-F93B0F0E1448}.Debug|Any CPU.Build.0 = Debug|Any CPU
39+
{D9851614-526F-43C3-B9E2-F93B0F0E1448}.Release|Any CPU.ActiveCfg = Release|Any CPU
40+
{D9851614-526F-43C3-B9E2-F93B0F0E1448}.Release|Any CPU.Build.0 = Release|Any CPU
41+
EndGlobalSection
42+
GlobalSection(SolutionProperties) = preSolution
43+
HideSolutionNode = FALSE
3844
EndGlobalSection
39-
GlobalSection(NestedProjects) = preSolution
45+
GlobalSection(ExtensibilityGlobals) = postSolution
46+
SolutionGuid = {5170C652-61A9-4542-954E-246518C6C40B}
4047
EndGlobalSection
4148
GlobalSection(MonoDevelopProperties) = preSolution
4249
version = 0.2

README.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Implementing observability in .NET Core stack
22

3-
This document takes a look at current options to implement observability in .NET Core stack.
3+
This document takes a look at current options to implement observability in .NET Core stack. For a quick peek into the sample application check section [Quickly run sample application](#Quickly-run-sample-application)
44

55
**DISCLAIMER 1**: I am familiar with Azure Application Insights. I don't have the same experience with the OSS options out there, therefore the sample code covers only Jaeger and Prometheus (at least for now).
66

@@ -91,6 +91,35 @@ For project setup information please check the source code or SDK documentation.
9191

9292
Before continue reading, **please go through the 3 sample scenarios**.
9393

94+
## Quickly run sample application
95+
96+
To quickly see the application running using pre-built docker images and docker-compose follow the guideline below:
97+
98+
### Using OpenTelemetry
99+
100+
1. Open terminal under `ready-to-run\sample`
101+
1. Execute `docker-compose up`
102+
1. Generate load with `watch -n 2 curl --request GET http://localhost:5001/api/enqueue/WebSiteA`
103+
1. View traces in [Jaeger](http://localhost:16686/)
104+
1. View metrics by searching for "Enqueued_Item" in [Prometheus](http://localhost:9090)
105+
1. Build dashboards in [Grafana](http://localhost:3000/) (admin/password1)
106+
107+
### Using Application Insights SDK
108+
109+
1. Open terminal under `ready-to-run\sample`
110+
2. Add .env file with following content:
111+
112+
```env
113+
USE_APPLICATIONINSIGHTS=true
114+
USE_OPENTELEMETRY=false
115+
AI_INSTRUMENTATIONKEY=<ENTER-APPLICATION-INSIGHTS-INSTRUMENTATION-KEY>
116+
```
117+
118+
3. Execute `docker-compose up`
119+
4. Generate load with `watch -n 2 curl --request GET http://localhost:5001/api/enqueue/WebSiteA`
120+
5. View logs, traces and metrics in Azure Portal Application Insights
121+
122+
94123
## Conclusion
95124

96125
OpenTelemetry is positioning itself as a strong candidate as a standard API for tracing and metrics collection. That becomes even more important when building polyglot systems as OpenTelemetry SDK supports multiple languages using the same idiom (even though other vendors usually support multiple languages).

docker-compose.dcproj

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" Sdk="Microsoft.Docker.Sdk">
3+
<PropertyGroup Label="Globals">
4+
<ProjectVersion>2.1</ProjectVersion>
5+
<DockerTargetOS>Linux</DockerTargetOS>
6+
<ProjectGuid>d9851614-526f-43c3-b9e2-f93b0f0e1448</ProjectGuid>
7+
<DockerLaunchAction>LaunchBrowser</DockerLaunchAction>
8+
<DockerServiceUrl>{Scheme}://localhost:{ServicePort}/{Scheme}://{ServiceHost}:{ServicePort}/api/dbtime</DockerServiceUrl>
9+
<DockerServiceName>sample.mainapi</DockerServiceName>
10+
</PropertyGroup>
11+
<ItemGroup>
12+
<None Include="docker-compose.override.yml">
13+
<DependentUpon>docker-compose.yml</DependentUpon>
14+
</None>
15+
<None Include="docker-compose.yml" />
16+
<None Include=".dockerignore" />
17+
</ItemGroup>
18+
</Project>

docker-compose.override.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
version: '3.4'
2+
3+
services:
4+
sample.mainapi:
5+
environment:
6+
- ASPNETCORE_ENVIRONMENT=Development
7+
ports:
8+
- "5001:80"
9+
10+
sample.timeapi:
11+
environment:
12+
- ASPNETCORE_ENVIRONMENT=Development
13+
ports:
14+
- "5002:80"
15+

docker-compose.yml

Lines changed: 96 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,96 @@
1-
# docker-compose.yml
2-
version: '2'
3-
services:
4-
prometheus:
5-
image: prom/prometheus
6-
volumes:
7-
- ./prometheus.yml:/etc/prometheus/prometheus.yml
8-
command:
9-
- '--config.file=/etc/prometheus/prometheus.yml'
10-
ports:
11-
- 9090:9090
12-
grafana:
13-
image: grafana/grafana
14-
environment:
15-
- GF_SECURITY_ADMIN_PASSWORD=password1
16-
depends_on:
17-
- prometheus
18-
ports:
19-
- 3000:3000
1+
version: '3.4'
2+
3+
services:
4+
sample.mainapi:
5+
image: ${DOCKER_REGISTRY-}dotnetobservabilitysample-mainapi${TAG-}
6+
environment:
7+
- SampleApp__RabbitMQHostName=rabbitmq
8+
- SampleApp__TimeAPIUrl=http://sample.timeapi
9+
- OpenTelemetry__Prometheus__Url=http://sample.mainapi:9184/metrics/
10+
- OpenTelemetry__Jaeger__AgentHost=jaeger
11+
depends_on:
12+
- rabbitmq
13+
- sample.timeapi
14+
- prometheus
15+
- jaeger
16+
build:
17+
context: .
18+
dockerfile: src/Sample.MainApi/Dockerfile
19+
ports:
20+
- "5001:80"
21+
- "9184:9184"
22+
23+
sample.rabbitmqprocessor:
24+
image: ${DOCKER_REGISTRY-}dotnetobservabilitysample-rabbitmqprocessor${TAG-}
25+
environment:
26+
- SampleApp__RabbitMQHostName=rabbitmq
27+
- SampleApp__TimeAPIUrl=http://sample.timeapi
28+
- OpenTelemetry__Jaeger__AgentHost=jaeger
29+
depends_on:
30+
- rabbitmq
31+
- sample.timeapi
32+
- prometheus
33+
- jaeger
34+
build:
35+
context: .
36+
dockerfile: src/Sample.RabbitMQProcessor/Dockerfile
37+
38+
sample.timeapi:
39+
image: ${DOCKER_REGISTRY-}dotnetobservabilitysample-timeapi${TAG-}
40+
depends_on:
41+
- sqlserver
42+
- prometheus
43+
- jaeger
44+
environment:
45+
- SampleApp__RabbitMQHostName=rabbitmq
46+
- SqlConnectionString=server=sqlserver;user id=sa;password=Pass@Word1;
47+
- OpenTelemetry__Jaeger__AgentHost=jaeger
48+
build:
49+
context: .
50+
dockerfile: src/Sample.TimeApi/Dockerfile
51+
ports:
52+
- "5002:80"
53+
54+
rabbitmq:
55+
image: rabbitmq:3-management
56+
ports:
57+
- 15672
58+
- 5672
59+
60+
sqlserver:
61+
image: mcr.microsoft.com/mssql/server:2019-GA-ubuntu-16.04
62+
environment:
63+
- ACCEPT_EULA=Y
64+
- SA_PASSWORD=Pass@Word1
65+
ports:
66+
- 1433
67+
68+
jaeger:
69+
image: jaegertracing/all-in-one
70+
environment:
71+
- COLLECTOR_ZIPKIN_HTTP_PORT=19411
72+
ports:
73+
- 5775:5775/udp
74+
- 6831:6831/udp
75+
- 6832:6832/udp
76+
- 5778:5778
77+
- 16686:16686
78+
- 14268:14268
79+
- 19411:19411
80+
81+
prometheus:
82+
image: prom/prometheus
83+
volumes:
84+
- ./prometheus.yml:/etc/prometheus/prometheus.yml
85+
command:
86+
- '--config.file=/etc/prometheus/prometheus.yml'
87+
ports:
88+
- 9090:9090
89+
grafana:
90+
image: grafana/grafana
91+
environment:
92+
- GF_SECURITY_ADMIN_PASSWORD=password1
93+
depends_on:
94+
- prometheus
95+
ports:
96+
- 3000:3000

prometheus.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ scrape_configs:
1414
- job_name: 'main-api'
1515
scrape_interval: 5s
1616
static_configs:
17-
- targets: ['host.docker.internal:9184']
17+
- targets: ['sample.mainapi:9184']
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# docker-compose.yml
2+
version: '2'
3+
services:
4+
prometheus:
5+
image: prom/prometheus
6+
volumes:
7+
- ./prometheus.yml:/etc/prometheus/prometheus.yml
8+
command:
9+
- '--config.file=/etc/prometheus/prometheus.yml'
10+
ports:
11+
- 9090:9090
12+
grafana:
13+
image: grafana/grafana
14+
environment:
15+
- GF_SECURITY_ADMIN_PASSWORD=password1
16+
depends_on:
17+
- prometheus
18+
ports:
19+
- 3000:3000
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# prometheus.yml
2+
global:
3+
scrape_interval: 5s
4+
external_labels:
5+
monitor: 'dotnet-observability-sample'
6+
7+
8+
scrape_configs:
9+
- job_name: 'prometheus'
10+
scrape_interval: 5s
11+
static_configs:
12+
- targets: ['localhost:9090']
13+
14+
- job_name: 'main-api'
15+
scrape_interval: 5s
16+
static_configs:
17+
- targets: ['host.docker.internal:9184']

0 commit comments

Comments
 (0)