Skip to content

Commit

Permalink
feat: renew ChatApp docker for MagicOnionv4
Browse files Browse the repository at this point in the history
  • Loading branch information
guitarrapc committed Nov 17, 2020
1 parent 013ae7d commit 315e379
Show file tree
Hide file tree
Showing 20 changed files with 125 additions and 79 deletions.
32 changes: 32 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
.git/
.vs/
bin/
obj/
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.gitattributes
**/.vs
**/.vscode
**/*.*proj.user
**/azds.yaml
**/charts
**/bin
**/obj
**/Dockerfile
**/Dockerfile.develop
**/docker-compose.yml
**/docker-compose.*.yml
**/*.dbmdl
**/*.jfm
**/secrets.dev.yaml
**/values.dev.yaml
**/.toolstarget

.github/
docs/
samples/ChatApp/ChatApp.Unity/Temp/
samples/ChatApp/ChatApp.Unity/Library/
sandbox/
tests/
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,4 @@ nuget/*.unitypackage
.idea/
src/MagicOnion.Client.Unity/Packages/manifest.json

packages
packages
8 changes: 6 additions & 2 deletions samples/ChatApp.Telemetry/.dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,9 @@ obj/
**/values.dev.yaml
**/.toolstarget

ChatApp.Unity/Temp/
ChatApp.Unity/Library/
docs/
samples/ChatApp/
samples/ChatApp.Telemetry/ChatApp.Unity/Temp/
samples/ChatApp.Telemetry/ChatApp.Unity/Library/
sandbox/
tests/
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
<LangVersion>8.0</LangVersion>
</PropertyGroup>

Expand Down
5 changes: 2 additions & 3 deletions samples/ChatApp.Telemetry/ChatApp.Server/ChatHub.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
using ChatApp.Shared.Hubs;
using ChatApp.Shared.MessagePackObjects;
using MagicOnion.Server;
using MagicOnion.Server.Hubs;
using MagicOnion.Server.OpenTelemetry;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading.Tasks;
using MagicOnion.Server.OpenTelemetry;

