mirror of https://github.com/citusdata/citus.git
Add logs to citus_stats_tenants (#6762)
Creates log message for citus_stats_tenantsmulti-tenant-monitoring-pgbench
parent
4b99fd0a2d
commit
e0046d2d79
|
@ -14,6 +14,14 @@ CREATE OR REPLACE FUNCTION pg_catalog.citus_stats_tenants (
|
|||
LANGUAGE plpgsql
|
||||
AS $function$
|
||||
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
|
||||
SELECT *
|
||||
FROM jsonb_to_recordset((
|
||||
|
|
|
@ -14,6 +14,14 @@ CREATE OR REPLACE FUNCTION pg_catalog.citus_stats_tenants (
|
|||
LANGUAGE plpgsql
|
||||
AS $function$
|
||||
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
|
||||
SELECT *
|
||||
FROM jsonb_to_recordset((
|
||||
|
|
|
@ -40,7 +40,6 @@ ExecutorEnd_hook_type prev_ExecutorEnd = NULL;
|
|||
char attributeToTenant[MAX_TENANT_ATTRIBUTE_LENGTH] = "";
|
||||
CmdType attributeCommandType = CMD_UNKNOWN;
|
||||
int colocationGroupId = -1;
|
||||
clock_t attributeToTenantStart = { 0 };
|
||||
|
||||
const char *SharedMemoryNameForMultiTenantMonitor =
|
||||
"Shared memory for multi tenant monitor";
|
||||
|
@ -238,14 +237,7 @@ AttributeQueryIfAnnotated(const char *query_string, CmdType commandType)
|
|||
tenantId = pstrdup(tenantId);
|
||||
*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);
|
||||
attributeToTenantStart = clock();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -330,17 +322,7 @@ AttributeMetricsIfApplicable()
|
|||
{
|
||||
if (strcmp(attributeToTenant, "") != 0)
|
||||
{
|
||||
clock_t end = { 0 };
|
||||
|
||||
end = clock();
|
||||
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();
|
||||
|
||||
|
|
|
@ -264,5 +264,45 @@ SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, q
|
|||
|
||||
\c - - - :master_port
|
||||
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;
|
||||
DROP SCHEMA citus_stats_tenants CASCADE;
|
||||
|
|
|
@ -96,5 +96,17 @@ SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, q
|
|||
\c - - - :master_port
|
||||
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;
|
||||
DROP SCHEMA citus_stats_tenants CASCADE;
|
||||
|
|
Loading…
Reference in New Issue