Turn tracking off by default

Turn it back on for in tests
Also address some reviews
multi-tenant-monitoring-pgbench
Halil Ozan Akgul 2023-04-04 16:33:36 +03:00
parent 14ad3eff54
commit 5c47c97bef
5 changed files with 37 additions and 26 deletions

View File

@ -2412,7 +2412,7 @@ RegisterCitusConfigVariables(void)
"Disables when set to 'none'. Disabling can be useful for " "Disables when set to 'none'. Disabling can be useful for "
"avoiding extra CPU cycles needed for the calculations."), "avoiding extra CPU cycles needed for the calculations."),
&StatTenantsTrack, &StatTenantsTrack,
STAT_TENANTS_TRACK_ALL, STAT_TENANTS_TRACK_NONE,
stat_tenants_track_options, stat_tenants_track_options,
PGC_SUSET, PGC_SUSET,
GUC_STANDARD, GUC_STANDARD,

View File

@ -41,16 +41,14 @@ ExecutorEnd_hook_type prev_ExecutorEnd = NULL;
#define STAT_TENANTS_COLUMNS 7 #define STAT_TENANTS_COLUMNS 7
#define ONE_QUERY_SCORE 1000000000 #define ONE_QUERY_SCORE 1000000000
/* TODO maybe needs to be a stack */ static char AttributeToTenant[MAX_TENANT_ATTRIBUTE_LENGTH] = "";
char attributeToTenant[MAX_TENANT_ATTRIBUTE_LENGTH] = ""; static CmdType AttributeToCommandType = CMD_UNKNOWN;
CmdType attributeToCommandType = CMD_UNKNOWN; static int AttributeToColocationGroupId = INVALID_COLOCATION_ID;
int attributeToColocationGroupId = INVALID_COLOCATION_ID;
const char *SharedMemoryNameForMultiTenantMonitor = static const char *SharedMemoryNameForMultiTenantMonitor =
"Shared memory for multi tenant monitor"; "Shared memory for multi tenant monitor";
static char *TenantTrancheName = "Tenant Tranche";
char *tenantTrancheName = "Tenant Tranche"; static char *MonitorTrancheName = "Multi Tenant Monitor Tranche";
char *monitorTrancheName = "Multi Tenant Monitor Tranche";
static shmem_startup_hook_type prev_shmem_startup_hook = NULL; static shmem_startup_hook_type prev_shmem_startup_hook = NULL;
@ -73,7 +71,7 @@ static char * UnescapeCommentChars(const char *str);
int StatTenantsLogLevel = CITUS_LOG_LEVEL_OFF; int StatTenantsLogLevel = CITUS_LOG_LEVEL_OFF;
int StatTenantsPeriod = (time_t) 60; int StatTenantsPeriod = (time_t) 60;
int StatTenantsLimit = 10; int StatTenantsLimit = 10;
int StatTenantsTrack = STAT_TENANTS_TRACK_ALL; int StatTenantsTrack = STAT_TENANTS_TRACK_NONE;
PG_FUNCTION_INFO_V1(citus_stat_tenants_local); PG_FUNCTION_INFO_V1(citus_stat_tenants_local);
@ -181,7 +179,7 @@ AttributeQueryIfAnnotated(const char *query_string, CmdType commandType)
return; return;
} }
strcpy_s(attributeToTenant, sizeof(attributeToTenant), ""); strcpy_s(AttributeToTenant, sizeof(AttributeToTenant), "");
if (query_string == NULL) if (query_string == NULL)
{ {
@ -223,10 +221,10 @@ AttributeTask(char *tenantId, int colocationId, CmdType commandType)
return; return;
} }
attributeToColocationGroupId = colocationId; AttributeToColocationGroupId = colocationId;
strncpy_s(attributeToTenant, MAX_TENANT_ATTRIBUTE_LENGTH, tenantId, strncpy_s(AttributeToTenant, MAX_TENANT_ATTRIBUTE_LENGTH, tenantId,
MAX_TENANT_ATTRIBUTE_LENGTH - 1); MAX_TENANT_ATTRIBUTE_LENGTH - 1);
attributeToCommandType = commandType; AttributeToCommandType = commandType;
} }
@ -313,7 +311,7 @@ static void
AttributeMetricsIfApplicable() AttributeMetricsIfApplicable()
{ {
if (StatTenantsTrack == STAT_TENANTS_TRACK_NONE || if (StatTenantsTrack == STAT_TENANTS_TRACK_NONE ||
attributeToTenant[0] == '\0') AttributeToTenant[0] == '\0')
{ {
return; return;
} }
@ -381,7 +379,7 @@ AttributeMetricsIfApplicable()
} }
LWLockRelease(&monitor->lock); LWLockRelease(&monitor->lock);
strcpy_s(attributeToTenant, sizeof(attributeToTenant), ""); strcpy_s(AttributeToTenant, sizeof(AttributeToTenant), "");
} }
@ -516,13 +514,13 @@ RecordTenantStats(TenantStats *tenantStats)
tenantStats->score = LLONG_MAX; tenantStats->score = LLONG_MAX;
} }
if (attributeToCommandType == CMD_SELECT) if (AttributeToCommandType == CMD_SELECT)
{ {
tenantStats->readsInThisPeriod++; tenantStats->readsInThisPeriod++;
} }
else if (attributeToCommandType == CMD_UPDATE || else if (AttributeToCommandType == CMD_UPDATE ||
attributeToCommandType == CMD_INSERT || AttributeToCommandType == CMD_INSERT ||
attributeToCommandType == CMD_DELETE) AttributeToCommandType == CMD_DELETE)
{ {
tenantStats->writesInThisPeriod++; tenantStats->writesInThisPeriod++;
} }
@ -556,7 +554,7 @@ CreateSharedMemoryForMultiTenantMonitor()
} }
monitor->namedLockTranche.trancheId = LWLockNewTrancheId(); monitor->namedLockTranche.trancheId = LWLockNewTrancheId();
monitor->namedLockTranche.trancheName = monitorTrancheName; monitor->namedLockTranche.trancheName = MonitorTrancheName;
LWLockRegisterTranche(monitor->namedLockTranche.trancheId, LWLockRegisterTranche(monitor->namedLockTranche.trancheId,
monitor->namedLockTranche.trancheName); monitor->namedLockTranche.trancheName);
@ -633,11 +631,11 @@ CreateTenantStats(MultiTenantMonitor *monitor, TimestampTz queryTime)
memset(&monitor->tenants[tenantIndex], 0, sizeof(monitor->tenants[tenantIndex])); memset(&monitor->tenants[tenantIndex], 0, sizeof(monitor->tenants[tenantIndex]));
strcpy_s(monitor->tenants[tenantIndex].tenantAttribute, strcpy_s(monitor->tenants[tenantIndex].tenantAttribute,
sizeof(monitor->tenants[tenantIndex].tenantAttribute), attributeToTenant); sizeof(monitor->tenants[tenantIndex].tenantAttribute), AttributeToTenant);
monitor->tenants[tenantIndex].colocationGroupId = attributeToColocationGroupId; monitor->tenants[tenantIndex].colocationGroupId = AttributeToColocationGroupId;
monitor->tenants[tenantIndex].namedLockTranche.trancheId = LWLockNewTrancheId(); monitor->tenants[tenantIndex].namedLockTranche.trancheId = LWLockNewTrancheId();
monitor->tenants[tenantIndex].namedLockTranche.trancheName = tenantTrancheName; monitor->tenants[tenantIndex].namedLockTranche.trancheName = TenantTrancheName;
LWLockRegisterTranche(monitor->tenants[tenantIndex].namedLockTranche.trancheId, LWLockRegisterTranche(monitor->tenants[tenantIndex].namedLockTranche.trancheId,
monitor->tenants[tenantIndex].namedLockTranche.trancheName); monitor->tenants[tenantIndex].namedLockTranche.trancheName);
@ -659,8 +657,8 @@ FindTenantStats(MultiTenantMonitor *monitor)
for (int i = 0; i < monitor->tenantCount; i++) for (int i = 0; i < monitor->tenantCount; i++)
{ {
TenantStats *tenantStats = &monitor->tenants[i]; TenantStats *tenantStats = &monitor->tenants[i];
if (strcmp(tenantStats->tenantAttribute, attributeToTenant) == 0 && if (strcmp(tenantStats->tenantAttribute, AttributeToTenant) == 0 &&
tenantStats->colocationGroupId == attributeToColocationGroupId) tenantStats->colocationGroupId == AttributeToColocationGroupId)
{ {
return i; return i;
} }

View File

@ -2,6 +2,15 @@ CREATE SCHEMA citus_stat_tenants;
SET search_path TO citus_stat_tenants; SET search_path TO citus_stat_tenants;
SET citus.next_shard_id TO 5797500; SET citus.next_shard_id TO 5797500;
SET citus.shard_replication_factor TO 1; SET citus.shard_replication_factor TO 1;
-- make sure that we are tracking the tenant stats
SELECT result FROM run_command_on_all_nodes('SHOW citus.stat_tenants_track');
result
---------------------------------------------------------------------
all
all
all
(3 rows)
CREATE OR REPLACE FUNCTION pg_catalog.sleep_until_next_period() CREATE OR REPLACE FUNCTION pg_catalog.sleep_until_next_period()
RETURNS VOID RETURNS VOID
LANGUAGE C LANGUAGE C

View File

@ -490,6 +490,7 @@ push(@pgOptions, "citus.allow_unsafe_locks_from_workers=on");
push(@pgOptions, "citus.stat_statements_track = 'all'"); push(@pgOptions, "citus.stat_statements_track = 'all'");
push(@pgOptions, "citus.enable_change_data_capture=on"); push(@pgOptions, "citus.enable_change_data_capture=on");
push(@pgOptions, "citus.stat_tenants_limit = 10"); push(@pgOptions, "citus.stat_tenants_limit = 10");
push(@pgOptions, "citus.stat_tenants_track = 'ALL'");
# Some tests look at shards in pg_class, make sure we can usually see them: # Some tests look at shards in pg_class, make sure we can usually see them:
push(@pgOptions, "citus.show_shards_for_app_name_prefixes='pg_regress'"); push(@pgOptions, "citus.show_shards_for_app_name_prefixes='pg_regress'");

View File

@ -3,6 +3,9 @@ SET search_path TO citus_stat_tenants;
SET citus.next_shard_id TO 5797500; SET citus.next_shard_id TO 5797500;
SET citus.shard_replication_factor TO 1; SET citus.shard_replication_factor TO 1;
-- make sure that we are tracking the tenant stats
SELECT result FROM run_command_on_all_nodes('SHOW citus.stat_tenants_track');
CREATE OR REPLACE FUNCTION pg_catalog.sleep_until_next_period() CREATE OR REPLACE FUNCTION pg_catalog.sleep_until_next_period()
RETURNS VOID RETURNS VOID
LANGUAGE C LANGUAGE C