From 7752a57580e8a02ce060067d554675bff52ad270 Mon Sep 17 00:00:00 2001 From: dmchen Date: Thu, 1 Feb 2024 07:26:05 +0000 Subject: [PATCH] not log null, memory leak, skip empty, default config --- source/common/src/tglobal.c | 2 +- source/libs/monitor/src/monFramework.c | 9 ++++-- source/libs/monitor/src/monMain.c | 13 ++++++--- .../monitorfw/src/taos_collector_registry.c | 29 ++++++++++++------- 4 files changed, 36 insertions(+), 17 deletions(-) diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index cb853c1a75..4a0a7a3a73 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -95,7 +95,7 @@ int32_t tsMonitorMaxLogs = 100; bool tsMonitorComp = false; bool tsMonitorLogProtocol = false; int32_t tsMonitorIntervalForBasic = 30; -bool tsMonitorForceV2 = false; +bool tsMonitorForceV2 = true; // audit bool tsEnableAudit = true; diff --git a/source/libs/monitor/src/monFramework.c b/source/libs/monitor/src/monFramework.c index 47912a188c..b1e6265906 100644 --- a/source/libs/monitor/src/monFramework.c +++ b/source/libs/monitor/src/monFramework.c @@ -638,8 +638,13 @@ void monSendPromReport() { char* promStr = NULL; char* pCont = (char *)taos_collector_registry_bridge_new(TAOS_COLLECTOR_REGISTRY_DEFAULT, ts, "%" PRId64, &promStr); if(tsMonitorLogProtocol){ - uInfoL("report cont:\n%s\n", pCont); - uDebugL("report cont prom:\n%s\n", promStr); + if(pCont != NULL){ + uInfoL("report cont:\n%s", pCont); + uDebugL("report cont prom:\n%s", promStr); + } + else{ + uInfo("report cont is null"); + } } if (pCont != NULL) { EHttpCompFlag flag = tsMonitor.cfg.comp ? HTTP_GZIP : HTTP_FLAT; diff --git a/source/libs/monitor/src/monMain.c b/source/libs/monitor/src/monMain.c index 22b53340e1..ba3db804c3 100644 --- a/source/libs/monitor/src/monMain.c +++ b/source/libs/monitor/src/monMain.c @@ -601,7 +601,12 @@ void monGenAndSendReport() { void monSendReportBasic(SMonInfo *pMonitor){ char *pCont = tjsonToString(pMonitor->pJson); if(tsMonitorLogProtocol){ - uInfoL("report cont basic:\n%s", pCont); + if(pCont != NULL){ + uInfoL("report cont basic:\n%s", pCont); + } + else{ + uInfo("report cont basic is null"); + } } if (pCont != NULL) { EHttpCompFlag flag = tsMonitor.cfg.comp ? HTTP_GZIP : HTTP_FLAT; @@ -614,13 +619,13 @@ void monSendReportBasic(SMonInfo *pMonitor){ void monGenAndSendReportBasic() { SMonInfo *pMonitor = monCreateMonitorInfo(); - if (pMonitor == NULL) return; - if (pMonitor->mmInfo.cluster.first_ep_dnode_id == 0) return; monGenBasicJsonBasic(pMonitor); monGenClusterJsonBasic(pMonitor); - monSendReportBasic(pMonitor); + if (pMonitor->mmInfo.cluster.first_ep_dnode_id != 0) { + monSendReportBasic(pMonitor); + } monCleanupMonitorInfo(pMonitor); } \ No newline at end of file diff --git a/source/libs/monitorfw/src/taos_collector_registry.c b/source/libs/monitorfw/src/taos_collector_registry.c index c94675c95c..acf2cb4248 100644 --- a/source/libs/monitorfw/src/taos_collector_registry.c +++ b/source/libs/monitorfw/src/taos_collector_registry.c @@ -234,6 +234,11 @@ const char *taos_collector_registry_bridge_new(taos_collector_registry_t *self, taos_metric_formatter_load_metrics_new(self->metric_formatter, self->collectors, ts, format, array); + if(tjsonGetArraySize(array) == 0){ + tjsonDelete(pJson); + return NULL; + } + //caller free this //generate prom protocol for debug if(prom_str != NULL){ @@ -245,36 +250,40 @@ const char *taos_collector_registry_bridge_new(taos_collector_registry_t *self, char* old_str = taos_string_builder_str(self->string_builder_batch); if(old_str[0] != '\0'){ r = taos_string_builder_add_str(self->string_builder_batch, ","); - if (r) return NULL; + if (r) goto _OVER; } char * item_str = tjsonToString(item); r = taos_string_builder_add_str(self->string_builder_batch, item_str); taos_free(item_str); - if (r) return NULL; - - tjsonDelete(pJson); + if (r) goto _OVER;; //generate final array format result, ie, add [] to str in batch cache taos_string_builder_t* tmp_builder = taos_string_builder_new(); r = taos_string_builder_add_str(tmp_builder, "["); - if (r) return NULL; + if (r) goto _OVER;; r = taos_string_builder_add_str(tmp_builder, taos_string_builder_str(self->string_builder_batch)); - if (r) return NULL; + if (r) goto _OVER;; r = taos_string_builder_add_str(tmp_builder, "]"); - if (r) return NULL; + if (r) goto _OVER;; //caller free this char *data = taos_string_builder_dump(tmp_builder); - if (data == NULL) return NULL; + if (data == NULL) goto _OVER;; r = taos_string_builder_clear(tmp_builder); - if (r) return NULL; + if (r) goto _OVER;; r = taos_string_builder_destroy(tmp_builder); tmp_builder = NULL; - if (r) return NULL; + if (r) goto _OVER;; + tjsonDelete(pJson); return data; + +_OVER: + tjsonDelete(pJson); + + return NULL; }