temp - local query monitoring

pull/6763/head
Gokhan Gulbiz 2023-03-22 11:03:13 +03:00
parent 174f9574a1
commit 125532e98a
No known key found for this signature in database
GPG Key ID: 608EF06B6BD1B45B
3 changed files with 31 additions and 14 deletions

View File

@ -400,6 +400,8 @@ SetTaskQueryIfShouldLazyDeparse(Task *task, Query *query)
task->taskQuery.queryType = TASK_QUERY_OBJECT; task->taskQuery.queryType = TASK_QUERY_OBJECT;
task->taskQuery.data.jobQueryReferenceForLazyDeparsing = query; task->taskQuery.data.jobQueryReferenceForLazyDeparsing = query;
task->queryCount = 1; task->queryCount = 1;
AttributeTask(task->partitionColumn, task->colocationId, query->commandType);
return; return;
} }

View File

@ -23,7 +23,8 @@
#include "utils/builtins.h" #include "utils/builtins.h"
#include "utils/json.h" #include "utils/json.h"
#include "distributed/utils/attribute.h" #include "distributed/utils/attribute.h"
#include "common/base64.h" #include "miscadmin.h"
#include <time.h> #include <time.h>
@ -172,8 +173,6 @@ AttributeQueryIfAnnotated(const char *query_string, CmdType commandType)
{ {
strcpy_s(attributeToTenant, sizeof(attributeToTenant), ""); strcpy_s(attributeToTenant, sizeof(attributeToTenant), "");
attributeCommandType = commandType;
if (query_string == NULL) if (query_string == NULL)
{ {
return; return;
@ -187,28 +186,43 @@ AttributeQueryIfAnnotated(const char *query_string, CmdType commandType)
Datum jsonbDatum = DirectFunctionCall1(jsonb_in, PointerGetDatum(annotation)); Datum jsonbDatum = DirectFunctionCall1(jsonb_in, PointerGetDatum(annotation));
text *tenantIdTextP = ExtractFieldTextP(jsonbDatum, "tId"); text *tenantIdTextP = ExtractFieldTextP(jsonbDatum, "tId");
char *tenantId = NULL;
if (tenantIdTextP != NULL) if (tenantIdTextP != NULL)
{ {
char *tenantId = UnescapeCommentChars(text_to_cstring(tenantIdTextP)); tenantId = UnescapeCommentChars(text_to_cstring(tenantIdTextP));
strcpy_s(attributeToTenant, sizeof(attributeToTenant), tenantId);
} }
colocationGroupId = ExtractFieldInt32(jsonbDatum, "cId", 0); int colocationId = ExtractFieldInt32(jsonbDatum, "cId",
0);
if (MultiTenantMonitoringLogLevel != CITUS_LOG_LEVEL_OFF) AttributeTask(tenantId, colocationId, commandType);
{
ereport(NOTICE, (errmsg(
"attributing query to tenant: %s, colocationGroupId: %d",
quote_literal_cstr(attributeToTenant),
colocationGroupId)));
}
} }
} }
}
/*
* AttributeTask assigns the given attributes of a tenant and starts a timer
*/
void AttributeTask(char *tenantId, int colocationId, CmdType commandType)
{
ereport(NOTICE, (errmsg("MyProcPid: %d", MyProcPid)));
sleep(10);
colocationGroupId = colocationId;
strcpy_s(attributeToTenant, sizeof(attributeToTenant), tenantId);
attributeCommandType = commandType;
if (MultiTenantMonitoringLogLevel != CITUS_LOG_LEVEL_OFF)
{
ereport(NOTICE, (errmsg(
"attributing query to tenant: %s, colocationGroupId: %d",
quote_literal_cstr(attributeToTenant),
colocationGroupId)));
}
attributeToTenantStart = clock(); attributeToTenantStart = clock();
} }
/* /*
* AnnotateQuery annotates the query with tenant attributes. * AnnotateQuery annotates the query with tenant attributes.
*/ */

View File

@ -56,6 +56,7 @@ extern void CitusAttributeToEnd(QueryDesc *queryDesc);
extern void AttributeQueryIfAnnotated(const char *queryString, CmdType commandType); extern void AttributeQueryIfAnnotated(const char *queryString, CmdType commandType);
extern char * AnnotateQuery(char *queryString, char *partitionColumn, int colocationId); extern char * AnnotateQuery(char *queryString, char *partitionColumn, int colocationId);
extern void InitializeMultiTenantMonitorSMHandleManagement(void); extern void InitializeMultiTenantMonitorSMHandleManagement(void);
extern void AttributeTask(char *tenantId, int colocationGroupId, CmdType commandType);
extern ExecutorEnd_hook_type prev_ExecutorEnd; extern ExecutorEnd_hook_type prev_ExecutorEnd;