-
Notifications
You must be signed in to change notification settings - Fork 399
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add InputInternalAlarms #2061
Open
Takuka0311
wants to merge
3
commits into
alibaba:main
Choose a base branch
from
Takuka0311:add-internal-alarm-input
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add InputInternalAlarms #2061
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,49 +107,12 @@ AlarmManager::AlarmManager() { | |
mMessageType[REGISTER_HANDLERS_TOO_SLOW_ALARM] = "REGISTER_HANDLERS_TOO_SLOW_ALARM"; | ||
} | ||
|
||
void AlarmManager::Init() { | ||
mThreadRes = async(launch::async, &AlarmManager::SendAlarmLoop, this); | ||
} | ||
|
||
void AlarmManager::Stop() { | ||
ForceToSend(); | ||
{ | ||
lock_guard<mutex> lock(mThreadRunningMux); | ||
mIsThreadRunning = false; | ||
} | ||
mStopCV.notify_one(); | ||
if (!mThreadRes.valid()) { | ||
return; | ||
} | ||
future_status s = mThreadRes.wait_for(chrono::seconds(1)); | ||
if (s == future_status::ready) { | ||
LOG_INFO(sLogger, ("alarm gathering", "stopped successfully")); | ||
} else { | ||
LOG_WARNING(sLogger, ("alarm gathering", "forced to stopped")); | ||
} | ||
} | ||
|
||
bool AlarmManager::SendAlarmLoop() { | ||
LOG_INFO(sLogger, ("alarm gathering", "started")); | ||
{ | ||
unique_lock<mutex> lock(mThreadRunningMux); | ||
while (mIsThreadRunning) { | ||
SendAllRegionAlarm(); | ||
if (mStopCV.wait_for(lock, std::chrono::seconds(3), [this]() { return !mIsThreadRunning; })) { | ||
break; | ||
} | ||
} | ||
} | ||
SendAllRegionAlarm(); | ||
return true; | ||
} | ||
|
||
void AlarmManager::SendAllRegionAlarm() { | ||
void AlarmManager::FlushAllRegionAlarm(vector<PipelineEventGroup>& pipelineEventGroupList) { | ||
int32_t currentTime = time(nullptr); | ||
size_t sendRegionIndex = 0; | ||
size_t sendAlarmTypeIndex = 0; | ||
do { | ||
LogGroup logGroup; | ||
PipelineEventGroup pipelineEventGroup(std::make_shared<SourceBuffer>()); | ||
string region; | ||
{ | ||
PTScopedLock lock(mAlarmBufferMutex); | ||
|
@@ -163,7 +126,8 @@ void AlarmManager::SendAllRegionAlarm() { | |
++allAlarmIter; | ||
} | ||
region = allAlarmIter->first; | ||
// LOG_DEBUG(sLogger, ("1Send Alarm", region)("region", sendRegionIndex)); | ||
pipelineEventGroup.SetMetadata(EventGroupMetaKey::TARGET_REGION, region); | ||
|
||
AlarmVector& alarmBufferVec = *(allAlarmIter->second.first); | ||
std::vector<int32_t>& lastUpdateTimeVec = allAlarmIter->second.second; | ||
// check this region end | ||
|
@@ -173,8 +137,7 @@ void AlarmManager::SendAllRegionAlarm() { | |
sendAlarmTypeIndex = 0; | ||
continue; | ||
} | ||
// LOG_DEBUG(sLogger, ("2Send Alarm", region)("region", sendRegionIndex)("alarm index", | ||
// mMessageType[sendAlarmTypeIndex])); | ||
|
||
// check valid | ||
if (alarmBufferVec.size() != (size_t)ALL_LOGTAIL_ALARM_NUM | ||
|| lastUpdateTimeVec.size() != (size_t)ALL_LOGTAIL_ALARM_NUM) { | ||
|
@@ -187,98 +150,46 @@ void AlarmManager::SendAllRegionAlarm() { | |
continue; | ||
} | ||
|
||
// LOG_DEBUG(sLogger, ("3Send Alarm", region)("region", sendRegionIndex)("alarm index", | ||
// mMessageType[sendAlarmTypeIndex])); | ||
map<string, unique_ptr<AlarmMessage>>& alarmMap = alarmBufferVec[sendAlarmTypeIndex]; | ||
if (alarmMap.size() == 0 | ||
|| currentTime - lastUpdateTimeVec[sendAlarmTypeIndex] < INT32_FLAG(logtail_alarm_interval)) { | ||
// go next alarm type | ||
++sendAlarmTypeIndex; | ||
continue; | ||
} | ||
// check sender queue status, if invalid jump this region | ||
|
||
string project = GetProfileSender()->GetProfileProjectName(region); | ||
QueueKey alarmPrjLogstoreKey | ||
= QueueKeyManager::GetInstance()->GetKey("-flusher_sls-" + project + "#" + ALARM_SLS_LOGSTORE_NAME); | ||
if (SenderQueueManager::GetInstance()->GetQueue(alarmPrjLogstoreKey) == nullptr) { | ||
CollectionPipelineContext ctx; | ||
SenderQueueManager::GetInstance()->CreateQueue( | ||
alarmPrjLogstoreKey, | ||
"self_monitor", | ||
ctx, | ||
{{"region", FlusherSLS::GetRegionConcurrencyLimiter(region)}, | ||
{"project", FlusherSLS::GetProjectConcurrencyLimiter(project)}, | ||
{"logstore", FlusherSLS::GetLogstoreConcurrencyLimiter(project, ALARM_SLS_LOGSTORE_NAME)}}); | ||
} | ||
if (!SenderQueueManager::GetInstance()->IsValidToPush(alarmPrjLogstoreKey)) { | ||
// jump this region | ||
++sendRegionIndex; | ||
sendAlarmTypeIndex = 0; | ||
continue; | ||
} | ||
|
||
// LOG_DEBUG(sLogger, ("4Send Alarm", region)("region", sendRegionIndex)("alarm index", | ||
// mMessageType[sendAlarmTypeIndex])); | ||
logGroup.set_source(LoongCollectorMonitor::mIpAddr); | ||
logGroup.set_category(ALARM_SLS_LOGSTORE_NAME); | ||
pipelineEventGroup.SetTagNoCopy(LOG_RESERVED_KEY_SOURCE, LoongCollectorMonitor::mIpAddr); | ||
pipelineEventGroup.SetTag(LOG_RESERVED_KEY_TOPIC, "__alarm__"); | ||
auto now = GetCurrentLogtailTime(); | ||
for (map<string, unique_ptr<AlarmMessage>>::iterator mapIter = alarmMap.begin(); mapIter != alarmMap.end(); | ||
++mapIter) { | ||
auto& messagePtr = mapIter->second; | ||
|
||
// LOG_DEBUG(sLogger, ("5Send Alarm", region)("region", sendRegionIndex)("alarm index", | ||
// sendAlarmTypeIndex)("msg", messagePtr->mMessage)); | ||
|
||
Log* logPtr = logGroup.add_logs(); | ||
SetLogTime(logPtr, | ||
AppConfig::GetInstance()->EnableLogTimeAutoAdjust() ? now.tv_sec + GetTimeDelta() | ||
: now.tv_sec); | ||
Log_Content* contentPtr = logPtr->add_contents(); | ||
contentPtr->set_key("alarm_type"); | ||
contentPtr->set_value(messagePtr->mMessageType); | ||
|
||
contentPtr = logPtr->add_contents(); | ||
contentPtr->set_key("alarm_message"); | ||
contentPtr->set_value(messagePtr->mMessage); | ||
|
||
contentPtr = logPtr->add_contents(); | ||
contentPtr->set_key("alarm_count"); | ||
contentPtr->set_value(ToString(messagePtr->mCount)); | ||
|
||
contentPtr = logPtr->add_contents(); | ||
contentPtr->set_key("ip"); | ||
contentPtr->set_value(LoongCollectorMonitor::mIpAddr); | ||
|
||
contentPtr = logPtr->add_contents(); | ||
contentPtr->set_key("os"); | ||
contentPtr->set_value(OS_NAME); | ||
|
||
contentPtr = logPtr->add_contents(); | ||
contentPtr->set_key("ver"); | ||
contentPtr->set_value(ILOGTAIL_VERSION); | ||
|
||
LogEvent* logEvent = pipelineEventGroup.AddLogEvent(); | ||
logEvent->SetTimestamp(AppConfig::GetInstance()->EnableLogTimeAutoAdjust() ? now.tv_sec + GetTimeDelta() | ||
: now.tv_sec); | ||
logEvent->SetContent("alarm_type", messagePtr->mMessageType); | ||
logEvent->SetContent("alarm_message", messagePtr->mMessage); | ||
logEvent->SetContent("alarm_count", ToString(messagePtr->mCount)); | ||
logEvent->SetContent("ip", LoongCollectorMonitor::mIpAddr); | ||
logEvent->SetContent("os", OS_NAME); | ||
logEvent->SetContent("ver", string(ILOGTAIL_VERSION)); | ||
if (!messagePtr->mProjectName.empty()) { | ||
contentPtr = logPtr->add_contents(); | ||
contentPtr->set_key("project_name"); | ||
contentPtr->set_value(messagePtr->mProjectName); | ||
logEvent->SetContent("project_name", messagePtr->mProjectName); | ||
} | ||
|
||
if (!messagePtr->mCategory.empty()) { | ||
contentPtr = logPtr->add_contents(); | ||
contentPtr->set_key("category"); | ||
contentPtr->set_value(messagePtr->mCategory); | ||
logEvent->SetContent("category", messagePtr->mCategory); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 设计上改造后能带上config吗 |
||
} | ||
} | ||
lastUpdateTimeVec[sendAlarmTypeIndex] = currentTime; | ||
alarmMap.clear(); | ||
++sendAlarmTypeIndex; | ||
} | ||
if (logGroup.logs_size() <= 0) { | ||
if (pipelineEventGroup.GetEvents().size() <= 0) { | ||
continue; | ||
} | ||
// this is an anonymous send and non lock send | ||
GetProfileSender()->SendToProfileProject(region, logGroup); | ||
pipelineEventGroupList.emplace_back(std::move(pipelineEventGroup)); | ||
} while (true); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alarm