Countly / countly-server

Countly is a product analytics platform that helps teams track, analyze and act-on their user actions and behaviour on mobile, web and desktop applications.
https://countly.com
Other
5.59k stars 973 forks source link

Question: is it a good idea to support mongo+srv connection strings? #1354

Closed dimaqq closed 4 years ago

dimaqq commented 4 years ago

I've been trialling countly server, v 20.04 from docker-hub, using docker-compose.

Obv., it worked like a charm with a local mongodb container, but I'd want to move this to the cloud. I've tried Azure Cosmos DB with Mongo API, but that doesn't support capped collections πŸ‘Ž I think AWS DocumentDB-thingy has the same limitation.

So, now I'm trying MongoDB (Cloud) Atlas, and it gives me a connection string with mongo+srv:// scheme. As far as I understand, that's not currently supported by countly-server, is it?

Would it be a good idea to support this scheme?

So, I've looked up actual hostnames (3 in total, 1 primary, 2 secondary), and set up: COUNTLY_CONFIG__MONGODB_HOST=foo-00.bar,foo-01.bar,foo-02.bar

This worked at first, but currently doesn't with "reason":{"type":"ReplicaSetNoPrimary",

I think what has happened is that a different host (among the 3) became mongo primary and neither api nor frontend can handle that.

iartem commented 4 years ago

Yep, neither of those Mongo-QL-replicating products is supported.

As for mongodb+srv://, it's not supported as of now, but we'll support it of course. Right now I'd suggest using what's called "legacy" connection string in Atlas, it's a plain mongodb:// one.

Regarding ReplicaSetNoPrimary, my guess would be that you don't pass replica set name (you use _HOST env var as opposed to URI, therefore no rs=XXX) and some tricky code in MongoDB driver doesn't handle that well. Could you try legacy URI and let us know?

dimaqq commented 4 years ago

Re: ReplicaSetNoPrimary it's also documented that this is the error that Mongo Atlas returns when there are too many requests for a given "instance". Since I was trying the free tier, it's possible that was the case, though that was not reflected in the metrics.

I'll poke it some more, however I've realised that all free and cheap tiers of Mongo Atlas are very limited. πŸ‘Ž The smallest sane "instance" type is M10 at $0.10 per hour, which is pretty steep. 😒

dimaqq commented 4 years ago

In case someone else lands here, this environment variable does not appear documented, here's an example for passing MongoDB Atlas NodeJS 2.2.12 or later style connection URL to 20.04 containers, docker-compose environment format:

- COUNTLY_CONFIG__MONGODB=mongodb://countly:${MONGODB_PASSWORD}@your-cluster-shard-00-00-gtup4.mongodb.net:27017,your-cluster-shard-00-01-gtup4.mongodb.net:27017,your-cluster-shard-00-02-gtup4.mongodb.net:27017/test?ssl=true&replicaSet=your-cluster-prv-shard-0&authSource=admin&retryWrites=true&w=majority

dimaqq commented 4 years ago

Now I'm not getting ReplicaSetNoPrimary any more, so far🀞, but I am getting MongoServerSelectionError: Authentication failed. from time to time.

dimaqq commented 4 years ago

Ah, sorry I think I misread the error, the auth failed also includes this bit: reason: TopologyDescription { type: 'ReplicaSetNoPrimary', So I guess it's the same error, whether combining 3 hosts via _MONGODB_HOST or passing a _MONGODB url with 3 embedded hostnames.

iartem commented 4 years ago

Not sure what you meant by COUNTLY_CONFIG__MONGODB not being documented - it is documented.

But thanks for the ReplicaSetNoPrimary being too much requests hint, noted. For the reference, it's listed as one of the reasons on this page.

Try setting COUNTLY_CONFIG_API_MONGODB_MAX_POOL_SIZE to something less than default 500. Start from 10, for example.

dimaqq commented 4 years ago

re: documentation, it could be better :) the variable is mentioned at https://support.count.ly/hc/en-us/articles/900000594266-Docker-Kubernetes-Enterprise-Edition

other locations, like docker-compose.yml list individual components, like _HOST/USERNAME/PASSWORD instead.

I am running with max pool size 10 now and so far it's mostly fine. Then again there's no traffic as the app is pre-beta so 🀷

iartem commented 4 years ago

Ok, main Docker documentation link is this one https://support.count.ly/hc/en-us/articles/360037814511-Docker-Kubernetes#configuration It almost exclusively uses __MONGODB variables

ar2rsawseen commented 4 years ago

MongoDB DNS seed list connection string support added here: https://github.com/Countly/countly-server/commit/98dc071ea2083e609975259bdc320bc052a3ea1f