Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Percona telemetry #5243

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2189,6 +2189,8 @@ IF(WITH_ENCRYPTION_UDF)
ADD_SUBDIRECTORY(extra/opensslpp)
ENDIF()

option(WITH_PERCONA_TELEMETRY "Build Percona Telemetry component" OFF)

# Utility target to build every executable tagged with ADD_TEST.
ADD_CUSTOM_TARGET(unittest_all)

Expand Down
45 changes: 45 additions & 0 deletions components/percona_telemetry/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright (c) 2024 Percona LLC and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; version 2 of
# the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA


DISABLE_MISSING_PROFILE_WARNING()

IF(WITH_PERCONA_TELEMETRY)
kamil-holubicki marked this conversation as resolved.
Show resolved Hide resolved
message(STATUS "Building Percona Telemetry component")
ELSE()
message(STATUS "Not building Percona Telemetry component")
RETURN()
ENDIF()

MYSQL_ADD_COMPONENT(percona_telemetry
percona_telemetry_component.cc
config.cc
data_provider.cc
storage.cc
worker.cc
component.cc
logger.cc
MODULE_ONLY
TEST_ONLY
)

IF(CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.1)
TARGET_LINK_LIBRARIES(component_percona_telemetry stdc++fs)
ENDIF()

TARGET_INCLUDE_DIRECTORIES(component_percona_telemetry SYSTEM PRIVATE ${BOOST_PATCHES_DIR} ${BOOST_INCLUDE_DIR})

TARGET_LINK_LIBRARIES(component_percona_telemetry extra::rapidjson)
53 changes: 53 additions & 0 deletions components/percona_telemetry/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
To compile and run:
1. configure project with cmake `-DWITH_PERCONA_TELEMETRY=ON``
2. compile the server and the component
3. start mysqld
4. Percona Telemetry component is enabled by default
5. To disable without server restart execute `UNINSTALL COMPONENT "file://component_percona_telemetry";``
6. To make disable changes permanent set `percona_telemetry_disable=1` in `my.cnf`
```
mysql> show variables like '%percona_telemetry%';
+-----------------------------------------+---------------------------------+
| Variable_name | Value |
+-----------------------------------------+---------------------------------+
| percona_telemetry.grace_interval | 86400 |
| percona_telemetry.history_keep_interval | 604800 |
| percona_telemetry.scrape_interval | 86400 |
| percona_telemetry.telemetry_root_dir | /usr/local/percona/telemetry/ps |
| percona_telemetry_disable | OFF |
+-----------------------------------------+---------------------------------+
```
Configurable in my.cnf:
```
percona_telemetry.grace_interval = 20
percona_telemetry.scrape_interval = 30
percona_telemetry.history_keep_interval = 70
percona_telemetry.telemetry_root_dir = /some/custom/dir
percona_telemetry_disable = ON/OFF
```
Note that `percona_telemetry.telemetry_root_dir` has to exist and be writable.

```
+-----------------------------------------+----------------------------------------------------------------------+
| Variable_name | Value |
+-----------------------------------------+----------------------------------------------------------------------+
| percona_telemetry.grace_interval | 20 |
| percona_telemetry.history_keep_interval | 70 |
| percona_telemetry.scrape_interval | 30 |
| percona_telemetry.telemetry_root_dir | /usr/local/percona/telemetry/ps |
| percona_telemetry_disable | OFF |
+-----------------------------------------+----------------------------------------------------------------------+

```
When the telemetry component is permanently disabled:
```
mysql> show variables like '%percona_telemetry%';
+---------------------------+-------+
| Variable_name | Value |
+---------------------------+-------+
| percona_telemetry_disable | ON |
+---------------------------+-------+
1 row in set (0,00 sec)
```


25 changes: 25 additions & 0 deletions components/percona_telemetry/common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* Copyright (c) 2024 Percona LLC and/or its affiliates. All rights reserved.

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; version 2 of
the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */

#ifndef PERCONA_TELEMETRY_COMMON_H
#define PERCONA_TELEMETRY_COMMON_H

#include <boost/preprocessor/stringize.hpp>

#define CURRENT_COMPONENT_NAME percona_telemetry
#define CURRENT_COMPONENT_NAME_STR BOOST_PP_STRINGIZE(CURRENT_COMPONENT_NAME)

#endif /* PERCONA_TELEMETRY_COMMON_H */
118 changes: 118 additions & 0 deletions components/percona_telemetry/component.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/* Copyright (c) 2024 Percona LLC and/or its affiliates. All rights reserved.

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; version 2 of
the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */

#include <mysql/components/component_implementation.h>
#include <mysql/components/my_service.h>
#include <mysql/components/services/component_sys_var_service.h>
#include <mysql/components/services/log_builtins.h>
#include <mysql/components/services/mysql_command_consumer.h>
#include <mysql/components/services/mysql_command_services.h>
#include <mysql/components/services/mysql_current_thread_reader.h>
#include <mysql/components/services/security_context.h>

