dapr / components-contrib

Community driven, reusable components for distributed apps
Apache License 2.0
546 stars 476 forks source link

Dapr Mongo State Store component does not support srv record format #904

Closed kshitijcode closed 3 years ago

kshitijcode commented 3 years ago

Expected Behavior

We are using the Dapr Mongo State component as a state store and Mongo Atlas as a DB provider. The DB is running in cluster mode and has primary and secondary replicas. Thus Mongo Atlas provides the connection String in SRV format, for example (mongodb+srv://cluster0.fulhd.mongodb.net/myFirstDatabase )

During Dapr initialization of the mongo component, we are getting init timeout after 5 seconds and the component is not loaded. This results in the failure of the Dapr sidecar during initialization. On further evaluation, we saw the connectionString is formed inside the code with "mongodb://" and does not support "mongodb+srv://" format.

https://github.com/dapr/components-contrib/blob/4ee732e0bd5e616b18fcfe15219712a74300b0fb/state/mongodb/mongodb.go#L49

There is also no way to supply a connectionString directly using any of the metadata fields as defined https://docs.dapr.io/reference/components-reference/supported-state-stores/setup-mongodb/.

Actual Behavior

Steps to Reproduce the Problem

  1. Create a shared cluster in Mongo Atlas or use an existing Mongo Atlas.
  2. Create a Dapr State Store Component file for MongoDb as described in https://docs.dapr.io/reference/components-reference/supported-state-stores/setup-mongodb/ . In the component file, the "host" should be the URI provided by Mongo Atlas for the created cluster.
    1. Start the application and wait for the components to be fully loaded.
  3. Dapr Mongo component fails to load.
yaron2 commented 3 years ago

Put this for 1.3. /cc @artursouza @pkedy

dmitsh commented 3 years ago

/assign