2222
2323#include " common/Flags.h"
2424#include " common/ParamExtractor.h"
25+ #include " common/TimeKeeper.h"
2526#include " grpcpp/support/status.h"
2627#include " logger/Logger.h"
2728#include " models/PipelineEventGroup.h"
@@ -69,6 +70,20 @@ bool LoongSuiteForwardServiceImpl::Update(std::string configName, const Json::Va
6970 return true ;
7071}
7172
73+ LoongSuiteForwardServiceImpl::LoongSuiteForwardServiceImpl (const std::string& address) : BaseService(address) {
74+ WriteMetrics::GetInstance ()->CreateMetricsRecordRef (mMetricsRecordRef ,
75+ MetricCategory::METRIC_CATEGORY_COMPONENT,
76+ {
77+ {METRIC_LABEL_KEY_COMPONENT_NAME, " loongsuite_forward" },
78+ {METRIC_LABEL_KEY_SERVICE_ADDRESS, address},
79+ });
80+ mInEventsTotal = mMetricsRecordRef .CreateCounter (METRIC_COMPONENT_IN_EVENTS_TOTAL);
81+ mInSizeBytes = mMetricsRecordRef .CreateCounter (METRIC_COMPONENT_IN_SIZE_BYTES);
82+ mTotalDelayMs = mMetricsRecordRef .CreateTimeCounter (METRIC_COMPONENT_TOTAL_DELAY_MS);
83+ mDiscardedEventsTotal = mMetricsRecordRef .CreateCounter (METRIC_COMPONENT_DISCARDED_ITEMS_TOTAL);
84+ WriteMetrics::GetInstance ()->CommitMetricsRecordRef (mMetricsRecordRef );
85+ }
86+
7287bool LoongSuiteForwardServiceImpl::Remove (std::string configName, const Json::Value& config) {
7388 std::string errorMsg;
7489
@@ -89,6 +104,9 @@ grpc::ServerUnaryReactor* LoongSuiteForwardServiceImpl::Forward(grpc::CallbackSe
89104 LoongSuiteForwardResponse* response) {
90105 auto * reactor = context->DefaultReactor ();
91106 grpc::Status status (grpc::StatusCode::NOT_FOUND, " No matching config found for forward request" );
107+ ADD_COUNTER (mInEventsTotal , 1 );
108+ ADD_COUNTER (mInSizeBytes , request->data_size ());
109+ auto before = TimeKeeper::GetInstance ()->NowMs ();
92110
93111 std::shared_ptr<ForwardConfig> config;
94112 if (FindMatchingConfig (context, config)) {
@@ -99,10 +117,13 @@ grpc::ServerUnaryReactor* LoongSuiteForwardServiceImpl::Forward(grpc::CallbackSe
99117 if (status.ok ()) {
100118 mRetryTimeController .UpRetryTimes (config->configName );
101119 } else {
120+ ADD_COUNTER (mDiscardedEventsTotal , 1 );
102121 mRetryTimeController .DownRetryTimes (config->configName );
103122 }
123+ } else {
124+ ADD_COUNTER (mDiscardedEventsTotal , 1 );
104125 }
105-
126+ ADD_COUNTER ( mTotalDelayMs , std::chrono::milliseconds ( TimeKeeper::GetInstance ()-> NowMs () - before));
106127 reactor->Finish (status);
107128 return reactor;
108129}
0 commit comments