#include "common.h"
#include "percona_telemetry_component.h"

namespace {
REQUIRES_SERVICE_PLACEHOLDER_AS(mysql_thd_security_context,
thd_security_context_srv);
REQUIRES_SERVICE_PLACEHOLDER_AS(mysql_command_thread, command_thread_srv);
REQUIRES_SERVICE_PLACEHOLDER_AS(mysql_command_factory, command_factory_srv);
REQUIRES_SERVICE_PLACEHOLDER_AS(mysql_command_options, command_options_srv);
REQUIRES_SERVICE_PLACEHOLDER_AS(mysql_command_query, command_query_srv);
REQUIRES_SERVICE_PLACEHOLDER_AS(mysql_command_query_result,
command_query_result_srv);
REQUIRES_SERVICE_PLACEHOLDER_AS(mysql_command_field_info,
command_field_info_srv);
REQUIRES_SERVICE_PLACEHOLDER_AS(mysql_command_error_info,
command_error_info_srv);
REQUIRES_SERVICE_PLACEHOLDER_AS(registry, registry_srv);
REQUIRES_SERVICE_PLACEHOLDER_AS(log_builtins, log_builtins_srv);
REQUIRES_SERVICE_PLACEHOLDER_AS(log_builtins_string, log_builtins_string_srv);
REQUIRES_SERVICE_PLACEHOLDER_AS(component_sys_variable_register,
component_sys_variable_register_srv);
REQUIRES_SERVICE_PLACEHOLDER_AS(component_sys_variable_unregister,
component_sys_variable_unregister_srv);

std::unique_ptr<PerconaTelemetryComponent> percona_telemetry_component;

mysql_service_status_t component_init() {
auto services = std::make_unique<PerconaTelemetryComponent::Services>();
services->thread_security_context_service = thd_security_context_srv;
services->command_thread_service = command_thread_srv;
services->command_factory_service = command_factory_srv;
services->command_options_service = command_options_srv;
services->command_query_service = command_query_srv;
services->command_query_result_service = command_query_result_srv;
services->command_field_info_service = command_field_info_srv;
services->command_error_info_service = command_error_info_srv;
services->log_builtins_service = log_builtins_srv;
services->log_builtins_string = log_builtins_string_srv;
services->var_register_service = component_sys_variable_register_srv;
services->var_unregister_service = component_sys_variable_unregister_srv;

percona_telemetry_component =
percona-ysorokin marked this conversation as resolved.
Show resolved Hide resolved
std::make_unique<PerconaTelemetryComponent>(std::move(services));

if (percona_telemetry_component->start()) {
return 1;
}

return 0;
}

mysql_service_status_t component_deinit() {
if (percona_telemetry_component->stop()) {
return 1;
}

percona_telemetry_component.reset();
return 0;
}

BEGIN_COMPONENT_PROVIDES(CURRENT_COMPONENT_NAME)
END_COMPONENT_PROVIDES();

BEGIN_COMPONENT_REQUIRES(CURRENT_COMPONENT_NAME)
REQUIRES_SERVICE_AS(mysql_thd_security_context, thd_security_context_srv),
REQUIRES_SERVICE_AS(mysql_command_thread, command_thread_srv),
REQUIRES_SERVICE_AS(mysql_command_factory, command_factory_srv),
REQUIRES_SERVICE_AS(mysql_command_options, command_options_srv),
REQUIRES_SERVICE_AS(mysql_command_query, command_query_srv),
REQUIRES_SERVICE_AS(mysql_command_query_result, command_query_result_srv),
REQUIRES_SERVICE_AS(mysql_command_field_info, command_field_info_srv),
REQUIRES_SERVICE_AS(mysql_command_error_info, command_error_info_srv),
REQUIRES_SERVICE_AS(registry, registry_srv),
REQUIRES_SERVICE_AS(log_builtins, log_builtins_srv),
REQUIRES_SERVICE_AS(log_builtins_string, log_builtins_string_srv),
REQUIRES_SERVICE_AS(component_sys_variable_register,
component_sys_variable_register_srv),
REQUIRES_SERVICE_AS(component_sys_variable_unregister,
component_sys_variable_unregister_srv),
END_COMPONENT_REQUIRES();

BEGIN_COMPONENT_METADATA(CURRENT_COMPONENT_NAME)
METADATA("mysql.author", "Percona Corporation"),
METADATA("mysql.license", "GPL"), METADATA("mysql.version", "1"),
END_COMPONENT_METADATA();

DECLARE_COMPONENT(CURRENT_COMPONENT_NAME, CURRENT_COMPONENT_NAME_STR)
component_init, component_deinit END_DECLARE_COMPONENT();

} // namespace

DECLARE_LIBRARY_COMPONENTS &COMPONENT_REF(CURRENT_COMPONENT_NAME)
END_DECLARE_LIBRARY_COMPONENTS
Loading
Loading