namespace ChatApp.Server
{
Expand All @@ -22,7 +21,7 @@ public class ChatHub : StreamingHubBase<IChatHub, IChatHubReceiver>, IChatHub
private readonly ActivitySource mysqlActivity;
private readonly ActivitySource redisActivity;

public ChatHub(MagicOnionActivitySources magiconionActivity, BackendActivitySources backendActivity, MagicOnionOpenTelemetryOptions options)
public ChatHub(MagicOnionActivitySources magiconionActivity, BackendActivitySources backendActivity)
{
this.magiconionActivity = magiconionActivity.Current;
this.mysqlActivity = backendActivity.Get("mysql");
Expand Down
8 changes: 4 additions & 4 deletions samples/ChatApp.Telemetry/ChatApp.Server/ChatService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ namespace ChatApp.Server
{
public class ChatService : ServiceBase<IChatService>, IChatService
{
private ActivitySource activitySource;
private ActivitySource mysqlActivitySource;
private ILogger logger;

public ChatService(ILogger<ChatService> logger, ActivitySource activitySource)
public ChatService(ILogger<ChatService> logger, BackendActivitySources backendActivity)
{
this.activitySource = activitySource;
this.mysqlActivitySource = backendActivity.Get("mysql");
this.logger = logger;
}

public async UnaryResult<Nil> GenerateException(string message)
{
var ex = new System.NotImplementedException();
// dummy external operation.
using (var activity = activitySource.StartActivity("db:errors/insert", ActivityKind.Internal))
using (var activity = mysqlActivitySource.StartActivity("db:errors/insert", ActivityKind.Internal))
{
// this is sample. use orm or any safe way.
activity.SetTag("table", "errors");
Expand Down
4 changes: 2 additions & 2 deletions samples/ChatApp.Telemetry/ChatApp.Server/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
FROM mcr.microsoft.com/dotnet/core/runtime:3.1 AS base
FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
EXPOSE 12345
WORKDIR /app

FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /src
COPY ["ChatApp.Server/ChatApp.Server.csproj", "ChatApp.Server/"]
COPY ["ChatApp.Shared/ChatApp.Shared.csproj", "ChatApp.Shared/"]
Expand Down
25 changes: 25 additions & 0 deletions samples/ChatApp.Telemetry/ChatApp.Server/Dockerfile.full
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
EXPOSE 12345
WORKDIR /app

FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /src
COPY ["samples/ChatApp.Telemetry/ChatApp.Server/ChatApp.Server.csproj", "samples/ChatApp.Telemetry/ChatApp.Server/"]
COPY ["samples/ChatApp.Telemetry/ChatApp.Shared/ChatApp.Shared.csproj", "samples/ChatApp.Telemetry/ChatApp.Shared/"]
COPY ["src/MagicOnion/MagicOnion.csproj", "src/MagicOnion/"]
COPY ["src/MagicOnion.Abstractions/MagicOnion.Abstractions.csproj", "src/MagicOnion.Abstractions/"]
COPY ["src/MagicOnion.Server/MagicOnion.Server.csproj", "src/MagicOnion.Server/"]
COPY ["src/MagicOnion.Server.OpenTelemetry/MagicOnion.Server.OpenTelemetry.csproj", "src/MagicOnion.Server.OpenTelemetry/"]
COPY ["src/MagicOnion.Shared/MagicOnion.Shared.csproj", "src/MagicOnion.Shared/"]
RUN dotnet restore "samples/ChatApp.Telemetry/ChatApp.Server/ChatApp.Server.csproj"
COPY . .
WORKDIR "/src/samples/ChatApp.Telemetry/ChatApp.Server"
RUN dotnet build "ChatApp.Server.csproj" -c Debug -o /app

FROM build AS publish
RUN dotnet publish "ChatApp.Server.csproj" -c Debug -o /app

FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "ChatApp.Server.dll"]
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,21 @@ sealed class PrometheusExporterMetricsService : IHostedService
private readonly PrometheusExporterMetricsHttpServerCustom server;
private readonly ILogger<PrometheusExporterMetricsService> logger;
private readonly MagicOnionOpenTelemetryOptions options;
private readonly string metricsExporterHostingEndpoint;

public PrometheusExporterMetricsService(MetricExporter exporter, MagicOnionOpenTelemetryOptions options, IConfiguration configuration, ILogger<PrometheusExporterMetricsService> logger)
{
this.logger = logger;
this.options = options;
if (exporter is PrometheusExporter prometheusExporter)
{
metricsExporterHostingEndpoint = options.MetricsExporterHostingEndpoint;
server = new PrometheusExporterMetricsHttpServerCustom(prometheusExporter, metricsExporterHostingEndpoint);
server = new PrometheusExporterMetricsHttpServerCustom(prometheusExporter, options.MetricsExporterHostingEndpoint);
}
}
public Task StartAsync(CancellationToken cancellationToken)
{
if (server != null)
{
logger.LogInformation($"PrometheusExporter MetricsServer is listening on: {metricsExporterHostingEndpoint}, sending to {options.MetricsExporterEndpoint}");
logger.LogInformation($"PrometheusExporter MetricsServer is listening on: {options.MetricsExporterHostingEndpoint}, sending to {options.MetricsExporterEndpoint}");
server.Start();
}
return Task.CompletedTask;
Expand Down
1 change: 1 addition & 0 deletions samples/ChatApp.Telemetry/ChatApp.Server/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public void ConfigureServices(IServiceCollection services)
.Build();
services.AddSingleton(new BackendActivitySources(new[] { new ActivitySource("mysql"), new ActivitySource("redis") }));

// host Prometheus Metrics Server
services.AddHostedService<PrometheusExporterMetricsService>();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,6 @@
"MagicOnion": {
"Service": {
"IsReturnExceptionStackTraceInErrorDetail": true
},
"ServerPorts": [
{
"Host": "localhost",
"Port": 12345,
"UseInsecureConnection": true
}
],
"OpenTelemetry": {
"ServiceName": "ChatApp.Server",
"MetricsExporterEndpoint": "http://127.0.0.1:9184/metrics/",
"TracerExporterEndpoint": "http://127.0.0.1:9411/api/v2/spans",
"PrometheusMetricsHostingEndpoint": "http://127.0.0.1:9184/metrics/"
}
}
}
7 changes: 0 additions & 7 deletions samples/ChatApp.Telemetry/ChatApp.Server/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
{
"MagicOnion": {
"ServerPorts": [
{
"Host": "0.0.0.0",
"Port": 12345,
"UseInsecureConnection": true
}
],
"OpenTelemetry": {
"MagicOnionActivityName": "chatapp.server",
"MetricsExporterEndpoint": "http://127.0.0.1:9184/metrics/",
Expand Down
28 changes: 17 additions & 11 deletions samples/ChatApp.Telemetry/docker-compose.telemetry.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: "3"

services:
prometheus:
image: prom/prometheus:v2.11.1
image: prom/prometheus:v2.22.2
volumes:
# persistent prometheus database
- ./docker/prometheus/data/:/prometheus
Expand All @@ -11,7 +11,15 @@ services:
ports:
- "9090:9090"

# # if you want monitor linux host machine, install node-exporter or use it through container.
alertmanager:
image: prom/alertmanager:v0.21.0
volumes:
- ./docker/alertmanager/config.yml:/etc/alertmanager/config.yml
command: "--config.file=/etc/alertmanager/config.yml"
ports:
- 9093:9093

# # if you want monitor linux host machine, install node-exporter or use container.
# # settings detail: https://qiita.com/kanga/items/21acb042237f8a27f437
# node-exporter:
# image: prom/node-exporter:latest
Expand Down Expand Up @@ -45,15 +53,13 @@ services:
ports:
- 3000:3000

alertmanager:
image: prom/alertmanager
volumes:
- ./docker/alertmanager/config.yml:/etc/alertmanager/config.yml
command: "--config.file=/etc/alertmanager/config.yml"
ports:
- 9093:9093

zipkin:
image: openzipkin/zipkin
image: openzipkin/zipkin:2.22
ports:
- 9411:9411

jaeger:
image: jaegertracing/all-in-one:1.20
ports:
- 6831:6831/udp # client post
- 16686:16686 # web
11 changes: 6 additions & 5 deletions samples/ChatApp.Telemetry/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ version: "3"

services:
magiconion:
image: cysharp/magiconion_sample_chatapp_telemetry:3.0.13
image: cysharp/magiconion_sample_chatapp_telemetry:4.0.1-0.8.0.beta1
ports:
- 12345:12345
- 5000:80
- 9184:9184
environment:
- DOTNET_ENVIRONMENT=Development
- MagicOnion__ServerPorts__0__Host=0.0.0.0
- MagicOnion__OpenTelemetry__MetricsExporterEndpoint=http://127.0.0.1:9184/metrics/
- MagicOnion__OpenTelemetry__TracerExporterEndpoint=http://zipkin:9411/api/v2/spans
- MagicOnion__OpenTelemetry__PrometheusMetricsHostingEndpoint=http://+:9184/metrics/
- MagicOnion__OpenTelemetry__MetricsExporterHostingEndpoint=http://+:9184/metrics/
- UseExporter=jaeger
- Jaeger__Host=jaeger
- Zipkin__Endpoint=http://zipkin:9411/api/v2/spans
2 changes: 1 addition & 1 deletion samples/ChatApp.Telemetry/docker/grafana/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
FROM grafana/grafana:latest-ubuntu
FROM grafana/grafana:7.3.2-ubuntu
COPY ["./docker/grafana/download_dashboards.sh", "/etc/grafana/download_dashboards.sh"]
RUN mkdir -p /var/tmp/grafana/dashboards/default && /bin/sh /etc/grafana/download_dashboards.sh
6 changes: 3 additions & 3 deletions samples/ChatApp.Telemetry/docker_push.bat
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
:: cysharp/magiconion_sample_chatapp_telemetry
docker-compose -f docker-compose.yaml build magiconion
docker build -t chatapp_magiconion:latest -f ChatApp.Server/Dockerfile .
docker tag chatapp_magiconion:latest cysharp/magiconion_sample_chatapp_telemetry:latest
docker tag chatapp_magiconion:latest cysharp/magiconion_sample_chatapp_telemetry:3.0.13
docker tag chatapp_magiconion:latest cysharp/magiconion_sample_chatapp_telemetry:4.0.1-0.8.0.beta1
docker push cysharp/magiconion_sample_chatapp_telemetry:latest
docker push cysharp/magiconion_sample_chatapp_telemetry:3.0.13
docker push cysharp/magiconion_sample_chatapp_telemetry:4.0.1-0.8.0.beta1
6 changes: 6 additions & 0 deletions samples/ChatApp.Telemetry/docker_push.full.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
:: cysharp/magiconion_sample_chatapp_telemetry
docker build -t chatapp_magiconion:latest -f samples/ChatApp.Telemetry/ChatApp.Server/Dockerfile.full .
docker tag chatapp_magiconion:latest cysharp/magiconion_sample_chatapp_telemetry:latest
docker tag chatapp_magiconion:latest cysharp/magiconion_sample_chatapp_telemetry:4.0.1-0.8.0.beta1
docker push cysharp/magiconion_sample_chatapp_telemetry:latest
docker push cysharp/magiconion_sample_chatapp_telemetry:4.0.1-0.8.0.beta1
2 changes: 1 addition & 1 deletion samples/ChatApp.Telemetry/k8s/app/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ spec:
spec:
containers:
- name: chatapp
image: cysharp/magiconion_sample_chatapp_telemetry:3.0.13
image: cysharp/magiconion_sample_chatapp_telemetry:4.0.1-0.8.0.beta1
ports:
- containerPort: 12345
name: magiconion
Expand Down
9 changes: 1 addition & 8 deletions samples/ChatApp/ChatApp.Server/appsettings.Development.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@
"MagicOnion": {
"Service": {
"IsReturnExceptionStackTraceInErrorDetail": true
},
"ServerPorts": [
{
"Host": "localhost",
"Port": 12345,
"UseInsecureConnection": true
}
]
}
}
}
27 changes: 14 additions & 13 deletions samples/ChatApp/ChatApp.Server/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
{
"MagicOnion": {
"ServerPorts": [
{
"Host": "0.0.0.0",
"Port": 12345,
"UseInsecureConnection": false,
"ServerCredentials": [
{
"CertificatePath": "./server.crt",
"KeyPath": "./server.key"
}
]
"Kestrel": {
"Endpoints": {
"Grpc": {
"Url": "http://localhost:5000",
"Protocols": "Http2"
},
"Https": {
"Url": "https://localhost:5001",
"Protocols": "Http1AndHttp2"
},
"Http": {
"Url": "http://localhost:5002",
"Protocols": "Http1"
}
]
}
},
"Logging": {
"LogLevel": {
Expand Down

0 comments on commit 315e379

Please sign in to comment.