From 54b8c39944b6a3fe7f6c110ad435ae6c02b820dc Mon Sep 17 00:00:00 2001 From: henryzhx8 Date: Thu, 9 Jan 2025 06:33:42 +0000 Subject: [PATCH 1/2] disable group batch when flusher_sls.telemetrytype equals metrics --- core/plugin/flusher/sls/FlusherSLS.cpp | 12 ++++++++---- core/unittest/flusher/FlusherSLSUnittest.cpp | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/core/plugin/flusher/sls/FlusherSLS.cpp b/core/plugin/flusher/sls/FlusherSLS.cpp index b5b91c6704..9bb1f313b7 100644 --- a/core/plugin/flusher/sls/FlusherSLS.cpp +++ b/core/plugin/flusher/sls/FlusherSLS.cpp @@ -491,9 +491,13 @@ bool FlusherSLS::Init(const Json::Value& config, Json::Value& optionalGoPipeline static_cast(INT32_FLAG(batch_send_metric_size)), static_cast(INT32_FLAG(merge_log_count_limit)), static_cast(INT32_FLAG(batch_send_interval))}; - if (!mBatcher.Init( - itr ? *itr : Json::Value(), this, strategy, !mContext->IsExactlyOnceEnabled() && mShardHashKeys.empty())) { - // when either exactly once is enabled or ShardHashKeys is not empty, we don't enable group batch + if (!mBatcher.Init(itr ? *itr : Json::Value(), + this, + strategy, + !mContext->IsExactlyOnceEnabled() && mShardHashKeys.empty() + && mTelemetryType != sls_logs::SLS_TELEMETRY_TYPE_METRICS)) { + // when either exactly once is enabled or ShardHashKeys is not empty or telemetry type is not metrics, we don't + // enable group batch return false; } @@ -893,7 +897,7 @@ void FlusherSLS::OnSendDone(const HttpResponse& response, SenderQueueItem* item) } } #ifdef __ENTERPRISE__ - bool hasNetworkError = (sendResult == SEND_NETWORK_ERROR || sendResult == SEND_SERVER_ERROR); + bool hasNetworkError = sendResult == SEND_NETWORK_ERROR; EnterpriseSLSClientManager::GetInstance()->UpdateHostStatus( mProject, mCandidateHostsInfo->GetMode(), data->mCurrentHost, !hasNetworkError); mCandidateHostsInfo->SelectBestHost(); diff --git a/core/unittest/flusher/FlusherSLSUnittest.cpp b/core/unittest/flusher/FlusherSLSUnittest.cpp index 16849af139..073b859441 100644 --- a/core/unittest/flusher/FlusherSLSUnittest.cpp +++ b/core/unittest/flusher/FlusherSLSUnittest.cpp @@ -439,6 +439,24 @@ void FlusherSLSUnittest::OnSuccessfulInit() { ctx.SetExactlyOnceFlag(false); SenderQueueManager::GetInstance()->Clear(); + configStr = R"( + { + "Type": "flusher_sls", + "Project": "test_project", + "Logstore": "test_logstore", + "Region": "test_region", + "Endpoint": "test_region.log.aliyuncs.com", + "TelemetryType": "metrics" + } + )"; + APSARA_TEST_TRUE(ParseJsonTable(configStr, configJson, errorMsg)); + flusher.reset(new FlusherSLS()); + flusher->SetContext(ctx); + flusher->SetMetricsRecordRef(FlusherSLS::sName, "1"); + APSARA_TEST_TRUE(flusher->Init(configJson, optionalGoPipeline)); + APSARA_TEST_FALSE(flusher->mBatcher.GetGroupFlushStrategy().has_value()); + SenderQueueManager::GetInstance()->Clear(); + // go param ctx.SetIsFlushingThroughGoPipelineFlag(true); configStr = R"( From 94675fb889128b38331fa2f0ac05d136c28e3ea4 Mon Sep 17 00:00:00 2001 From: henryzhx8 Date: Fri, 10 Jan 2025 06:55:26 +0000 Subject: [PATCH 2/2] polish --- core/plugin/flusher/sls/FlusherSLS.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/plugin/flusher/sls/FlusherSLS.cpp b/core/plugin/flusher/sls/FlusherSLS.cpp index 9bb1f313b7..676f5fbc9b 100644 --- a/core/plugin/flusher/sls/FlusherSLS.cpp +++ b/core/plugin/flusher/sls/FlusherSLS.cpp @@ -496,7 +496,7 @@ bool FlusherSLS::Init(const Json::Value& config, Json::Value& optionalGoPipeline strategy, !mContext->IsExactlyOnceEnabled() && mShardHashKeys.empty() && mTelemetryType != sls_logs::SLS_TELEMETRY_TYPE_METRICS)) { - // when either exactly once is enabled or ShardHashKeys is not empty or telemetry type is not metrics, we don't + // when either exactly once is enabled or ShardHashKeys is not empty or telemetry type is metrics, we don't // enable group batch return false; }