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

Add logs to citus_stats_tenants #6762

Merged
merged 1 commit into from
Mar 29, 2023
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

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;