Skip to content

Commit

Permalink
Add logs to citus_stats_tenants (#6762)
Browse files Browse the repository at this point in the history
Creates log message for citus_stats_tenants
  • Loading branch information
halilozanakgul committed Apr 5, 2023
1 parent ff0db22 commit 14487fd
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 18 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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((
Expand Down
18 changes: 0 additions & 18 deletions src/backend/distributed/utils/attribute.c
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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();

Expand Down
40 changes: 40 additions & 0 deletions src/test/regress/expected/citus_stats_tenants.out
Original file line number Diff line number Diff line change
Expand Up @@ -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;
12 changes: 12 additions & 0 deletions src/test/regress/sql/citus_stats_tenants.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit 14487fd

Please sign in to comment.