coiled / dask-mongo

BSD 3-Clause "New" or "Revised" License
19 stars 9 forks source link

Track appname in MongoClient #18

Closed ncclementi closed 2 years ago

ncclementi commented 2 years ago

It'll be useful for the Atlas folks to see how many people are connecting to Atlas Clusters via our dask-mongo connector. To do that we need to include the appname when creating the client.

I believe it would look something like

app_info = f"dask-mongo/{dask_mongo.__version__}"

with pymongo.MongoClient(**connection_kwargs, appname=app_info) as mongo_client:
       #do things

We should include this in write_mongo, fetch_mongo, and read_mongo in https://github.com/coiled/dask-mongo/blob/main/dask_mongo/core.py

For reference, read appname in https://pymongo.readthedocs.io/en/stable/api/pymongo/mongo_client.html

cc: @jrbourbeau @rrpelgrim @baf509

jrbourbeau commented 2 years ago

Sounds reasonable to me. Are there restrictions on what characters can be in appname? Is app_info = f"dask-mongo/{dask_mongo.__version__}" a valid name?

ncclementi commented 2 years ago

It looks like appname takes strings, according to the docs.

appname: (string or None) The name of the application that created this MongoClient instance. The server will log this value upon establishing each connection. It is also recorded in the slow query log and profile collections.

ShaneHarvey commented 2 years ago

Are there restrictions on what characters can be in appname?

No restrictions, f"dask-mongo/{dask_mongo.__version__}" makes sense to me.

jrbourbeau commented 2 years ago

Thanks for clarifying @ShaneHarvey. Are you able to confirm if the appname added in https://github.com/coiled/dask-mongo/pull/19 is showing up on the mongo side?

ShaneHarvey commented 2 years ago

You can verify by inspecting the server logs. The server will log the appname on each new connection like this:

{"t":{"$date":"2022-05-24T18:57:35.254-07:00"},"s":"I",  "c":"NETWORK",  "id":22943,   "ctx":"listener","msg":"Connection accepted","attr":{"remote":"127.0.0.1:49719","uuid":"6182ae63-66e5-40c6-8284-511b3363fd94","connectionId":27,"connectionCount":6}}
{"t":{"$date":"2022-05-24T18:57:35.255-07:00"},"s":"I",  "c":"NETWORK",  "id":51800,   "ctx":"conn27","msg":"client metadata","attr":{"remote":"127.0.0.1:49719","client":"conn27","doc":{"driver":{"name":"PyMongo","version":"4.2.0.dev1"},"os":{"type":"Darwin","name":"Darwin","architecture":"x86_64","version":"10.16"},"platform":"CPython 3.7.9.final.0","application":{"name":"dask-mongo/1.1.1"}}}}
ncclementi commented 2 years ago

@ShaneHarvey Can you tell me more about how can I access the logs? I'm currently using the M0 free tier instances, and I can't seem to find the logs on Atlas. Is there a way to access the logs through some pymongo command?

baf509 commented 2 years ago

I don't think you can download the logs for the M0, at M10 or higher there should be a button under the "Three Dot Menu" on the Cluster card which says "Download Logs".

I'm guessing Shane was using an M10 or maybe just doing the testing with a local MongoDB where you can access the logs locally.

On Wed, May 25, 2022 at 10:04 AM Naty Clementi @.***> wrote:

@ShaneHarvey https://github.com/ShaneHarvey Can you tell me more about how can I access the logs? I'm currently using the M0 free tier instances, and I can't seem to find the logs on Atlas. Is there a way to access the logs through some pymongo command?

— Reply to this email directly, view it on GitHub https://github.com/coiled/dask-mongo/issues/18#issuecomment-1137289860, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAXQ7NBAJLKLQBXKAVPVAHDVLYXPFANCNFSM5W2NK6OQ . You are receiving this because you were mentioned.Message ID: @.***>

-- Benjamin Flast 908-249-3044

ncclementi commented 2 years ago

Thanks @baf509 I was able to test it locally by printing the mongo_client.server_info().

{"t":{"$date":"2022-05-25T12:08:24.475-04:00"},"s":"I",  "c":"COMMAND",  "id":51803,   "ctx":"conn11","msg":"Slow query","attr":{"type":"command","ns":"test-db.test-collection",
"appName":"dask-mongo/2021.7.3","command":{"insert":"test-collection","ordered":true,"lsid":{"id":{"$uuid":"667d444d-3034-445d-bbf4-f812a75b6c56"}},"$db":"test-db"},"ninserted":2,"keysInserted":2,"numYields":0,"reslen":45,"locks":{"ParallelBatchWriterMode":{"acquireCount":{"r":4}},"ReplicationStateTransition":{"acquireCount":{"w":4}},"Global":{"acquireCount":{"r":1,"w":3}},"Database":{"acquireCount":{"r":1,"w":3}},"Collection":{"acquireCount":{"r":1,"w":3}},"Mutex":
{"acquireCount":{"r":5}}},"flowControl":{"acquireCount":3,"timeAcquiringMicros":10},"storage":{},"remote":"127.0.0.1:53735","protocol":"op_msg","durationMillis":252}}

I will go ahead and do a release, pypi should be fast, we will have to wait a bit for conda-forge until the bots pick it up.

@jrbourbeau Do I have a green light to release?

jrbourbeau commented 2 years ago

Releasing sounds great 👍

ncclementi commented 2 years ago

@baf509 The new release of dask-mongo that includes the tracking of the appname is up on PyPI and should be in conda-forge in 1h or so, we've just merged the conda-forge feedstock PR.

bafMdb commented 2 years ago

That's great, thanks @ncclementi!