Skip to content

Conversation

@kanakagrawal
Copy link
Contributor

@kanakagrawal kanakagrawal commented Aug 11, 2021

PMM-7424

Add dbStats collector

Here are the metrics added because of this new collector (testdb is name of database I added. Same metrics are added for all databases)

# HELP mongodb_dbstats_testdb_avgObjSize dbstats_testdb.
# TYPE mongodb_dbstats_testdb_avgObjSize untyped
mongodb_dbstats_testdb_avgObjSize{cl_id="611fa5e6165e2964515910a7",cl_role="shardsvr",rs_nm="rs1",rs_state="1"} 40
# HELP mongodb_dbstats_testdb_clusterTime_signature_keyId dbstats_testdb.$clusterTime.signature.
# TYPE mongodb_dbstats_testdb_clusterTime_signature_keyId untyped
mongodb_dbstats_testdb_clusterTime_signature_keyId{cl_id="611fa5e6165e2964515910a7",cl_role="shardsvr",rs_nm="rs1",rs_state="1"} 0
# HELP mongodb_dbstats_testdb_collections dbstats_testdb.
# TYPE mongodb_dbstats_testdb_collections untyped
mongodb_dbstats_testdb_collections{cl_id="611fa5e6165e2964515910a7",cl_role="shardsvr",rs_nm="rs1",rs_state="1"} 3
# HELP mongodb_dbstats_testdb_configServerState_opTime_t dbstats_testdb.$configServerState.opTime.
# TYPE mongodb_dbstats_testdb_configServerState_opTime_t untyped
mongodb_dbstats_testdb_configServerState_opTime_t{cl_id="611fa5e6165e2964515910a7",cl_role="shardsvr",rs_nm="rs1",rs_state="1"} 1
# HELP mongodb_dbstats_testdb_dataSize dbstats_testdb.
# TYPE mongodb_dbstats_testdb_dataSize untyped
mongodb_dbstats_testdb_dataSize{cl_id="611fa5e6165e2964515910a7",cl_role="shardsvr",rs_nm="rs1",rs_state="1"} 1200
# HELP mongodb_dbstats_testdb_fsTotalSize dbstats_testdb.
# TYPE mongodb_dbstats_testdb_fsTotalSize untyped
mongodb_dbstats_testdb_fsTotalSize{cl_id="611fa5e6165e2964515910a7",cl_role="shardsvr",rs_nm="rs1",rs_state="1"} 9.82899539968e+11
# HELP mongodb_dbstats_testdb_fsUsedSize dbstats_testdb.
# TYPE mongodb_dbstats_testdb_fsUsedSize untyped
mongodb_dbstats_testdb_fsUsedSize{cl_id="611fa5e6165e2964515910a7",cl_role="shardsvr",rs_nm="rs1",rs_state="1"} 1.31967700992e+11
# HELP mongodb_dbstats_testdb_indexSize dbstats_testdb.
# TYPE mongodb_dbstats_testdb_indexSize untyped
mongodb_dbstats_testdb_indexSize{cl_id="611fa5e6165e2964515910a7",cl_role="shardsvr",rs_nm="rs1",rs_state="1"} 49152
# HELP mongodb_dbstats_testdb_indexes dbstats_testdb.
# TYPE mongodb_dbstats_testdb_indexes untyped
mongodb_dbstats_testdb_indexes{cl_id="611fa5e6165e2964515910a7",cl_role="shardsvr",rs_nm="rs1",rs_state="1"} 3
# HELP mongodb_dbstats_testdb_numExtents dbstats_testdb.
# TYPE mongodb_dbstats_testdb_numExtents untyped
mongodb_dbstats_testdb_numExtents{cl_id="611fa5e6165e2964515910a7",cl_role="shardsvr",rs_nm="rs1",rs_state="1"} 0
# HELP mongodb_dbstats_testdb_objects dbstats_testdb.
# TYPE mongodb_dbstats_testdb_objects untyped
mongodb_dbstats_testdb_objects{cl_id="611fa5e6165e2964515910a7",cl_role="shardsvr",rs_nm="rs1",rs_state="1"} 30
# HELP mongodb_dbstats_testdb_ok dbstats_testdb.
# TYPE mongodb_dbstats_testdb_ok untyped
mongodb_dbstats_testdb_ok{cl_id="611fa5e6165e2964515910a7",cl_role="shardsvr",rs_nm="rs1",rs_state="1"} 1
# HELP mongodb_dbstats_testdb_storageSize dbstats_testdb.
# TYPE mongodb_dbstats_testdb_storageSize untyped
mongodb_dbstats_testdb_storageSize{cl_id="611fa5e6165e2964515910a7",cl_role="shardsvr",rs_nm="rs1",rs_state="1"} 49152
# HELP mongodb_dbstats_testdb_views dbstats_testdb.
# TYPE mongodb_dbstats_testdb_views untyped
mongodb_dbstats_testdb_views{cl_id="611fa5e6165e2964515910a7",cl_role="shardsvr",rs_nm="rs1",rs_state="1"} 0

  • Tests passed.
  • Fix conflicts with target branch.
  • Update jira ticket description if needed.
  • Attach screenshots/console output to confirm new behavior to jira ticket, if applicable.

When all checks have passed and code is ready for the review, bot should add pmm-review-exporters team as the reviewer. That would assign people from the review team automatically. Report any issues on our Forums and Discord.

