-
Notifications
You must be signed in to change notification settings - Fork 5k
feat(accounting): allow flexible database selection #2645
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| # docker-compose-mongo.yml | ||
| # Use: docker compose -f docker-compose.yml -f docker-compose-mongo.yml up | ||
|
|
||
| x-default-logging: &logging | ||
| driver: "json-file" | ||
| options: | ||
| max-size: "5m" | ||
| max-file: "2" | ||
| tag: "{{.Name}}" | ||
|
|
||
| services: | ||
| # 1. Remove the Postgres service | ||
| postgresql: !reset null | ||
|
|
||
| # 2. Add the MongoDB service | ||
| mongo: | ||
| image: mongo:7 | ||
| container_name: mongo | ||
| restart: unless-stopped | ||
| environment: | ||
| MONGO_INITDB_DATABASE: otel | ||
| MONGO_INITDB_ROOT_USERNAME: otelu | ||
| MONGO_INITDB_ROOT_PASSWORD: otelp | ||
| OTEL_DOTNET_AUTO_INSTRUMENTATION_MONGODB_ENABLED: true | ||
| ports: | ||
| - "27017:27017" | ||
| healthcheck: | ||
| test: ["CMD", "mongosh", "--eval", "db.adminCommand('ping')"] | ||
| interval: 10s | ||
| timeout: 5s | ||
| retries: 5 | ||
| logging: *logging | ||
| networks: | ||
| - default | ||
|
|
||
| # 3. Configure 'accounting' service for MongoDB | ||
| accounting: | ||
| environment: | ||
| - DB_TYPE=mongo | ||
| - DB_CONNECTION_STRING=mongodb://otelu:otelp@mongo:27017/otel?authSource=admin | ||
| depends_on: | ||
| postgresql: !reset [] | ||
| otel-collector: | ||
| condition: service_started | ||
| kafka: | ||
| condition: service_healthy | ||
| mongo: | ||
| condition: service_healthy | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| # This is a Docker Compose override file to switch the demo from PostgreSQL to MySQL. | ||
| # To use it, run: | ||
| # docker compose -f docker-compose.yml -f docker-compose-mysql.yml up | ||
|
|
||
| # Use the same default logging as the base file | ||
| x-default-logging: &logging | ||
| driver: "json-file" | ||
| options: | ||
| max-size: "5m" | ||
| max-file: "2" | ||
| tag: "{{.Name}}" | ||
|
|
||
| services: | ||
| # 1. Remove the Postgres service defined in the base file. | ||
| # The `!reset null` syntax completely removes the service. | ||
| postgresql: !reset null | ||
|
|
||
| # 2. Add the MySQL service. | ||
| mysql: | ||
| image: mysql:8 | ||
| # The platform is important for users on ARM-based machines (e.g., Apple M1/M2). | ||
| # For x86/amd64 machines, you can remove this line. | ||
| platform: linux/arm64 | ||
| container_name: mysql | ||
| restart: unless-stopped | ||
| environment: | ||
| MYSQL_ROOT_PASSWORD: otelp | ||
| MYSQL_DATABASE: otel | ||
| MYSQL_USER: otelu | ||
| MYSQL_PASSWORD: otelp | ||
| ports: | ||
| - "3306:3306" | ||
| # A healthcheck ensures other services only start after MySQL is ready. | ||
| healthcheck: | ||
| test: ["CMD", "mysqladmin", "ping", "-h", "localhost"] | ||
| interval: 10s | ||
| timeout: 5s | ||
| retries: 5 | ||
| logging: *logging | ||
| networks: | ||
| - default | ||
|
|
||
| # 3. Override the 'accounting' service to use MySQL. | ||
| accounting: | ||
| environment: | ||
| # Set the DB_TYPE to trigger the MySQL logic in your code. | ||
| - DB_TYPE=mysql | ||
| # IMPORTANT: Use the correct key-value pair format for the Pomelo driver. | ||
| - DB_CONNECTION_STRING=Server=mysql;Port=3306;Database=otel;User=otelu;Password=otelp; | ||
| depends_on: | ||
| postgresql: !reset [] | ||
| otel-collector: | ||
| condition: service_started | ||
| kafka: | ||
| condition: service_healthy | ||
| # Add a dependency on the new mysql service and wait for it to be healthy. | ||
| mysql: | ||
| condition: service_healthy |
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. have checkout locally your code. Your goal should be to avoid downgrades (especially in AutoInstrumentation) and utilize secure versions of packages Please consider following versions as the goal. It is compiling, but I didn't check if it gives expected results. <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Confluent.Kafka" Version="2.12.0" />
<PackageReference Include="EFCore.NamingConventions" Version="9.0.0" />
<PackageReference Include="Google.Protobuf" Version="3.32.1" />
<PackageReference Include="Grpc.Tools" Version="2.68.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.9" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.22.1" />
<PackageReference Include="MongoDB.Driver" Version="3.5.0" />
<PackageReference Include="MongoDB.Driver.Core.Extensions.DiagnosticSources" Version="2.1.0" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.4" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="9.0.0" />
<PackageReference Include="OpenTelemetry.AutoInstrumentation" Version="1.12.0" />
</ItemGroup>
<ItemGroup>
<!-- GrpcServices is 'none' so that we do not need to depend on the grpc nuget package, and we only need protobuf support. -->
<Protobuf Include="src/protos/demo.proto" GrpcServices="none" />
</ItemGroup>
<ItemGroup>
<Folder Include="src\protos\" />
</ItemGroup>
</Project> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,34 +1,39 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>net8.0</TargetFramework> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS> | ||
| </PropertyGroup> | ||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>net8.0</TargetFramework> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS> | ||
| <!-- ADDED: Suppress the security audit warning that is failing the build --> | ||
| <NoWarn>$(NoWarn);NU1903</NoWarn> | ||
|
Comment on lines
+9
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is very bad practice to mute security errors. Especially in the demonstrating objects. |
||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Confluent.Kafka" Version="2.11.0" /> | ||
| <PackageReference Include="EFCore.NamingConventions" Version="9.0.0" /> | ||
| <PackageReference Include="Google.Protobuf" Version="3.31.1" /> | ||
| <PackageReference Include="Grpc.Tools" Version="2.68.1"> | ||
| <PrivateAssets>all</PrivateAssets> | ||
| <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
| </PackageReference> | ||
| <PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.7" /> | ||
| <PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.22.1" /> | ||
| <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.4" /> | ||
| <PackageReference Include="OpenTelemetry.AutoInstrumentation" Version="1.12.0" /> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <PackageReference Include="Confluent.Kafka" Version="2.11.0" /> | ||
| <PackageReference Include="EFCore.NamingConventions" Version="8.0.3" /> | ||
| <PackageReference Include="Google.Protobuf" Version="3.31.1" /> | ||
| <PackageReference Include="Grpc.Tools" Version="2.68.1"> | ||
| <PrivateAssets>all</PrivateAssets> | ||
| <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
| </PackageReference> | ||
| <PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" /> | ||
| <PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.22.1" /> | ||
| <PackageReference Include="MongoDB.Driver" Version="3.0.0" /> | ||
| <PackageReference Include="MongoDB.Driver.Core.Extensions.DiagnosticSources" Version="2.1.0" /> | ||
| <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.4" /> | ||
| <PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="8.0.2" /> | ||
| <PackageReference Include="OpenTelemetry.AutoInstrumentation" Version="1.9.0" /> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the second change which is stopper to me. Demo is designed in this way, that is should work with the latest version of AutoInstrumentaiton. In case of any issues, please let me know what is wrong here. |
||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <!-- GrpcServices is 'none' so that we do not need to depend on the grpc nuget package, and we only need protobuf support. --> | ||
| <Protobuf Include="src\protos\demo.proto" GrpcServices="none" /> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <!-- GrpcServices is 'none' so that we do not need to depend on the grpc nuget package, and we only need protobuf support. --> | ||
| <Protobuf Include="src/protos/demo.proto" GrpcServices="none" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Folder Include="src\protos\" /> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <Folder Include="src\protos\" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> | ||
| </Project> | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would consider pinning it by the SHA for security reasons, but it should be probably done across the repository. Here it can stay as is.