Skip to content

Commit 400664d

Browse files
Merge pull request #5756 from kamil-holubicki/PS-10264-8.0
(8.0) PS-10264: Implement Telemetry Collection for Key DB Features (ThreadPool, MyRocks)
2 parents 101d844 + c49d009 commit 400664d

File tree

2 files changed

+100
-20
lines changed

2 files changed

+100
-20
lines changed

components/percona_telemetry/data_provider.cc

Lines changed: 98 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ const char *is_source = "is_source";
5555
const char *is_semisync_replica = "is_semisync_replica";
5656
const char *is_replica = "is_replica";
5757
const char *replication_info = "replication_info";
58+
const char *se_info = "se_info";
59+
const char *name = "name";
60+
const char *size = "size";
61+
62+
// server configuration variables
63+
const char *server_config_info = "server_config_info";
64+
const char *thread_handling = "thread_handling";
5865
} // namespace JSONKey
5966
} // namespace
6067

@@ -212,7 +219,7 @@ bool DataProvider::do_query(const std::string &query, QueryResult *result,
212219
const std::string &DataProvider::get_database_instance_id() {
213220
if (!database_instance_id_cache_.length()) {
214221
QueryResult result;
215-
if (do_query("SELECT @@server_uuid", &result)) {
222+
if (do_query("SELECT @@server_uuid", &result) || result.empty()) {
216223
static std::string empty;
217224
return empty;
218225
}
@@ -245,7 +252,8 @@ bool DataProvider::collect_product_version_info(rapidjson::Document *document) {
245252
// Version doesn't change during the lifetime, so query and cache it
246253
if (version_cache_.empty()) {
247254
QueryResult result;
248-
if (do_query("SELECT @@VERSION, @@VERSION_COMMENT", &result)) {
255+
if (do_query("SELECT @@VERSION, @@VERSION_COMMENT", &result) ||
256+
result.empty()) {
249257
return true;
250258
}
251259

@@ -311,7 +319,7 @@ bool DataProvider::collect_components_info(rapidjson::Document *document) {
311319

312320
bool DataProvider::collect_uptime_info(rapidjson::Document *document) {
313321
QueryResult result;
314-
if (do_query("SHOW GLOBAL STATUS LIKE 'Uptime'", &result)) {
322+
if (do_query("SHOW GLOBAL STATUS LIKE 'Uptime'", &result) || result.empty()) {
315323
return true;
316324
}
317325

@@ -327,7 +335,8 @@ bool DataProvider::collect_dbs_number_info(rapidjson::Document *document) {
327335
if (do_query(
328336
"SELECT COUNT(*) FROM information_schema.SCHEMATA WHERE SCHEMA_NAME "
329337
"NOT IN('mysql', 'information_schema', 'performance_schema', 'sys')",
330-
&result)) {
338+
&result) ||
339+
result.empty()) {
331340
return true;
332341
}
333342

@@ -339,15 +348,22 @@ bool DataProvider::collect_dbs_number_info(rapidjson::Document *document) {
339348
return false;
340349
}
341350

342-
/* Note that this metric is update very X, so it may be inacurate.
351+
/* Note that metrics related to size are updated every 24hrs, so they may be
352+
inaccurate.
343353
We could make it accurate but that would need ANALYZE TABLE for every table
344-
which would be overkill.*/
354+
which would be overkill. */
355+
/* Collect the size of all databases. This information is available also via
356+
metrics collected in collect_se_info(), but we keep collecting it here
357+
as well for backward compatibility. If not needed, we can safely remove this
358+
method in the future. */
345359
bool DataProvider::collect_dbs_size_info(rapidjson::Document *document) {
360+
// total size of databases
346361
QueryResult result;
347362
if (do_query("SELECT IFNULL(ROUND(SUM(data_length + index_length), 1), '0') "
348-
"size_MB FROM information_schema.tables WHERE table_schema NOT "
363+
"bytes FROM information_schema.tables WHERE table_schema NOT "
349364
"IN('mysql', 'information_schema', 'performance_schema', 'sys')",
350-
&result)) {
365+
&result) ||
366+
result.empty()) {
351367
return true;
352368
}
353369

@@ -359,6 +375,10 @@ bool DataProvider::collect_dbs_size_info(rapidjson::Document *document) {
359375
return false;
360376
}
361377

378+
/* Collect the list of SEs in use. This information is available also via
379+
metrics collected in collect_se_info(), but we keep collecting it here
380+
as well for backward compatibility. If not needed, we can safely remove this
381+
method in the future. */
362382
bool DataProvider::collect_se_usage_info(rapidjson::Document *document) {
363383
QueryResult result;
364384
if (do_query("SELECT DISTINCT ENGINE FROM information_schema.tables WHERE "
@@ -381,6 +401,40 @@ bool DataProvider::collect_se_usage_info(rapidjson::Document *document) {
381401
return false;
382402
}
383403

404+
/* Collect the SE info (for now only size) */
405+
bool DataProvider::collect_se_info(rapidjson::Document *document) {
406+
QueryResult result;
407+
if (do_query("SELECT ENGINE, "
408+
"IFNULL(ROUND(SUM(data_length + index_length), 1), '0') bytes "
409+
"FROM information_schema.TABLES "
410+
"WHERE TABLE_SCHEMA NOT IN ('mysql', 'performance_schema', "
411+
"'information_schema', 'sys') "
412+
"GROUP BY ENGINE;",
413+
&result)) {
414+
return true;
415+
}
416+
417+
rapidjson::Document::AllocatorType &allocator = document->GetAllocator();
418+
rapidjson::Value se_info(rapidjson::Type::kArrayType);
419+
420+
for (auto &engine_iter : result) {
421+
rapidjson::Document engine_obj(rapidjson::Type::kObjectType);
422+
rapidjson::Value engine_name;
423+
engine_name.SetString(engine_iter[0].c_str(), allocator);
424+
engine_obj.AddMember(rapidjson::StringRef(JSONKey::name), engine_name,
425+
allocator);
426+
rapidjson::Value engine_size;
427+
engine_size.SetString(engine_iter[1].c_str(), allocator);
428+
engine_obj.AddMember(rapidjson::StringRef(JSONKey::size), engine_size,
429+
allocator);
430+
431+
se_info.PushBack(engine_obj, allocator);
432+
}
433+
document->AddMember(rapidjson::StringRef(JSONKey::se_info), se_info,
434+
allocator);
435+
return false;
436+
}
437+
384438
bool DataProvider::collect_group_replication_info(
385439
rapidjson::Document *document) {
386440
// Do fast check if there is anything to learn about GR
@@ -407,7 +461,7 @@ bool DataProvider::collect_group_replication_info(
407461
return false;
408462
}
409463

410-
if (result.size() > 0) {
464+
if (!result.empty()) {
411465
// We've got some rows. Try to collect more details.
412466
rapidjson::Document::AllocatorType &allocator = document->GetAllocator();
413467
rapidjson::Document gr_json(rapidjson::Type::kObjectType);
@@ -427,7 +481,8 @@ bool DataProvider::collect_group_replication_info(
427481
/* replication group size */
428482
if (!do_query(
429483
"SELECT COUNT(*) FROM performance_schema.replication_group_members",
430-
&result)) {
484+
&result) &&
485+
!result.empty()) {
431486
rapidjson::Value group_size;
432487
group_size.SetString(result[0][0].c_str(), allocator);
433488
gr_json.AddMember(rapidjson::StringRef(JSONKey::group_size), group_size,
@@ -452,28 +507,30 @@ bool DataProvider::collect_async_replication_info(
452507
if (do_query("SHOW REPLICAS", &result)) {
453508
return true;
454509
}
455-
is_source = result.size() > 0;
510+
is_source = !result.empty();
456511

457512
// If we are replica
458513
if (do_query("SHOW REPLICA STATUS", &result)) {
459514
return true;
460515
}
461-
is_replica = result.size() > 0;
516+
is_replica = !result.empty();
462517

463518
// Name of the variable depends on what plugin was installed
464519
// If we are semisync source
465-
if (!do_query("SELECT @@global.rpl_semi_sync_source_enabled", &result,
466-
nullptr, true) ||
467-
!do_query("SELECT @@global.rpl_semi_sync_master_enabled", &result,
468-
nullptr, true)) {
520+
if ((!do_query("SELECT @@global.rpl_semi_sync_source_enabled", &result,
521+
nullptr, true) ||
522+
!do_query("SELECT @@global.rpl_semi_sync_master_enabled", &result,
523+
nullptr, true)) &&
524+
!result.empty()) {
469525
is_semisync_source = !result[0][0].compare("1");
470526
is_semisync_source &= is_source;
471527
}
472528
// If we are semisync replica
473-
if (!do_query("SELECT @@global.rpl_semi_sync_replica_enabled", &result,
474-
nullptr, true) ||
475-
!do_query("SELECT @@global.rpl_semi_sync_slave_enabled", &result, nullptr,
476-
true)) {
529+
if ((!do_query("SELECT @@global.rpl_semi_sync_replica_enabled", &result,
530+
nullptr, true) ||
531+
!do_query("SELECT @@global.rpl_semi_sync_slave_enabled", &result,
532+
nullptr, true)) &&
533+
!result.empty()) {
477534
is_semisync_replica = !result[0][0].compare("1");
478535
is_semisync_replica &= is_replica;
479536
}
@@ -532,6 +589,25 @@ bool DataProvider::collect_db_replication_id(rapidjson::Document *document) {
532589
return false;
533590
}
534591

592+
bool DataProvider::collect_server_config(rapidjson::Document *document) {
593+
rapidjson::Document::AllocatorType &allocator = document->GetAllocator();
594+
rapidjson::Document server_config_json(rapidjson::Type::kObjectType);
595+
596+
/* Collect as much as possible. In case of error, skip and continue. */
597+
QueryResult result;
598+
if (!do_query("SELECT @@thread_handling", &result) && !result.empty()) {
599+
rapidjson::Value thread_handling;
600+
thread_handling.SetString(result[0][0].c_str(), allocator);
601+
server_config_json.AddMember(rapidjson::StringRef(JSONKey::thread_handling),
602+
thread_handling, allocator);
603+
}
604+
605+
document->AddMember(rapidjson::StringRef(JSONKey::server_config_info),
606+
server_config_json, allocator);
607+
608+
return false;
609+
}
610+
535611
bool DataProvider::collect_metrics(rapidjson::Document *document) {
536612
/* The configuration of this instance might have changed, so we need to colect
537613
it every time. */
@@ -554,8 +630,10 @@ bool DataProvider::collect_metrics(rapidjson::Document *document) {
554630
res |= collect_dbs_number_info(document);
555631
res |= collect_dbs_size_info(document);
556632
res |= collect_se_usage_info(document);
633+
res |= collect_se_info(document);
557634
res |= collect_group_replication_info(document);
558635
res |= collect_async_replication_info(document);
636+
res |= collect_server_config(document);
559637

560638
/* The requirement is to have db_replication_id key at the top of JSON
561639
structure. But it may originate from the different places. The above

components/percona_telemetry/data_provider.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,10 @@ class DataProvider {
8484
bool collect_dbs_number_info(rapidjson::Document *document);
8585
bool collect_dbs_size_info(rapidjson::Document *document);
8686
bool collect_se_usage_info(rapidjson::Document *document);
87+
bool collect_se_info(rapidjson::Document *document);
8788
bool collect_group_replication_info(rapidjson::Document *document);
8889
bool collect_async_replication_info(rapidjson::Document *document);
90+
bool collect_server_config(rapidjson::Document *document);
8991
bool collect_db_replication_id(rapidjson::Document *document);
9092
bool collect_metrics(rapidjson::Document *document);
9193

0 commit comments

Comments
 (0)