Add logs to citus_stats_tenants (#6762)

Creates log message for citus_stats_tenants
multi-tenant-monitoring-pgbench
Halil Ozan Akgül 2023-03-29 11:50:16 +03:00 committed by Halil Ozan Akgul
parent 4b99fd0a2d
commit e0046d2d79
5 changed files with 68 additions and 18 deletions

View File

@ -14,6 +14,14 @@ CREATE OR REPLACE FUNCTION pg_catalog.citus_stats_tenants (
LANGUAGE plpgsql LANGUAGE plpgsql
AS $function$ AS $function$
BEGIN BEGIN
IF
array_position(enumvals, 'log') >= array_position(enumvals, setting)
AND setting != 'off'
FROM pg_settings
WHERE name = 'citus.multi_tenant_monitoring_log_level'
THEN
RAISE LOG 'Generating citus_stats_tenants';
END IF;
RETURN QUERY RETURN QUERY
SELECT * SELECT *
FROM jsonb_to_recordset(( FROM jsonb_to_recordset((

View File

@ -14,6 +14,14 @@ CREATE OR REPLACE FUNCTION pg_catalog.citus_stats_tenants (
LANGUAGE plpgsql LANGUAGE plpgsql
AS $function$ AS $function$
BEGIN BEGIN
IF
array_position(enumvals, 'log') >= array_position(enumvals, setting)
AND setting != 'off'
FROM pg_settings
WHERE name = 'citus.multi_tenant_monitoring_log_level'
THEN
RAISE LOG 'Generating citus_stats_tenants';
END IF;
RETURN QUERY RETURN QUERY
SELECT * SELECT *
FROM jsonb_to_recordset(( FROM jsonb_to_recordset((

View File

@ -40,7 +40,6 @@ ExecutorEnd_hook_type prev_ExecutorEnd = NULL;
char attributeToTenant[MAX_TENANT_ATTRIBUTE_LENGTH] = ""; char attributeToTenant[MAX_TENANT_ATTRIBUTE_LENGTH] = "";
CmdType attributeCommandType = CMD_UNKNOWN; CmdType attributeCommandType = CMD_UNKNOWN;
int colocationGroupId = -1; int colocationGroupId = -1;
clock_t attributeToTenantStart = { 0 };
const char *SharedMemoryNameForMultiTenantMonitor = const char *SharedMemoryNameForMultiTenantMonitor =
"Shared memory for multi tenant monitor"; "Shared memory for multi tenant monitor";
@ -238,14 +237,7 @@ AttributeQueryIfAnnotated(const char *query_string, CmdType commandType)
tenantId = pstrdup(tenantId); tenantId = pstrdup(tenantId);
*tenantEnd = tenantEndTmp; *tenantEnd = tenantEndTmp;
if (MultiTenantMonitoringLogLevel != CITUS_LOG_LEVEL_OFF)
{
ereport(NOTICE, (errmsg("attributing query to tenant: %s",
quote_literal_cstr(tenantId))));
}
strcpy_s(attributeToTenant, sizeof(attributeToTenant), tenantId); strcpy_s(attributeToTenant, sizeof(attributeToTenant), tenantId);
attributeToTenantStart = clock();
} }
else else
{ {
@ -330,17 +322,7 @@ AttributeMetricsIfApplicable()
{ {
if (strcmp(attributeToTenant, "") != 0) if (strcmp(attributeToTenant, "") != 0)
{ {
clock_t end = { 0 };
end = clock();
time_t queryTime = time(0); time_t queryTime = time(0);
double cpu_time_used = ((double) (end - attributeToTenantStart)) / CLOCKS_PER_SEC;
if (MultiTenantMonitoringLogLevel != CITUS_LOG_LEVEL_OFF)
{
ereport(NOTICE, (errmsg("attribute cpu counter (%f) to tenant: %s",
cpu_time_used, attributeToTenant)));
}
MultiTenantMonitor *monitor = GetMultiTenantMonitor(); MultiTenantMonitor *monitor = GetMultiTenantMonitor();

View File

@ -264,5 +264,45 @@ SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, q
\c - - - :master_port \c - - - :master_port
SET search_path TO citus_stats_tenants; SET search_path TO citus_stats_tenants;
-- test logs
SET client_min_messages TO LOG;
SELECT count(*)>=0 FROM citus_stats_tenants;
?column?
---------------------------------------------------------------------
t
(1 row)
SET citus.multi_tenant_monitoring_log_level TO ERROR;
SELECT count(*)>=0 FROM citus_stats_tenants;
?column?
---------------------------------------------------------------------
t
(1 row)
SET citus.multi_tenant_monitoring_log_level TO OFF;
SELECT count(*)>=0 FROM citus_stats_tenants;
?column?
---------------------------------------------------------------------
t
(1 row)
SET citus.multi_tenant_monitoring_log_level TO LOG;
SELECT count(*)>=0 FROM citus_stats_tenants;
LOG: Generating citus_stats_tenants
CONTEXT: PL/pgSQL function citus_stats_tenants(boolean) line XX at RAISE
?column?
---------------------------------------------------------------------
t
(1 row)
SET citus.multi_tenant_monitoring_log_level TO DEBUG;
SELECT count(*)>=0 FROM citus_stats_tenants;
LOG: Generating citus_stats_tenants
CONTEXT: PL/pgSQL function citus_stats_tenants(boolean) line XX at RAISE
?column?
---------------------------------------------------------------------
t
(1 row)
SET client_min_messages TO ERROR; SET client_min_messages TO ERROR;
DROP SCHEMA citus_stats_tenants CASCADE; DROP SCHEMA citus_stats_tenants CASCADE;

View File

@ -96,5 +96,17 @@ SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, q
\c - - - :master_port \c - - - :master_port
SET search_path TO citus_stats_tenants; SET search_path TO citus_stats_tenants;
-- test logs
SET client_min_messages TO LOG;
SELECT count(*)>=0 FROM citus_stats_tenants;
SET citus.multi_tenant_monitoring_log_level TO ERROR;
SELECT count(*)>=0 FROM citus_stats_tenants;
SET citus.multi_tenant_monitoring_log_level TO OFF;
SELECT count(*)>=0 FROM citus_stats_tenants;
SET citus.multi_tenant_monitoring_log_level TO LOG;
SELECT count(*)>=0 FROM citus_stats_tenants;
SET citus.multi_tenant_monitoring_log_level TO DEBUG;
SELECT count(*)>=0 FROM citus_stats_tenants;
SET client_min_messages TO ERROR; SET client_min_messages TO ERROR;
DROP SCHEMA citus_stats_tenants CASCADE; DROP SCHEMA citus_stats_tenants CASCADE;