Skip to content
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

"not a valid value for readpreferencetags" on mongo integration #17942

Open
ewertonhm opened this issue Jun 27, 2024 · 2 comments
Open

"not a valid value for readpreferencetags" on mongo integration #17942

ewertonhm opened this issue Jun 27, 2024 · 2 comments

Comments

@ewertonhm
Copy link
Contributor

ewertonhm commented Jun 27, 2024

Note: If you have a feature request, you should contact support so the request can be properly tracked.

Output of the info page

  Check Initialization Errors
  ===========================

      mongo (6.2.0)
      -------------

      instance 0:

        could not invoke 'mongo' python check constructor. New constructor API returned:
Traceback (most recent call last):
  File "C:\Program Files\Datadog\Datadog Agent\embedded3\Lib\site-packages\datadog_checks\mongo\config.py", line 116, in _get_clean_server_name
    return parse_mongo_uri(server, sanitize_username=bool(self.tls_params))[4]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Datadog\Datadog Agent\embedded3\Lib\site-packages\datadog_checks\mongo\utils.py", line 47, in parse_mongo_uri
    parsed = pymongo.uri_parser.parse_uri(server)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Datadog\Datadog Agent\embedded3\Lib\site-packages\pymongo\uri_parser.py", line 529, in parse_uri
    options.update(split_options(opts, validate, warn, normalize))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Datadog\Datadog Agent\embedded3\Lib\site-packages\pymongo\uri_parser.py", line 363, in split_options
    options = cast(_CaseInsensitiveDictionary, validate_options(options, warn))
                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Datadog\Datadog Agent\embedded3\Lib\site-packages\pymongo\uri_parser.py", line 321, in validate_options
    return get_validated_options(opts, warn)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Datadog\Datadog Agent\embedded3\Lib\site-packages\pymongo\common.py", line 860, in get_validated_options
    value = validator(opt, value)  # noqa: PLW2901
            ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Datadog\Datadog Agent\embedded3\Lib\site-packages\pymongo\common.py", line 413, in validate_read_preference_tags
    raise ValueError(f"{tag_set!r} not a valid value for {name}") from None
ValueError: '%5B%7B%27nodeType%27%3A+%27ANALYTICS%27%7D%5D' not a valid value for readpreferencetags

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files\Datadog\Datadog Agent\embedded3\Lib\site-packages\datadog_checks\mongo\mongo.py", line 65, in __init__
    self._config = MongoConfig(self.instance, self.log)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Datadog\Datadog Agent\embedded3\Lib\site-packages\datadog_checks\mongo\config.py", line 71, in __init__
    self.clean_server_name = self._get_clean_server_name()
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Datadog\Datadog Agent\embedded3\Lib\site-packages\datadog_checks\mongo\config.py", line 118, in _get_clean_server_name
    raise ConfigurationError(
datadog_checks.base.errors.ConfigurationError: Could not build a mongo uri with the given hosts: ['estrelabet.nkw6f.mongodb.net:27017']. Error: ValueError("'%5B%7B%27nodeType%27%3A+%27ANALYTICS%27%7D%5D' not a valid value for readpreferencetags")
Deprecated constructor API returned:
MongoDb.__init__() got an unexpected keyword argument 'agentConfig'
  Config Errors
  ==============
    process
    -------
      Configuration file contains no valid instances
  Loading Errors
  ==============
    mongo
    -----
      Core Check Loader:
        Check mongo not found in Catalog

      JMX Check Loader:
        check is not a jmx check, or unable to determine if it's so

      Python Check Loader:
        could not configure check instance for python check mongo: could not invoke 'mongo' python check constructor. New constructor API returned:
Traceback (most recent call last):
  File "C:\Program Files\Datadog\Datadog Agent\embedded3\Lib\site-packages\datadog_checks\mongo\config.py", line 116, in _get_clean_server_name
    return parse_mongo_uri(server, sanitize_username=bool(self.tls_params))[4]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Datadog\Datadog Agent\embedded3\Lib\site-packages\datadog_checks\mongo\utils.py", line 47, in parse_mongo_uri
    parsed = pymongo.uri_parser.parse_uri(server)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Datadog\Datadog Agent\embedded3\Lib\site-packages\pymongo\uri_parser.py", line 529, in parse_uri
    options.update(split_options(opts, validate, warn, normalize))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Datadog\Datadog Agent\embedded3\Lib\site-packages\pymongo\uri_parser.py", line 363, in split_options
    options = cast(_CaseInsensitiveDictionary, validate_options(options, warn))
                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Datadog\Datadog Agent\embedded3\Lib\site-packages\pymongo\uri_parser.py", line 321, in validate_options
    return get_validated_options(opts, warn)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Datadog\Datadog Agent\embedded3\Lib\site-packages\pymongo\common.py", line 860, in get_validated_options
    value = validator(opt, value)  # noqa: PLW2901
            ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Datadog\Datadog Agent\embedded3\Lib\site-packages\pymongo\common.py", line 413, in validate_read_preference_tags
    raise ValueError(f"{tag_set!r} not a valid value for {name}") from None
ValueError: '%5B%7B%27nodeType%27%3A+%27ANALYTICS%27%7D%5D' not a valid value for readpreferencetags

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files\Datadog\Datadog Agent\embedded3\Lib\site-packages\datadog_checks\mongo\mongo.py", line 65, in __init__
    self._config = MongoConfig(self.instance, self.log)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Datadog\Datadog Agent\embedded3\Lib\site-packages\datadog_checks\mongo\config.py", line 71, in __init__
    self.clean_server_name = self._get_clean_server_name()
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Datadog\Datadog Agent\embedded3\Lib\site-packages\datadog_checks\mongo\config.py", line 118, in _get_clean_server_name
    raise ConfigurationError(
datadog_checks.base.errors.ConfigurationError: Could not build a mongo uri with the given hosts: ['estrelabet.nkw6f.mongodb.net:27017']. Error: ValueError("'%5B%7B%27nodeType%27%3A+%27ANALYTICS%27%7D%5D' not a valid value for readpreferencetags")
Deprecated constructor API returned:
MongoDb.__init__() got an unexpected keyword argument 'agentConfig'

Additional environment details (Operating System, Cloud provider, etc):

Steps to reproduce the issue:

  1. Setup mongo integration with the following conf.yaml:
instances:
  - hosts: 
    - <host:port>
      username: username
      password: password
      dbnames:
        - database
      options:
        retryWrites: 'true'
        readPreference: secondary
        readPreferenceTags:
          - nodeType: ANALYTICS
        w: majority

alto tryed with

        readPreferenceTags:
          - "nodeType:ANALYTICS"

and also with:

        readPreferenceTags: "nodeType: ANALYTICS"

they all gave the same result, "not a valid value for readpreferencetags"

Describe the results you received:
not a valid value for readpreferencetags

@ewertonhm ewertonhm changed the title not possible to pass read_preference_tags on mongo integration "not a valid value for readpreferencetags" on mongo integration Jun 27, 2024
@ewertonhm
Copy link
Contributor Author

Maybe am I not doing the correcly sintax in my conf.yaml, but there is no documentation on this topic, if its not a problem on the integration, we should at least fix the documentation about it.

@lu-zhengda
Copy link
Contributor

Hi @ewertonhm, we recommend directly connecting to each database host in your MongoDB cluster.

For example, if your MongoDB Atlas cluster has a 3-node replica set and 1 analytics node, you can configure four separate MongoDB integration instances in the conf.yaml, each targeting a specific host. Here’s a sample conf.yaml setup:

instances:
  - hosts: 
    - my-cluster-shard-00-00.xxxxx.mongodb.net:27017  # replica set node 1
    username: username
    password: password
    dbnames:
      - database
    options:
      authSource: admin
    tls: true
  - hosts: 
    - my-cluster-shard-00-01.xxxxx.mongodb.net:27017 # replica set node 2
    username: username
    password: password
    dbnames:
      - database
    options:
      authSource: admin
    tls: true
  - hosts: 
    - my-cluster-shard-00-02.xxxxx.mongodb.net:27017 # replica set node 3
    username: username
    password: password
    dbnames:
      - database
    options:
      authSource: admin
    tls: true
  - hosts: 
    - my-cluster-shard-00-03.xxxxx.mongodb.net:27017 # analytics node
    username: username
    password: password
    dbnames:
      - database
    options:
      authSource: admin
    tls: true

To find the specific hostnames for your cluster nodes, you can use the command:

dig +short SRV _mongodb._tcp.<SRV_ENDPOINT>.

This command lists all underlying database hosts in the SRV record.

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

No branches or pull requests

2 participants