Skip to content

update mongo configuration template#838

Merged
lu-zhengda merged 1 commit intomainfrom
zhengda.lu/mongo
Feb 26, 2025
Merged

update mongo configuration template#838
lu-zhengda merged 1 commit intomainfrom
zhengda.lu/mongo

Conversation

@lu-zhengda
Copy link
Copy Markdown
Contributor

What does this PR do?

This PR updates mongo integration config template to be in sync with integrations-core.

Motivation

Additional Notes

Describe your test plan

@lu-zhengda lu-zhengda requested review from a team as code owners February 26, 2025 03:20
{
servers: [
{
'hosts' => ['localhost:27017'],
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Quality Violation

Suggested change
'hosts' => ['localhost:27017'],
'hosts' => %w[localhost:27017],
Consider using the %w syntax instead (...read more)

The rule "Prefer %w to the literal array syntax" is a Ruby style guideline that encourages the use of %w notation instead of the traditional array syntax when defining arrays of strings. This rule is part of the Ruby community's efforts to promote readability and simplicity in Ruby code.

This rule is important because it helps to keep the code concise and easy to read. The %w notation allows you to define an array of strings without having to use quotes and commas. This can make the code cleaner and easier to understand, especially when dealing with large arrays.

To follow this rule, replace the traditional array syntax with the %w notation. For example, instead of writing ['foo', 'bar', 'baz'], you should write %w[foo bar baz]. This will create the same array, but in a more readable and concise way. By following this rule, you can help to make your Ruby code cleaner and easier to understand.

View in Datadog  Leave us feedback  Documentation

'username' => 'user',
'password' => 'pass',
'dbm' => true,
'database_autodiscovery' => { 'enabled' => true },
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Quality Violation

Consider using symbols instead of string hash keys (...read more)

In Ruby, it is a best practice to use symbols instead of strings as hash keys. This rule emphasizes that it's more efficient and idiomatic to use symbols for this purpose. Symbols are immutable and unique, which makes them ideal for identifying things, whereas strings are mutable and can create multiple objects for the same sequence of characters.

The importance of this rule lies in the performance and memory usage of your Ruby application. Using symbols as hash keys reduces memory usage because they are stored in memory only once during a Ruby process. This can make a significant difference in the efficiency of your application, especially when dealing with large data sets.

To ensure you're following good coding practices, always use symbols for hash keys unless there's a specific reason to use a string. A simple refactoring from values = { 'foo' => 42, 'bar' => 99, 'baz' => 123 } to values = { foo: 42, bar: 99, baz: 123 } will make your code compliant with this rule. This not only improves your code's performance but also makes it more readable and consistent with Ruby's conventions.

View in Datadog  Leave us feedback  Documentation

@lu-zhengda lu-zhengda merged commit 9472fc7 into main Feb 26, 2025
@lu-zhengda lu-zhengda deleted the zhengda.lu/mongo branch February 26, 2025 22:13
jhatler pushed a commit to jhatler/puppet-datadog-agent that referenced this pull request Nov 21, 2025
Backport MongoDB integration fix from main branch to resolve broken
connection strings when using modern configuration format with hosts
array instead of legacy host/port parameters.

The current 3.x template generates malformed MongoDB URIs
(mongodb://user:pass@:/admin with missing host:port) when users
provide modern 'hosts' array parameters. This occurs because the
template expects old-style 'host' and 'port' keys but receives
'hosts' array from modern configurations, causing nil values in
the connection string.

Changes:
- Add dual-path template logic supporting both formats
- Modern configs with 'hosts' array use hosts format (works correctly)
- Legacy configs with 'host'/'port' use connection string (backward compatible)
- Add support for new MongoDB monitoring parameters:
  - dbm: Database Monitoring feature
  - database_autodiscovery: Auto-discovery of databases
  - reported_database_hostname: Custom hostname for metrics
- Update documentation to deprecate host/port in favor of hosts
- Add RSpec tests for modern hosts array format
- Update CHANGELOG for unreleased changes

Template changes:
- Check if server['hosts'] exists and has elements
- If yes: render modern hosts array format with fields
- If no: fall back to legacy connection string format
- Add dbm, database_autodiscovery, reported_database_hostname rendering

Documentation changes:
- Move hosts, dbm, database_autodiscovery, reported_database_hostname to top
- Mark host and port as deprecated with recommendation to use hosts
- Update examples to show modern hosts array format
- Add link to official Datadog MongoDB integration docs

Test changes:
- Add test context for hosts array configuration
- Verify hosts array renders correctly
- Verify all new parameters render correctly
- Maintain backward compatibility with existing tests

Tested:
- pdk validate: PASSED
- Full test suite: 4895 examples, 0 failures, 63 pending
- Syntax validation: PASSED

Refs: 9472fc7
Refs: DataDog#838
Signed-off-by: Jaremy Hatler <j.hatler@xsolla.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants