Skip to content

Commit

Permalink
fix SelfMonitorServer bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Takuka0311 committed Nov 26, 2024
1 parent ad9870e commit 56e22f8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
34 changes: 15 additions & 19 deletions core/monitor/SelfMonitorServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,44 +107,40 @@ void SelfMonitorServer::SendMetrics() {
}
}

void UpdateSelfMonitorMetricEventByRule(SelfMonitorMetricEvent& event,
SelfMonitorMetricEventMap& eventMap,
SelfMonitorMetricRule& rule) {
bool SelfMonitorServer::ProcessSelfMonitorMetricEvent(SelfMonitorMetricEvent& event, const SelfMonitorMetricRule& rule) {
if (!rule.mEnable) {
if (eventMap.find(event.mKey) != eventMap.end()) {
eventMap.erase(event.mKey);
if (mSelfMonitorMetricEventMap.find(event.mKey) != mSelfMonitorMetricEventMap.end()) {
mSelfMonitorMetricEventMap.erase(event.mKey);
}
return;
};
return false;
}
event.SetInterval(rule.mInterval);
return true;
}

void SelfMonitorServer::PushSelfMonitorMetricEvents(std::vector<SelfMonitorMetricEvent>& events) {
for (auto event : events) {
bool shouldSkip = false;
if (event.mCategory == MetricCategory::METRIC_CATEGORY_AGENT) {
UpdateSelfMonitorMetricEventByRule(
event, mSelfMonitorMetricEventMap, mSelfMonitorMetricRules->mAgentMetricsRule);
shouldSkip = !ProcessSelfMonitorMetricEvent(event, mSelfMonitorMetricRules->mAgentMetricsRule);
}
if (event.mCategory == MetricCategory::METRIC_CATEGORY_RUNNER) {
UpdateSelfMonitorMetricEventByRule(
event, mSelfMonitorMetricEventMap, mSelfMonitorMetricRules->mRunnerMetricsRule);
shouldSkip = !ProcessSelfMonitorMetricEvent(event, mSelfMonitorMetricRules->mRunnerMetricsRule);
}
if (event.mCategory == MetricCategory::METRIC_CATEGORY_COMPONENT) {
UpdateSelfMonitorMetricEventByRule(
event, mSelfMonitorMetricEventMap, mSelfMonitorMetricRules->mComponentMetricsRule);
shouldSkip = !ProcessSelfMonitorMetricEvent(event, mSelfMonitorMetricRules->mComponentMetricsRule);
}
if (event.mCategory == MetricCategory::METRIC_CATEGORY_PIPELINE) {
UpdateSelfMonitorMetricEventByRule(
event, mSelfMonitorMetricEventMap, mSelfMonitorMetricRules->mPipelineMetricsRule);
shouldSkip = !ProcessSelfMonitorMetricEvent(event, mSelfMonitorMetricRules->mPipelineMetricsRule);
}
if (event.mCategory == MetricCategory::METRIC_CATEGORY_PLUGIN) {
UpdateSelfMonitorMetricEventByRule(
event, mSelfMonitorMetricEventMap, mSelfMonitorMetricRules->mPluginMetricsRule);
shouldSkip = !ProcessSelfMonitorMetricEvent(event, mSelfMonitorMetricRules->mPluginMetricsRule);
}
if (event.mCategory == MetricCategory::METRIC_CATEGORY_PLUGIN_SOURCE) {
UpdateSelfMonitorMetricEventByRule(
event, mSelfMonitorMetricEventMap, mSelfMonitorMetricRules->mPluginSourceMetricsRule);
shouldSkip = !ProcessSelfMonitorMetricEvent(event, mSelfMonitorMetricRules->mPluginSourceMetricsRule);
}
if (shouldSkip) continue;

if (mSelfMonitorMetricEventMap.find(event.mKey) != mSelfMonitorMetricEventMap.end()) {
mSelfMonitorMetricEventMap[event.mKey].Merge(event);
} else {
Expand Down
1 change: 1 addition & 0 deletions core/monitor/SelfMonitorServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class SelfMonitorServer {
std::condition_variable mStopCV;

void SendMetrics();
bool ProcessSelfMonitorMetricEvent(SelfMonitorMetricEvent& event, const SelfMonitorMetricRule& rule);
void PushSelfMonitorMetricEvents(std::vector<SelfMonitorMetricEvent>& events);
void ReadAsPipelineEventGroup(PipelineEventGroup& pipelineEventGroup);

Expand Down

0 comments on commit 56e22f8

Please sign in to comment.