-
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?
feat(accounting): allow flexible database selection #2645
Conversation
d055006 to
a4d6d4e
Compare
| <!-- ADDED: Suppress the security audit warning that is failing the build --> | ||
| <NoWarn>$(NoWarn);NU1903</NoWarn> |
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.
This is very bad practice to mute security errors. Especially in the demonstrating objects.
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.
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>| <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 comment
The 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.
| @@ -1,6 +1,3 @@ | |||
| // Copyright The OpenTelemetry Authors | |||
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.
Licenses are mandatory, please bring it back.
| using System; | ||
| using System.Linq; | ||
| using System.Threading.Tasks; |
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.
These are redundat
| using System; | |
| using System.Linq; | |
| using System.Threading.Tasks; |
| public Consumer(ILogger<Consumer> logger) | ||
| { | ||
| _logger = logger; | ||
| _dbType = Environment.GetEnvironmentVariable("DB_TYPE")?.ToLowerInvariant(); |
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 think that you should inject this value from the constructor. You have already parsed it by the Consumer.
Alternative approach is to make DBContext abstract, and create MySqlDBContext and NpgsqlDbContext.
|
|
||
| # 2. Add the MongoDB service | ||
| mongo: | ||
| image: mongo:7 |
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.
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.
Why not https://www.nuget.org/packages/MongoDB.EntityFrameworkCore?
EFCore is common for other databases.
|
Hello @luke6Lh43, thank you for your time in putting this together. (also thx @Kielek for the review!) We had some time ago the PR #2143 from @henrikrexed where he proposed using Dapr to control the DB switch. Your PR follows a totally different approach and it may be a bit tricky to handle that same behaviour on K8s deployments. |
|
would we have to update the OTel Collector receivers config:
@rogercoll I see there another opportunity to showcase the OTel Collector Receiver Creator :-) |
|
Thank you @Kielek for reviewing code changes! @julianocosta89 should I go ahead and implement what @Kielek has suggested? Or rather wait on your feedback if we want to move forward with this proposed change. Also, could you please clarify why you think there will be a problem to implement the same with Kubernetes? I believe there is lots of flexibility in Helm charts where we could adjust config based on parameter selected, kind of the same as I did with Docker. Thanks! |
I'd recommend waiting.
With Helm yes, but we also have the k8s manifests |
|
Hello @luke6Lh43 👋🏽 After discussing it in the SIG meeting we have decided to go with Dapr.
I'm not sure if you would like to take parts of what he has done, and adapt your PR, or something else, but we would still love to see your contributions on the Demo |
|
The dapr integration works fine for anything that is not using a database ( vallkey, Kafka) are 2 great way of using it. I have paused the work on the DAPR waiting for their core support on Database ( for the product-catalog) |
|
@henrikrexed do we get any database attributes with Dapr? If they do not produce any DB attributes, then that would be a no go |
@julianocosta89 Thank you so much for your feedback! I understand there’s a more effective approach to achieve the same results using Dapr. Based on your input, I’ll pause work on this PR for now. Hopefully, Dapr will add support for databases soon, and these capabilities can be integrated into the OpenTelemetry demo, allowing end users to choose their preferred database. Thanks again for your guidance! |
Thank you @luke6Lh43 for taking the time to work on this. Hopefully we can still see you around. |
|
This PR was marked stale due to lack of activity. It will be closed in 7 days. |
Changes
This PR introduces flexible database selection for the OpenTelemetry Demo, allowing users to easily switch between PostgreSQL (default), MySQL, and MongoDB for the database service where records from Kafka are saved (Accounting service).
Currently, OpenTelemetey demo is tightly coupled to PostgreSQL. With this change, users gain the flexibility to choose their preferred database by simply utilizing new Docker Compose override files.
Key changes include:
DB_TYPEEnvironment Variable: A new environment variable,DB_TYPE, has been introduced to control which database backend the services connect to.docker-compose-mysql.ymloverride file and necessary configuration to enable MySQL as a backend option.docker-compose-mongo.ymloverride file and necessary configuration to enable MongoDB as a backend option.To use PostgreSQL (default):
To use MySQL:
To use MongoDB:
Merge Requirements
For new features contributions, please make sure you have completed the following
essential items:
CHANGELOG.mdupdated to document new feature additionsFixes #2600