@it-percona-cla
Copy link

it-percona-cla commented Aug 11, 2021

CLA assistant check
All committers have signed the CLA.

@kanakagrawal
Copy link
Contributor Author

@percona-csalguero can you approve for running workflows on this PR?

@denisok denisok requested review from a team, JiriCtvrtka and percona-csalguero and removed request for a team August 11, 2021 06:06
@kanakagrawal kanakagrawal marked this pull request as draft August 11, 2021 06:29
@kanakagrawal kanakagrawal marked this pull request as ready for review August 12, 2021 06:15
@kanakagrawal
Copy link
Contributor Author

Github Actions has added some linter suggestions in the code. But I've followed the coding style as used at other places in the code. It says -

exporter/dbstats_collector.go:45:3: return with no blank line before (nlreturn)
exporter/dbstats_collector.go:55:4: continue with no blank line before (nlreturn)
Function 'TestDBStatsCollector' is too long (77 > 60) (funlen)
exporter/dbstats_collector_test.go:58:8: ctx, compatibleMode are missing in dbstatsCollector (exhaustivestruct) c := &dbstatsCollector{

At many places in the current code, these scenarios already happens.

For now, I'm ignoring it. Let me know if I should address these linter suggestions.

@percona-csalguero
Copy link
Contributor

Hello again.
This looks good. I ran the tests and they are passing. I just requested a small change just to make the main list more clear and we can filter out metrics.

Thanks

// Since all dbstats will have the same fields, we need to use a metric prefix (db)
// to differentiate metrics between different databases. Labels are being set only to make it easier
// to filter
prefix := db
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make the prefix cs + db?
I am thinking about a way to group all the metrics from this collector in the main list.
Thanks,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused about what is cs? Do you mean to append just the string like this -

 		prefix := "cs" + db

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some prefix to identify the collector
dbstats_ or something like that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added the dbstats_ prefix. Here is an example metric after that (testdb is name of database)-

mongodb_dbstats_testdb_indexes{cl_id="611fa5e6165e2964515910a7",cl_role="shardsvr",rs_nm="rs1",rs_state="1"} 3

I've also updated the test case and metrics mentioned in PR description.

@percona-csalguero
Copy link
Contributor

@kanakagrawal thanks for making the requested changes.
I approved the PR but we need a second approval to merge it. While other team members review and approve the PR, feel free to update the Changelog file and add yourself as a contributor.

@kanakagrawal
Copy link
Contributor Author

@kanakagrawal thanks for making the requested changes.
I approved the PR but we need a second approval to merge it. While other team members review and approve the PR, feel free to update the Changelog file and add yourself as a contributor.

I've updated the Changelog file. I'm not sure what you meant by adding myself as a contributor? I've signed the CLA if that is what you meant.

@kanakagrawal
Copy link
Contributor Author

@percona-csalguero there is one issue with this PR. Even after setting the d.compatibleMode to true, the old metrics are not added here

		for _, metric := range makeMetrics(prefix, dbStats, d.topologyInfo.baseLabels(), d.compatibleMode) {
			ch <- metric
		}

I see that for mongos old metrics are already added in the mongosMetrics function like this -

# HELP mongodb_mongos_db_data_size_bytes The total size in bytes of the uncompressed data held in this database
# TYPE mongodb_mongos_db_data_size_bytes gauge
mongodb_mongos_db_data_size_bytes{db="admin",shard="rs1"} 599
mongodb_mongos_db_data_size_bytes{db="admin",shard="rs2"} 221
mongodb_mongos_db_data_size_bytes{db="config",shard="rs1"} 130185
mongodb_mongos_db_data_size_bytes{db="config",shard="rs2"} 130152
mongodb_mongos_db_data_size_bytes{db="testdb",shard="rs1"} 1200
mongodb_mongos_db_data_size_bytes{db="testdb",shard="rs2"} 0
# HELP mongodb_mongos_db_index_size_bytes The total size in bytes of all indexes created on this database
# TYPE mongodb_mongos_db_index_size_bytes gauge
mongodb_mongos_db_index_size_bytes{db="admin",shard="rs1"} 36864
mongodb_mongos_db_index_size_bytes{db="admin",shard="rs2"} 16384
mongodb_mongos_db_index_size_bytes{db="config",shard="rs1"} 208896
mongodb_mongos_db_index_size_bytes{db="config",shard="rs2"} 184320
mongodb_mongos_db_index_size_bytes{db="testdb",shard="rs1"} 49152
mongodb_mongos_db_index_size_bytes{db="testdb",shard="rs2"} 0

But they are missing for mongod.

With this patch, database name is part of the metric name. So, we need to modify the metricRenameAndLabel call for these metrics. WDYT?

@denisok
Copy link
Contributor

denisok commented Aug 25, 2021

OK, we are moving it to QA and checking if everything works from QA perspective

@percona-csalguero percona-csalguero merged commit a1fd7ce into percona:main Aug 26, 2021
@kanakagrawal kanakagrawal deleted the PMM-7424-dbStats branch September 1, 2021 02:53
@denisok denisok added the award swag prize for the contributors. Please contact Percona if we can't reach you! label Dec 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

award swag prize for the contributors. Please contact Percona if we can't reach you! community enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants