Skip to content
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 flusher_sls_monitor #1944

Merged
merged 2 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/constants/Constants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const char* SLS_EMPTY_STR_FOR_INDEX = "\01";
// profile project
const std::string PROFILE_PROJECT = "profile_project";
const std::string PROFILE_PROJECT_REGION = "profile_project_region";
const std::string PROFILE_LOGSTORE = "profile_logstore";

// global config
const std::string GLOBAL_CONFIG_NODE = "config";
Expand Down
1 change: 1 addition & 0 deletions core/constants/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ extern const char* SLS_EMPTY_STR_FOR_INDEX;
// profile project
extern const std::string PROFILE_PROJECT;
extern const std::string PROFILE_PROJECT_REGION;
extern const std::string PROFILE_LOGSTORE;

// global config
extern const std::string GLOBAL_CONFIG_NODE;
Expand Down
3 changes: 0 additions & 3 deletions core/monitor/MetricManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ using namespace std;

namespace logtail {

const string METRIC_KEY_CATEGORY = "category";
const string METRIC_KEY_LABEL = "label";
const string METRIC_TOPIC_TYPE = "loongcollector_metric";
const string METRIC_EXPORT_TYPE_GO = "direct";
const string METRIC_EXPORT_TYPE_CPP = "cpp_provided";

Expand Down
2 changes: 0 additions & 2 deletions core/monitor/MetricManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@

namespace logtail {

extern const std::string METRIC_TOPIC_TYPE;

class WriteMetrics {
private:
WriteMetrics() = default;
Expand Down
1 change: 0 additions & 1 deletion core/monitor/SelfMonitorServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ void SelfMonitorServer::SendMetrics() {

PipelineEventGroup pipelineEventGroup(std::make_shared<SourceBuffer>());
pipelineEventGroup.SetTagNoCopy(LOG_RESERVED_KEY_SOURCE, LoongCollectorMonitor::mIpAddr);
pipelineEventGroup.SetTagNoCopy(LOG_RESERVED_KEY_TOPIC, METRIC_TOPIC_TYPE);
ReadAsPipelineEventGroup(pipelineEventGroup);

shared_ptr<Pipeline> pipeline
Expand Down
6 changes: 6 additions & 0 deletions core/pipeline/plugin/PluginRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
#include "plugin/flusher/blackhole/FlusherBlackHole.h"
#include "plugin/flusher/file/FlusherFile.h"
#include "plugin/flusher/sls/FlusherSLS.h"
#ifdef __ENTERPRISE__
#include "plugin/flusher/sls/EnterpriseFlusherSLSMonitor.h"
#endif
#include "plugin/input/InputContainerStdio.h"
#include "plugin/input/InputFile.h"
#include "plugin/input/InputPrometheus.h"
Expand Down Expand Up @@ -160,6 +163,9 @@ void PluginRegistry::LoadStaticPlugins() {
RegisterFlusherCreator(new StaticFlusherCreator<FlusherSLS>());
RegisterFlusherCreator(new StaticFlusherCreator<FlusherBlackHole>());
RegisterFlusherCreator(new StaticFlusherCreator<FlusherFile>());
#ifdef __ENTERPRISE__
RegisterFlusherCreator(new StaticFlusherCreator<FlusherSLSMonitor>());
#endif
}

void PluginRegistry::LoadDynamicPlugins(const set<string>& plugins) {
Expand Down
20 changes: 20 additions & 0 deletions core/plugin/flusher/sls/FlusherSLS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ mutex FlusherSLS::sProjectRefCntMapLock;
unordered_map<string, int32_t> FlusherSLS::sProjectRefCntMap;
mutex FlusherSLS::sRegionRefCntMapLock;
unordered_map<string, int32_t> FlusherSLS::sRegionRefCntMap;
mutex FlusherSLS::sProjectRegionMapLock;
unordered_map<string, string> FlusherSLS::sProjectRegionMap;


string FlusherSLS::GetAllProjects() {
string result;
Expand Down Expand Up @@ -261,6 +264,21 @@ void FlusherSLS::DecreaseRegionReferenceCnt(const string& region) {
}
}

std::string FlusherSLS::GetProjectRegion(const std::string& project) {
lock_guard<mutex> lock(sProjectRefCntMapLock);
return sProjectRegionMap[project];
}

void FlusherSLS::SetProjectRegion(const std::string& project, const std::string& region) {
lock_guard<mutex> lock(sProjectRefCntMapLock);
sProjectRegionMap[project] = region;
}

void FlusherSLS::RemoveProjectRegion(const std::string& project) {
lock_guard<mutex> lock(sProjectRefCntMapLock);
sProjectRegionMap.erase(project);
}

mutex FlusherSLS::sRegionStatusLock;
unordered_map<string, bool> FlusherSLS::sAllRegionStatus;

Expand Down Expand Up @@ -542,6 +560,7 @@ bool FlusherSLS::Start() {

IncreaseProjectReferenceCnt(mProject);
IncreaseRegionReferenceCnt(mRegion);
SetProjectRegion(mProject, mRegion);
Takuka0311 marked this conversation as resolved.
Show resolved Hide resolved
SLSClientManager::GetInstance()->IncreaseAliuidReferenceCntForRegion(mRegion, mAliuid);
return true;
}
Expand All @@ -551,6 +570,7 @@ bool FlusherSLS::Stop(bool isPipelineRemoving) {

DecreaseProjectReferenceCnt(mProject);
DecreaseRegionReferenceCnt(mRegion);
RemoveProjectRegion(mProject);
SLSClientManager::GetInstance()->DecreaseAliuidReferenceCntForRegion(mRegion, mAliuid);
return true;
}
Expand Down
5 changes: 5 additions & 0 deletions core/plugin/flusher/sls/FlusherSLS.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class FlusherSLS : public HttpFlusher {
static void SetDefaultRegion(const std::string& region);
static std::string GetAllProjects();
static bool IsRegionContainingConfig(const std::string& region);
static std::string GetProjectRegion(const std::string& project);

// TODO: should be moved to enterprise config provider
static bool GetRegionStatus(const std::string& region);
Expand Down Expand Up @@ -94,6 +95,8 @@ class FlusherSLS : public HttpFlusher {
static void DecreaseProjectReferenceCnt(const std::string& project);
static void IncreaseRegionReferenceCnt(const std::string& region);
static void DecreaseRegionReferenceCnt(const std::string& region);
static void SetProjectRegion(const std::string& project, const std::string& region);
static void RemoveProjectRegion(const std::string& project);

static std::mutex sMux;
static std::unordered_map<std::string, std::weak_ptr<ConcurrencyLimiter>> sProjectConcurrencyLimiterMap;
Expand All @@ -107,6 +110,8 @@ class FlusherSLS : public HttpFlusher {
static std::unordered_map<std::string, int32_t> sProjectRefCntMap;
static std::mutex sRegionRefCntMapLock;
static std::unordered_map<std::string, int32_t> sRegionRefCntMap;
static std::mutex sProjectRegionMapLock;
static std::unordered_map<std::string, std::string> sProjectRegionMap;

// TODO: should be moved to enterprise config provider
static std::mutex sRegionStatusLock;
Expand Down
Loading