Skip to content

Commit

Permalink
[mongo] add index tag to index stats metrics (#18546)
Browse files Browse the repository at this point in the history
* add index tag to index stats metrics

* add changelog
  • Loading branch information
lu-zhengda authored Sep 10, 2024
1 parent 61cccc1 commit 33559a0
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
1 change: 1 addition & 0 deletions mongo/changelog.d/18546.added
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add `index` tag to `mongodb.collection.indexes.accesses.opsps` metric for consistency with `mongodb.collection.indexsizes`.
10 changes: 6 additions & 4 deletions mongo/datadog_checks/mongo/collectors/index_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ def collect(self, api):
for coll_name in coll_names:
try:
for stats in api.index_stats(self.db_name, coll_name):
idx_name = stats.get('name', 'unknown')
additional_tags = [
"name:{0}".format(stats.get('name', 'unknown')),
"collection:{0}".format(coll_name),
"db:{0}".format(self.db_name),
f"name:{idx_name}", # deprecated but kept for backward compatability, use index instead
f"index:{idx_name}",
f"collection:{coll_name}",
f"db:{self.db_name}",
]
if stats.get('shard'):
additional_tags.append("shard:{0}".format(stats['shard']))
additional_tags.append(f"shard:{stats['shard']}")
self._submit_payload({"indexes": stats}, additional_tags, INDEX_METRICS, "collection")
except OperationFailure as e:
# Atlas restricts $indexStats on system collections
Expand Down
16 changes: 16 additions & 0 deletions mongo/tests/results/metrics-indexes-stats-autodiscover.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"tags": [
"server:mongodb://testUser2:*****@localhost:27017/test",
"name:_id_",
"index:_id_",
"collection:foo",
"db:test"
]
Expand All @@ -17,6 +18,7 @@
"tags": [
"server:mongodb://testUser2:*****@localhost:27017/test",
"name:_id_",
"index:_id_",
"collection:bar",
"db:test"
]
Expand All @@ -28,6 +30,7 @@
"tags": [
"server:mongodb://testUser2:*****@localhost:27017/test",
"name:_id_",
"index:_id_",
"collection:foo",
"db:admin"
]
Expand All @@ -39,6 +42,7 @@
"tags": [
"server:mongodb://testUser2:*****@localhost:27017/test",
"name:_id_",
"index:_id_",
"collection:bar",
"db:admin"
]
Expand All @@ -50,6 +54,7 @@
"tags": [
"server:mongodb://testUser2:*****@localhost:27017/test",
"name:_id_",
"index:_id_",
"collection:foo",
"db:config"
]
Expand All @@ -61,6 +66,7 @@
"tags": [
"server:mongodb://testUser2:*****@localhost:27017/test",
"name:_id_",
"index:_id_",
"collection:bar",
"db:config"
]
Expand All @@ -72,6 +78,7 @@
"tags": [
"server:mongodb://testUser2:*****@localhost:27017/test",
"name:_id_",
"index:_id_",
"collection:foo",
"db:integration"
]
Expand All @@ -83,6 +90,7 @@
"tags": [
"server:mongodb://testUser2:*****@localhost:27017/test",
"name:_id_",
"index:_id_",
"collection:bar",
"db:integration"
]
Expand All @@ -94,6 +102,7 @@
"tags": [
"server:mongodb://testUser2:*****@localhost:27017/test",
"name:_id_",
"index:_id_",
"collection:foo",
"db:test"
]
Expand All @@ -105,6 +114,7 @@
"tags": [
"server:mongodb://testUser2:*****@localhost:27017/test",
"name:_id_",
"index:_id_",
"collection:bar",
"db:test"
]
Expand All @@ -116,6 +126,7 @@
"tags": [
"server:mongodb://testUser2:*****@localhost:27017/test",
"name:_id_",
"index:_id_",
"collection:foo",
"db:admin"
]
Expand All @@ -127,6 +138,7 @@
"tags": [
"server:mongodb://testUser2:*****@localhost:27017/test",
"name:_id_",
"index:_id_",
"collection:bar",
"db:admin"
]
Expand All @@ -138,6 +150,7 @@
"tags": [
"server:mongodb://testUser2:*****@localhost:27017/test",
"name:_id_",
"index:_id_",
"collection:foo",
"db:config"
]
Expand All @@ -149,6 +162,7 @@
"tags": [
"server:mongodb://testUser2:*****@localhost:27017/test",
"name:_id_",
"index:_id_",
"collection:bar",
"db:config"
]
Expand All @@ -160,6 +174,7 @@
"tags": [
"server:mongodb://testUser2:*****@localhost:27017/test",
"name:_id_",
"index:_id_",
"collection:foo",
"db:integration"
]
Expand All @@ -171,6 +186,7 @@
"tags": [
"server:mongodb://testUser2:*****@localhost:27017/test",
"name:_id_",
"index:_id_",
"collection:bar",
"db:integration"
]
Expand Down
4 changes: 4 additions & 0 deletions mongo/tests/results/metrics-indexes-stats.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"tags": [
"server:mongodb://testUser2:*****@localhost:27017/test",
"name:_id_",
"index:_id_",
"collection:foo",
"db:test"
]
Expand All @@ -17,6 +18,7 @@
"tags": [
"server:mongodb://testUser2:*****@localhost:27017/test",
"name:_id_",
"index:_id_",
"collection:bar",
"db:test"
]
Expand All @@ -28,6 +30,7 @@
"tags": [
"server:mongodb://testUser2:*****@localhost:27017/test",
"name:_id_",
"index:_id_",
"collection:foo",
"db:test"
]
Expand All @@ -39,6 +42,7 @@
"tags": [
"server:mongodb://testUser2:*****@localhost:27017/test",
"name:_id_",
"index:_id_",
"collection:bar",
"db:test"
]
Expand Down

0 comments on commit 33559a0

Please sign in to comment.