From f01d166b3c0b4f2bdc90b5313fc9a0867cdf1e74 Mon Sep 17 00:00:00 2001 From: dmchen Date: Tue, 10 Sep 2024 03:40:38 +0000 Subject: [PATCH 1/6] enh/TD-31977-monitor-qid --- include/libs/audit/audit.h | 1 + include/libs/monitor/monitor.h | 1 + include/util/tuuid.h | 11 +++++++++++ source/dnode/mgmt/node_mgmt/src/dmNodes.c | 6 ++++++ source/dnode/mgmt/node_util/inc/dmUtil.h | 1 + source/dnode/mgmt/node_util/src/dmUtil.c | 2 ++ source/libs/audit/inc/auditInt.h | 1 + source/libs/audit/src/auditMain.c | 2 ++ source/libs/monitor/inc/monInt.h | 1 + source/libs/monitor/src/monFramework.c | 7 +++++-- source/libs/monitor/src/monMain.c | 18 ++++++++++++++---- source/util/src/tuuid.c | 15 +++++++++++++++ 12 files changed, 60 insertions(+), 6 deletions(-) diff --git a/include/libs/audit/audit.h b/include/libs/audit/audit.h index 4fa69f1b4f..1af8093fcf 100644 --- a/include/libs/audit/audit.h +++ b/include/libs/audit/audit.h @@ -49,6 +49,7 @@ typedef struct { } SAuditRecord; int32_t auditInit(const SAuditCfg *pCfg); +void auditOpen(int32_t dnodeId); void auditCleanup(); int32_t auditSend(SJson *pJson); void auditRecord(SRpcMsg *pReq, int64_t clusterId, char *operation, char *target1, char *target2, diff --git a/include/libs/monitor/monitor.h b/include/libs/monitor/monitor.h index 96ac53ef4e..b64cf223be 100644 --- a/include/libs/monitor/monitor.h +++ b/include/libs/monitor/monitor.h @@ -218,6 +218,7 @@ typedef struct { } SDmNotifyHandle; int32_t monInit(const SMonCfg *pCfg); +void monOpen(int32_t dnodeId); void monInitVnode(); void monCleanup(); void monRecordLog(int64_t ts, ELogLevel level, const char *content); diff --git a/include/util/tuuid.h b/include/util/tuuid.h index 315c2ad497..a4e1059371 100644 --- a/include/util/tuuid.h +++ b/include/util/tuuid.h @@ -37,3 +37,14 @@ int32_t tGenIdPI32(void); * @return */ int64_t tGenIdPI64(void); + +/** + * Generate an qid + *+------------+-----+-----------+---------------+ + *| nodeid| 0| serial number | 0 | + *+------------+-----+-----------+---------------+ + *| 8bit | 16bit|32bit |8bit | + *+------------+-----+-----------+---------------+ + * @return + */ +int64_t tGenQid64(int8_t dnodeId); diff --git a/source/dnode/mgmt/node_mgmt/src/dmNodes.c b/source/dnode/mgmt/node_mgmt/src/dmNodes.c index 38bd9f6b92..84a6ba0399 100644 --- a/source/dnode/mgmt/node_mgmt/src/dmNodes.c +++ b/source/dnode/mgmt/node_mgmt/src/dmNodes.c @@ -15,6 +15,9 @@ #define _DEFAULT_SOURCE #include "dmMgmt.h" +#include "dmUtil.h" +#include "monitor.h" +#include "audit.h" int32_t dmOpenNode(SMgmtWrapper *pWrapper) { int32_t code = 0; @@ -98,6 +101,9 @@ static int32_t dmOpenNodes(SDnode *pDnode) { } } + auditOpen(dmGetDnodeId(&pDnode->data)); + monOpen(dmGetDnodeId(&pDnode->data)); + dmSetStatus(pDnode, DND_STAT_RUNNING); return 0; } diff --git a/source/dnode/mgmt/node_util/inc/dmUtil.h b/source/dnode/mgmt/node_util/inc/dmUtil.h index 425f10392f..b5842acbad 100644 --- a/source/dnode/mgmt/node_util/inc/dmUtil.h +++ b/source/dnode/mgmt/node_util/inc/dmUtil.h @@ -217,6 +217,7 @@ int32_t dmInitDndInfo(SDnodeData *pData); // dmEps.c int32_t dmGetDnodeSize(SDnodeData *pData); +int32_t dmGetDnodeId(SDnodeData *pData); int32_t dmReadEps(SDnodeData *pData); int32_t dmWriteEps(SDnodeData *pData); void dmUpdateEps(SDnodeData *pData, SArray *pDnodeEps); diff --git a/source/dnode/mgmt/node_util/src/dmUtil.c b/source/dnode/mgmt/node_util/src/dmUtil.c index 68f4c9d0ff..13096d7cb8 100644 --- a/source/dnode/mgmt/node_util/src/dmUtil.c +++ b/source/dnode/mgmt/node_util/src/dmUtil.c @@ -66,3 +66,5 @@ void dmGetMonitorSystemInfo(SMonSysInfo *pInfo) { taosGetCardInfoDelta(&pInfo->net_in, &pInfo->net_out); taosGetProcIODelta(&pInfo->io_read, &pInfo->io_write, &pInfo->io_read_disk, &pInfo->io_write_disk); } + +int32_t dmGetDnodeId(SDnodeData *pData) { return pData->dnodeId; } \ No newline at end of file diff --git a/source/libs/audit/inc/auditInt.h b/source/libs/audit/inc/auditInt.h index e5fed2e473..7af48e3d41 100644 --- a/source/libs/audit/inc/auditInt.h +++ b/source/libs/audit/inc/auditInt.h @@ -23,6 +23,7 @@ typedef struct { SAuditCfg cfg; SArray *records; TdThreadMutex lock; + int32_t dnodeId; } SAudit; #endif /*_TD_AUDIT_INT_H_*/ diff --git a/source/libs/audit/src/auditMain.c b/source/libs/audit/src/auditMain.c index cdc4a964c7..2b1b0e648d 100644 --- a/source/libs/audit/src/auditMain.c +++ b/source/libs/audit/src/auditMain.c @@ -36,6 +36,8 @@ int32_t auditInit(const SAuditCfg *pCfg) { return taosThreadMutexInit(&tsAudit.lock, NULL); } +void auditOpen(int32_t dnodeId) { tsAudit.dnodeId = dnodeId; } + static FORCE_INLINE void auditDeleteRecord(SAuditRecord * record) { if (record) { taosMemoryFree(record->detail); diff --git a/source/libs/monitor/inc/monInt.h b/source/libs/monitor/inc/monInt.h index 7fc718393b..e7d2552e57 100644 --- a/source/libs/monitor/inc/monInt.h +++ b/source/libs/monitor/inc/monInt.h @@ -47,6 +47,7 @@ typedef struct { SMonQmInfo qmInfo; SMonBmInfo bmInfo; SHashObj *metrics; + int32_t dnodeId; } SMonitor; void monGenClusterInfoTable(SMonInfo *pMonitor); diff --git a/source/libs/monitor/src/monFramework.c b/source/libs/monitor/src/monFramework.c index c3b63787a6..fe32754160 100644 --- a/source/libs/monitor/src/monFramework.c +++ b/source/libs/monitor/src/monFramework.c @@ -767,9 +767,12 @@ void monSendPromReport() { } if (pCont != NULL) { EHttpCompFlag flag = tsMonitor.cfg.comp ? HTTP_GZIP : HTTP_FLAT; - if (taosSendHttpReport(tsMonitor.cfg.server, tsMonFwUri, tsMonitor.cfg.port, pCont, strlen(pCont), flag) != 0) { + char tmp[100] = {0}; + (void)sprintf(tmp, "%s?qid=%" PRId64, tsMonFwUri, tGenQid64(tsMonitor.dnodeId)); + uDebug("report cont to %s", tmp); + if (taosSendHttpReport(tsMonitor.cfg.server, tmp, tsMonitor.cfg.port, pCont, strlen(pCont), flag) != 0) { uError("failed to send monitor msg"); - }else{ + } else { (void)taos_collector_registry_clear_batch(TAOS_COLLECTOR_REGISTRY_DEFAULT); } taosMemoryFreeClear(pCont); diff --git a/source/libs/monitor/src/monMain.c b/source/libs/monitor/src/monMain.c index 14d62fbf0e..84d0806c4f 100644 --- a/source/libs/monitor/src/monMain.c +++ b/source/libs/monitor/src/monMain.c @@ -131,6 +131,8 @@ int32_t monInit(const SMonCfg *pCfg) { return 0; } +void monOpen(int32_t dnodeId) { tsMonitor.dnodeId = dnodeId; } + void monInitVnode() { if (!tsEnableMonitor || tsMonitorFqdn[0] == 0 || tsMonitorPort == 0) return; if (tsInsertCounter == NULL) { @@ -599,7 +601,10 @@ void monSendReport(SMonInfo *pMonitor) { } if (pCont != NULL) { EHttpCompFlag flag = tsMonitor.cfg.comp ? HTTP_GZIP : HTTP_FLAT; - if (taosSendHttpReport(tsMonitor.cfg.server, tsMonUri, tsMonitor.cfg.port, pCont, strlen(pCont), flag) != 0) { + char tmp[100] = {0}; + (void)sprintf(tmp, "%s?qid=%" PRId64, tsMonUri, tGenQid64(tsMonitor.dnodeId)); + uDebug("report cont to %s", tmp); + if (taosSendHttpReport(tsMonitor.cfg.server, tmp, tsMonitor.cfg.port, pCont, strlen(pCont), flag) != 0) { uError("failed to send monitor msg"); } taosMemoryFree(pCont); @@ -617,8 +622,10 @@ void monSendReportBasic(SMonInfo *pMonitor) { } if (pCont != NULL) { EHttpCompFlag flag = tsMonitor.cfg.comp ? HTTP_GZIP : HTTP_FLAT; - if (taosSendHttpReport(tsMonitor.cfg.server, tsMonFwBasicUri, tsMonitor.cfg.port, pCont, strlen(pCont), flag) != - 0) { + char tmp[100] = {0}; + (void)sprintf(tmp, "%s?qid=%" PRId64, tsMonFwBasicUri, tGenQid64(tsMonitor.dnodeId)); + uDebug("report cont basic to %s", tmp); + if (taosSendHttpReport(tsMonitor.cfg.server, tmp, tsMonitor.cfg.port, pCont, strlen(pCont), flag) != 0) { uError("failed to send monitor msg"); } taosMemoryFree(pCont); @@ -669,8 +676,11 @@ void monSendContent(char *pCont, const char *uri) { } } if (pCont != NULL) { + char tmp[100] = {0}; + (void)sprintf(tmp, "%s?qid=%" PRId64, uri, tGenQid64(tsMonitor.dnodeId)); + uInfoL("report client cont to %s", tmp); EHttpCompFlag flag = tsMonitor.cfg.comp ? HTTP_GZIP : HTTP_FLAT; - if (taosSendHttpReport(tsMonitor.cfg.server, uri, tsMonitor.cfg.port, pCont, strlen(pCont), flag) != 0) { + if (taosSendHttpReport(tsMonitor.cfg.server, tmp, tsMonitor.cfg.port, pCont, strlen(pCont), flag) != 0) { uError("failed to send monitor msg"); } } diff --git a/source/util/src/tuuid.c b/source/util/src/tuuid.c index 9d749cc002..4472189d37 100644 --- a/source/util/src/tuuid.c +++ b/source/util/src/tuuid.c @@ -65,3 +65,18 @@ int64_t tGenIdPI64(void) { return id; } + +int64_t tGenQid64(int8_t dnodeId) { + int64_t id = dnodeId; + + while (true) { + int32_t val = atomic_add_fetch_32(&tUUIDSerialNo, 1); + + id = (id << 56) | (val & 0xFFFFF) << 8; + if (id) { + break; + } + } + + return id; +} \ No newline at end of file From c6d8bd733397d1babafa7cd99d9a1d8002175313 Mon Sep 17 00:00:00 2001 From: dmchen Date: Tue, 10 Sep 2024 09:49:36 +0000 Subject: [PATCH 2/6] ehn/TD-31977-move-qid-to-header --- include/libs/transport/thttp.h | 4 +- source/libs/monitor/src/monFramework.c | 7 ++- source/libs/monitor/src/monMain.c | 21 ++++--- source/libs/transport/src/thttp.c | 76 ++++++++++++++++++-------- 4 files changed, 72 insertions(+), 36 deletions(-) diff --git a/include/libs/transport/thttp.h b/include/libs/transport/thttp.h index a2f6b5ac8b..9f635b8523 100644 --- a/include/libs/transport/thttp.h +++ b/include/libs/transport/thttp.h @@ -28,9 +28,11 @@ typedef enum { HTTP_GZIP, HTTP_FLAT } EHttpCompFlag; int32_t taosSendHttpReport(const char* server, const char* uri, uint16_t port, char* pCont, int32_t contLen, EHttpCompFlag flag); +int32_t taosSendHttpReportWithQID(const char* server, const char* uri, uint16_t port, char* pCont, int32_t contLen, + EHttpCompFlag flag, const char* qid); int64_t taosInitHttpChan(); int32_t taosSendHttpReportByChan(const char* server, const char* uri, uint16_t port, char* pCont, int32_t contLen, - EHttpCompFlag flag, int64_t chanId); + EHttpCompFlag flag, int64_t chanId, const char* qid); void taosDestroyHttpChan(int64_t chanId); #ifdef __cplusplus diff --git a/source/libs/monitor/src/monFramework.c b/source/libs/monitor/src/monFramework.c index fe32754160..98de5eae57 100644 --- a/source/libs/monitor/src/monFramework.c +++ b/source/libs/monitor/src/monFramework.c @@ -768,9 +768,10 @@ void monSendPromReport() { if (pCont != NULL) { EHttpCompFlag flag = tsMonitor.cfg.comp ? HTTP_GZIP : HTTP_FLAT; char tmp[100] = {0}; - (void)sprintf(tmp, "%s?qid=%" PRId64, tsMonFwUri, tGenQid64(tsMonitor.dnodeId)); - uDebug("report cont to %s", tmp); - if (taosSendHttpReport(tsMonitor.cfg.server, tmp, tsMonitor.cfg.port, pCont, strlen(pCont), flag) != 0) { + (void)sprintf(tmp, "%" PRId64, tGenQid64(tsMonitor.dnodeId)); + uDebug("report cont with QID:%s", tmp); + if (taosSendHttpReportWithQID(tsMonitor.cfg.server, tsMonFwUri, tsMonitor.cfg.port, pCont, strlen(pCont), flag, + tmp) != 0) { uError("failed to send monitor msg"); } else { (void)taos_collector_registry_clear_batch(TAOS_COLLECTOR_REGISTRY_DEFAULT); diff --git a/source/libs/monitor/src/monMain.c b/source/libs/monitor/src/monMain.c index 84d0806c4f..fd70cd29ef 100644 --- a/source/libs/monitor/src/monMain.c +++ b/source/libs/monitor/src/monMain.c @@ -602,9 +602,10 @@ void monSendReport(SMonInfo *pMonitor) { if (pCont != NULL) { EHttpCompFlag flag = tsMonitor.cfg.comp ? HTTP_GZIP : HTTP_FLAT; char tmp[100] = {0}; - (void)sprintf(tmp, "%s?qid=%" PRId64, tsMonUri, tGenQid64(tsMonitor.dnodeId)); - uDebug("report cont to %s", tmp); - if (taosSendHttpReport(tsMonitor.cfg.server, tmp, tsMonitor.cfg.port, pCont, strlen(pCont), flag) != 0) { + (void)sprintf(tmp, "%" PRId64, tGenQid64(tsMonitor.dnodeId)); + uDebug("report cont with QID:%s", tmp); + if (taosSendHttpReportWithQID(tsMonitor.cfg.server, tsMonUri, tsMonitor.cfg.port, pCont, strlen(pCont), flag, + tmp) != 0) { uError("failed to send monitor msg"); } taosMemoryFree(pCont); @@ -623,9 +624,10 @@ void monSendReportBasic(SMonInfo *pMonitor) { if (pCont != NULL) { EHttpCompFlag flag = tsMonitor.cfg.comp ? HTTP_GZIP : HTTP_FLAT; char tmp[100] = {0}; - (void)sprintf(tmp, "%s?qid=%" PRId64, tsMonFwBasicUri, tGenQid64(tsMonitor.dnodeId)); - uDebug("report cont basic to %s", tmp); - if (taosSendHttpReport(tsMonitor.cfg.server, tmp, tsMonitor.cfg.port, pCont, strlen(pCont), flag) != 0) { + (void)sprintf(tmp, "%" PRId64, tGenQid64(tsMonitor.dnodeId)); + uDebug("report cont basic with QID:%s", tmp); + if (taosSendHttpReportWithQID(tsMonitor.cfg.server, tsMonFwBasicUri, tsMonitor.cfg.port, pCont, strlen(pCont), flag, + tmp) != 0) { uError("failed to send monitor msg"); } taosMemoryFree(pCont); @@ -677,10 +679,11 @@ void monSendContent(char *pCont, const char *uri) { } if (pCont != NULL) { char tmp[100] = {0}; - (void)sprintf(tmp, "%s?qid=%" PRId64, uri, tGenQid64(tsMonitor.dnodeId)); - uInfoL("report client cont to %s", tmp); + (void)sprintf(tmp, "%" PRId64, tGenQid64(tsMonitor.dnodeId)); + uInfoL("report client cont with QID:%s", tmp); EHttpCompFlag flag = tsMonitor.cfg.comp ? HTTP_GZIP : HTTP_FLAT; - if (taosSendHttpReport(tsMonitor.cfg.server, tmp, tsMonitor.cfg.port, pCont, strlen(pCont), flag) != 0) { + if (taosSendHttpReportWithQID(tsMonitor.cfg.server, uri, tsMonitor.cfg.port, pCont, strlen(pCont), flag, tmp) != + 0) { uError("failed to send monitor msg"); } } diff --git a/source/libs/transport/src/thttp.c b/source/libs/transport/src/thttp.c index d19877dbf1..3f04d8577c 100644 --- a/source/libs/transport/src/thttp.c +++ b/source/libs/transport/src/thttp.c @@ -53,6 +53,7 @@ typedef struct SHttpMsg { int8_t quit; int64_t chanId; int64_t seq; + char* qid; } SHttpMsg; typedef struct SHttpClient { @@ -81,7 +82,7 @@ static void httpHandleQuit(SHttpMsg* msg); static int32_t httpSendQuit(SHttpModule* http, int64_t chanId); static int32_t httpCreateMsg(const char* server, const char* uri, uint16_t port, char* pCont, int32_t contLen, - EHttpCompFlag flag, int64_t chanId, SHttpMsg** httpMsg); + EHttpCompFlag flag, int64_t chanId, const char* qid, SHttpMsg** httpMsg); static void httpDestroyMsg(SHttpMsg* msg); static bool httpFailFastShoudIgnoreMsg(SHashObj* pTable, char* server, int16_t port); @@ -91,31 +92,53 @@ static int32_t taosSendHttpReportImpl(const char* server, const char* uri, uint1 static void httpModuleDestroy(SHttpModule* http); static int32_t taosSendHttpReportImplByChan(const char* server, const char* uri, uint16_t port, char* pCont, - int32_t contLen, EHttpCompFlag flag, int64_t chanId); + int32_t contLen, EHttpCompFlag flag, int64_t chanId, const char* qid); -static int32_t taosBuildHttpHeader(const char* server, const char* uri, int32_t contLen, char* pHead, int32_t headLen, +static int32_t taosBuildHttpHeader(const char* server, const char* uri, int32_t contLen, const char* qid, char* pHead, + int32_t headLen, EHttpCompFlag flag) { int32_t code = 0; int32_t len = 0; if (flag == HTTP_FLAT) { - len = snprintf(pHead, headLen, - "POST %s HTTP/1.1\n" - "Host: %s\n" - "Content-Type: application/json\n" - "Content-Length: %d\n\n", - uri, server, contLen); + if (qid == NULL) { + len = snprintf(pHead, headLen, + "POST %s HTTP/1.1\n" + "Host: %s\n" + "Content-Type: application/json\n" + "Content-Length: %d\n\n", + uri, server, contLen); + } else { + len = snprintf(pHead, headLen, + "POST %s HTTP/1.1\n" + "Host: %s\n" + "X-QID: %s\n" + "Content-Type: application/json\n" + "Content-Length: %d\n\n", + uri, server, qid, contLen); + } if (len < 0 || len >= headLen) { code = TSDB_CODE_OUT_OF_RANGE; } } else if (flag == HTTP_GZIP) { - len = snprintf(pHead, headLen, - "POST %s HTTP/1.1\n" - "Host: %s\n" - "Content-Type: application/json\n" - "Content-Encoding: gzip\n" - "Content-Length: %d\n\n", - uri, server, contLen); + if (qid == NULL) { + len = snprintf(pHead, headLen, + "POST %s HTTP/1.1\n" + "Host: %s\n" + "Content-Type: application/json\n" + "Content-Encoding: gzip\n" + "Content-Length: %d\n\n", + uri, server, contLen); + } else { + len = snprintf(pHead, headLen, + "POST %s HTTP/1.1\n" + "Host: %s\n" + "X-QID: %s\n" + "Content-Type: application/json\n" + "Content-Encoding: gzip\n" + "Content-Length: %d\n\n", + uri, server, qid, contLen); + } if (len < 0 || len >= headLen) { code = TSDB_CODE_OUT_OF_RANGE; } @@ -218,7 +241,7 @@ static void* httpThread(void* arg) { } static int32_t httpCreateMsg(const char* server, const char* uri, uint16_t port, char* pCont, int32_t contLen, - EHttpCompFlag flag, int64_t chanId, SHttpMsg** httpMsg) { + EHttpCompFlag flag, int64_t chanId, const char* qid, SHttpMsg** httpMsg) { int64_t seqNum = atomic_fetch_add_64(&httpSeqNum, 1); if (server == NULL || uri == NULL) { tError("http-report failed to report to invalid addr, chanId:%" PRId64 ", seq:%" PRId64 "", chanId, seqNum); @@ -243,6 +266,7 @@ static int32_t httpCreateMsg(const char* server, const char* uri, uint16_t port, msg->server = taosStrdup(server); msg->uri = taosStrdup(uri); msg->cont = taosMemoryMalloc(contLen); + if (qid != NULL) msg->qid = taosStrdup(qid); if (msg->server == NULL || msg->uri == NULL || msg->cont == NULL) { httpDestroyMsg(msg); *httpMsg = NULL; @@ -263,6 +287,7 @@ static void httpDestroyMsg(SHttpMsg* msg) { taosMemoryFree(msg->server); taosMemoryFree(msg->uri); taosMemoryFree(msg->cont); + taosMemoryFree(msg->qid); taosMemoryFree(msg); } static void httpDestroyMsgWrapper(void* cont, void* param) { @@ -561,7 +586,7 @@ static void httpHandleReq(SHttpMsg* msg) { goto END; } - int32_t headLen = taosBuildHttpHeader(msg->server, msg->uri, msg->len, header, cap, msg->flag); + int32_t headLen = taosBuildHttpHeader(msg->server, msg->uri, msg->len, msg->qid, header, cap, msg->flag); if (headLen < 0) { code = headLen; goto END; @@ -675,10 +700,10 @@ void httpModuleDestroy2(SHttpModule* http) { } static int32_t taosSendHttpReportImplByChan(const char* server, const char* uri, uint16_t port, char* pCont, - int32_t contLen, EHttpCompFlag flag, int64_t chanId) { + int32_t contLen, EHttpCompFlag flag, int64_t chanId, const char* qid) { SHttpModule* load = NULL; SHttpMsg* msg = NULL; - int32_t code = httpCreateMsg(server, uri, port, pCont, contLen, flag, chanId, &msg); + int32_t code = httpCreateMsg(server, uri, port, pCont, contLen, flag, chanId, qid, &msg); if (code != 0) { goto _ERROR; } @@ -714,14 +739,19 @@ _ERROR: } int32_t taosSendHttpReportByChan(const char* server, const char* uri, uint16_t port, char* pCont, int32_t contLen, - EHttpCompFlag flag, int64_t chanId) { - return taosSendHttpReportImplByChan(server, uri, port, pCont, contLen, flag, chanId); + EHttpCompFlag flag, int64_t chanId, const char* qid) { + return taosSendHttpReportImplByChan(server, uri, port, pCont, contLen, flag, chanId, qid); } int32_t taosSendHttpReport(const char* server, const char* uri, uint16_t port, char* pCont, int32_t contLen, EHttpCompFlag flag) { + return taosSendHttpReportWithQID(server, uri, port, pCont, contLen, flag, NULL); +} + +int32_t taosSendHttpReportWithQID(const char* server, const char* uri, uint16_t port, char* pCont, int32_t contLen, + EHttpCompFlag flag, const char* qid) { (void)taosThreadOnce(&transHttpInit, transHttpEnvInit); - return taosSendHttpReportImplByChan(server, uri, port, pCont, contLen, flag, httpDefaultChanId); + return taosSendHttpReportImplByChan(server, uri, port, pCont, contLen, flag, httpDefaultChanId, qid); } static void transHttpDestroyHandle(void* handle) { taosMemoryFree(handle); } From 61a1a5a2cb8c5795bca840cb9a0954b49b4a9431 Mon Sep 17 00:00:00 2001 From: dmchen Date: Wed, 11 Sep 2024 03:50:05 +0000 Subject: [PATCH 3/6] enh/TD-31977-fix-case --- source/libs/monitor/src/monMain.c | 2 +- source/libs/transport/src/thttp.c | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/source/libs/monitor/src/monMain.c b/source/libs/monitor/src/monMain.c index fd70cd29ef..c6357d9b75 100644 --- a/source/libs/monitor/src/monMain.c +++ b/source/libs/monitor/src/monMain.c @@ -602,7 +602,7 @@ void monSendReport(SMonInfo *pMonitor) { if (pCont != NULL) { EHttpCompFlag flag = tsMonitor.cfg.comp ? HTTP_GZIP : HTTP_FLAT; char tmp[100] = {0}; - (void)sprintf(tmp, "%" PRId64, tGenQid64(tsMonitor.dnodeId)); + (void)snprintf(tmp, 100, "%" PRId64, tGenQid64(tsMonitor.dnodeId)); uDebug("report cont with QID:%s", tmp); if (taosSendHttpReportWithQID(tsMonitor.cfg.server, tsMonUri, tsMonitor.cfg.port, pCont, strlen(pCont), flag, tmp) != 0) { diff --git a/source/libs/transport/src/thttp.c b/source/libs/transport/src/thttp.c index 3f04d8577c..2c050469c1 100644 --- a/source/libs/transport/src/thttp.c +++ b/source/libs/transport/src/thttp.c @@ -266,7 +266,10 @@ static int32_t httpCreateMsg(const char* server, const char* uri, uint16_t port, msg->server = taosStrdup(server); msg->uri = taosStrdup(uri); msg->cont = taosMemoryMalloc(contLen); - if (qid != NULL) msg->qid = taosStrdup(qid); + if (qid != NULL) + msg->qid = taosStrdup(qid); + else + msg->qid = NULL; if (msg->server == NULL || msg->uri == NULL || msg->cont == NULL) { httpDestroyMsg(msg); *httpMsg = NULL; From 91de6700629c79a5c2b3ef0312360ff55358554e Mon Sep 17 00:00:00 2001 From: dmchen Date: Wed, 11 Sep 2024 08:29:38 +0000 Subject: [PATCH 4/6] en/TD-31977-fix-case --- source/libs/transport/src/thttp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/libs/transport/src/thttp.c b/source/libs/transport/src/thttp.c index 2c050469c1..724cc10933 100644 --- a/source/libs/transport/src/thttp.c +++ b/source/libs/transport/src/thttp.c @@ -290,7 +290,7 @@ static void httpDestroyMsg(SHttpMsg* msg) { taosMemoryFree(msg->server); taosMemoryFree(msg->uri); taosMemoryFree(msg->cont); - taosMemoryFree(msg->qid); + if (msg->qid != NULL) taosMemoryFree(msg->qid); taosMemoryFree(msg); } static void httpDestroyMsgWrapper(void* cont, void* param) { From f18926bf0de14cebefafd9b1313b8d3bfa1abc5d Mon Sep 17 00:00:00 2001 From: dmchen Date: Thu, 12 Sep 2024 01:35:22 +0000 Subject: [PATCH 5/6] enh/TD-31977-monitor-qid-fix-case --- source/libs/transport/src/thttp.c | 1 + 1 file changed, 1 insertion(+) diff --git a/source/libs/transport/src/thttp.c b/source/libs/transport/src/thttp.c index 724cc10933..a8c9b14b08 100644 --- a/source/libs/transport/src/thttp.c +++ b/source/libs/transport/src/thttp.c @@ -618,6 +618,7 @@ static void httpHandleReq(SHttpMsg* msg) { cli->chanId = chanId; cli->addr = msg->server; cli->port = msg->port; + if (msg->qid != NULL) taosMemoryFree(msg->qid); taosMemoryFree(msg->uri); taosMemoryFree(msg); From 86c2944ed9736cbe339106941697bf5c47a69ee0 Mon Sep 17 00:00:00 2001 From: dmchen Date: Wed, 18 Sep 2024 09:44:27 +0000 Subject: [PATCH 6/6] enh/TD-31977-monitor-qid-qid-format-set-dnodeid-when-first-start --- include/libs/audit/audit.h | 2 +- include/libs/monitor/monitor.h | 2 +- source/dnode/mgmt/mgmt_dnode/src/dmHandle.c | 4 ++++ source/dnode/mgmt/node_mgmt/src/dmNodes.c | 4 ++-- source/libs/audit/src/auditMain.c | 2 +- source/libs/monitor/src/monFramework.c | 2 +- source/libs/monitor/src/monMain.c | 8 ++++---- 7 files changed, 14 insertions(+), 10 deletions(-) diff --git a/include/libs/audit/audit.h b/include/libs/audit/audit.h index 1af8093fcf..2e786ab2b3 100644 --- a/include/libs/audit/audit.h +++ b/include/libs/audit/audit.h @@ -49,7 +49,7 @@ typedef struct { } SAuditRecord; int32_t auditInit(const SAuditCfg *pCfg); -void auditOpen(int32_t dnodeId); +void auditSetDnodeId(int32_t dnodeId); void auditCleanup(); int32_t auditSend(SJson *pJson); void auditRecord(SRpcMsg *pReq, int64_t clusterId, char *operation, char *target1, char *target2, diff --git a/include/libs/monitor/monitor.h b/include/libs/monitor/monitor.h index b64cf223be..636e7a3143 100644 --- a/include/libs/monitor/monitor.h +++ b/include/libs/monitor/monitor.h @@ -218,7 +218,7 @@ typedef struct { } SDmNotifyHandle; int32_t monInit(const SMonCfg *pCfg); -void monOpen(int32_t dnodeId); +void monSetDnodeId(int32_t dnodeId); void monInitVnode(); void monCleanup(); void monRecordLog(int64_t ts, ELogLevel level, const char *content); diff --git a/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c b/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c index 9c22a11674..61ffe334ed 100644 --- a/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c +++ b/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c @@ -14,7 +14,9 @@ */ #define _DEFAULT_SOURCE +#include "audit.h" #include "dmInt.h" +#include "monitor.h" #include "systable.h" #include "tchecksum.h" @@ -27,6 +29,8 @@ static void dmUpdateDnodeCfg(SDnodeMgmt *pMgmt, SDnodeCfg *pCfg) { (void)taosThreadRwlockWrlock(&pMgmt->pData->lock); pMgmt->pData->dnodeId = pCfg->dnodeId; pMgmt->pData->clusterId = pCfg->clusterId; + monSetDnodeId(pCfg->dnodeId); + auditSetDnodeId(pCfg->dnodeId); code = dmWriteEps(pMgmt->pData); if (code != 0) { dInfo("failed to set local info, dnodeId:%d clusterId:%" PRId64 " reason:%s", pCfg->dnodeId, pCfg->clusterId, diff --git a/source/dnode/mgmt/node_mgmt/src/dmNodes.c b/source/dnode/mgmt/node_mgmt/src/dmNodes.c index 84a6ba0399..f0f2410da2 100644 --- a/source/dnode/mgmt/node_mgmt/src/dmNodes.c +++ b/source/dnode/mgmt/node_mgmt/src/dmNodes.c @@ -101,8 +101,8 @@ static int32_t dmOpenNodes(SDnode *pDnode) { } } - auditOpen(dmGetDnodeId(&pDnode->data)); - monOpen(dmGetDnodeId(&pDnode->data)); + auditSetDnodeId(dmGetDnodeId(&pDnode->data)); + monSetDnodeId(dmGetDnodeId(&pDnode->data)); dmSetStatus(pDnode, DND_STAT_RUNNING); return 0; diff --git a/source/libs/audit/src/auditMain.c b/source/libs/audit/src/auditMain.c index 2b1b0e648d..52a4c1c523 100644 --- a/source/libs/audit/src/auditMain.c +++ b/source/libs/audit/src/auditMain.c @@ -36,7 +36,7 @@ int32_t auditInit(const SAuditCfg *pCfg) { return taosThreadMutexInit(&tsAudit.lock, NULL); } -void auditOpen(int32_t dnodeId) { tsAudit.dnodeId = dnodeId; } +void auditSetDnodeId(int32_t dnodeId) { tsAudit.dnodeId = dnodeId; } static FORCE_INLINE void auditDeleteRecord(SAuditRecord * record) { if (record) { diff --git a/source/libs/monitor/src/monFramework.c b/source/libs/monitor/src/monFramework.c index 98de5eae57..76473ccbb1 100644 --- a/source/libs/monitor/src/monFramework.c +++ b/source/libs/monitor/src/monFramework.c @@ -768,7 +768,7 @@ void monSendPromReport() { if (pCont != NULL) { EHttpCompFlag flag = tsMonitor.cfg.comp ? HTTP_GZIP : HTTP_FLAT; char tmp[100] = {0}; - (void)sprintf(tmp, "%" PRId64, tGenQid64(tsMonitor.dnodeId)); + (void)sprintf(tmp, "0x%" PRIxLEAST64, tGenQid64(tsMonitor.dnodeId)); uDebug("report cont with QID:%s", tmp); if (taosSendHttpReportWithQID(tsMonitor.cfg.server, tsMonFwUri, tsMonitor.cfg.port, pCont, strlen(pCont), flag, tmp) != 0) { diff --git a/source/libs/monitor/src/monMain.c b/source/libs/monitor/src/monMain.c index c6357d9b75..4808ae0fdf 100644 --- a/source/libs/monitor/src/monMain.c +++ b/source/libs/monitor/src/monMain.c @@ -131,7 +131,7 @@ int32_t monInit(const SMonCfg *pCfg) { return 0; } -void monOpen(int32_t dnodeId) { tsMonitor.dnodeId = dnodeId; } +void monSetDnodeId(int32_t dnodeId) { tsMonitor.dnodeId = dnodeId; } void monInitVnode() { if (!tsEnableMonitor || tsMonitorFqdn[0] == 0 || tsMonitorPort == 0) return; @@ -602,7 +602,7 @@ void monSendReport(SMonInfo *pMonitor) { if (pCont != NULL) { EHttpCompFlag flag = tsMonitor.cfg.comp ? HTTP_GZIP : HTTP_FLAT; char tmp[100] = {0}; - (void)snprintf(tmp, 100, "%" PRId64, tGenQid64(tsMonitor.dnodeId)); + (void)snprintf(tmp, 100, "0x%" PRIxLEAST64, tGenQid64(tsMonitor.dnodeId)); uDebug("report cont with QID:%s", tmp); if (taosSendHttpReportWithQID(tsMonitor.cfg.server, tsMonUri, tsMonitor.cfg.port, pCont, strlen(pCont), flag, tmp) != 0) { @@ -624,7 +624,7 @@ void monSendReportBasic(SMonInfo *pMonitor) { if (pCont != NULL) { EHttpCompFlag flag = tsMonitor.cfg.comp ? HTTP_GZIP : HTTP_FLAT; char tmp[100] = {0}; - (void)sprintf(tmp, "%" PRId64, tGenQid64(tsMonitor.dnodeId)); + (void)sprintf(tmp, "0x%" PRIxLEAST64, tGenQid64(tsMonitor.dnodeId)); uDebug("report cont basic with QID:%s", tmp); if (taosSendHttpReportWithQID(tsMonitor.cfg.server, tsMonFwBasicUri, tsMonitor.cfg.port, pCont, strlen(pCont), flag, tmp) != 0) { @@ -679,7 +679,7 @@ void monSendContent(char *pCont, const char *uri) { } if (pCont != NULL) { char tmp[100] = {0}; - (void)sprintf(tmp, "%" PRId64, tGenQid64(tsMonitor.dnodeId)); + (void)sprintf(tmp, "0x%" PRIxLEAST64, tGenQid64(tsMonitor.dnodeId)); uInfoL("report client cont with QID:%s", tmp); EHttpCompFlag flag = tsMonitor.cfg.comp ? HTTP_GZIP : HTTP_FLAT; if (taosSendHttpReportWithQID(tsMonitor.cfg.server, uri, tsMonitor.cfg.port, pCont, strlen(pCont), flag, tmp) !=