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

ensure config name in golang config and ctx matching C++ config name #1437

Merged
merged 1 commit into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
17 changes: 0 additions & 17 deletions core/go_pipeline/LogtailPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,6 @@ int LogtailPlugin::SendPbV2(const char* configName,
return 0;
}
} else {
if (!GetRealConfigName(configNameStr)) {
return -2;
}
shared_ptr<Pipeline> p = PipelineManager::GetInstance()->FindPipelineByName(configNameStr);
if (!p) {
LOG_INFO(sLogger,
Expand All @@ -270,9 +267,6 @@ int LogtailPlugin::ExecPluginCmd(
return -2;
}
string configNameStr(configName, configNameSize);
if (!GetRealConfigName(configNameStr)) {
return -2;
}
string paramsStr(params, paramsLen);
PluginCmdType cmdType = (PluginCmdType)cmdId;
LOG_DEBUG(sLogger, ("exec cmd", cmdType)("config", configNameStr)("detail", paramsStr));
Expand Down Expand Up @@ -565,14 +559,3 @@ K8sContainerMeta LogtailPlugin::GetContainerMeta(const string& containerID) {
}
return K8sContainerMeta();
}

bool LogtailPlugin::GetRealConfigName(std::string& name) {
// all Go pipeline name should end with "/1" or "/2"
size_t len = name.size();
if (len <= 2) {
LOG_ERROR(sLogger, ("invalid Go pipeline name", "something wrong happend")("config", name));
return false;
}
name = name.substr(0, len - 2);
return true;
}
2 changes: 0 additions & 2 deletions core/go_pipeline/LogtailPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,6 @@ class LogtailPlugin {
K8sContainerMeta GetContainerMeta(const std::string& containerID);

private:
static bool GetRealConfigName(std::string& name);

void* mPluginBasePtr;
void* mPluginAdapterPtr;

Expand Down
8 changes: 8 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,11 @@ func DeserializeLoadedConfig(cfg []byte) ([]*LoadedConfig, error) {
}
return c, nil
}

func GetRealConfigName(configName string) string {
realConfigName := configName
if len(configName) > 2 && (configName[len(configName)-2:] == "/1" || configName[len(configName)-2:] == "/2") {
realConfigName = configName[:len(configName)-2]
}
return realConfigName
}
3 changes: 2 additions & 1 deletion pkg/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package pkg
import (
"context"

"github.com/alibaba/ilogtail/pkg/config"
"github.com/alibaba/ilogtail/pkg/util"
)

Expand All @@ -39,7 +40,7 @@ func NewLogtailContextMeta(project, logstore, configName string) (context.Contex
meta := &LogtailContextMeta{
project: project,
logstore: logstore,
configName: configName,
configName: config.GetRealConfigName(configName),
alarm: new(util.Alarm),
}
if len(logstore) == 0 {
Expand Down
10 changes: 8 additions & 2 deletions pluginmanager/checkpoint_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,19 @@ func (p *checkPointManager) keyMatch(key []byte) bool {
logger.Error(context.Background(), "CHECKPOINT_ALARM", "key format not match, key", keyStr)
return false
}
_, existFlag := LogtailConfig[keyStr[0:index]]
configName := keyStr[0:index]
// configName in checkpoint is real config Name, while configName in LogtailConfig has suffix '/1' or '/2'
// since checkpoint is only used in input, so configName can only be 'realConfigName/1', meaning go pipeline with input
if len(configName) >= 2 && configName[len(configName)-2:len(configName)-1] == "/" {
configName += "/1"
}
_, existFlag := LogtailConfig[configName]
if existFlag {
return true
}
DisabledLogtailConfigLock.Lock()
defer DisabledLogtailConfigLock.Unlock()
_, existFlag = DisabledLogtailConfig[keyStr[0:index]]
_, existFlag = DisabledLogtailConfig[configName]
return existFlag
}

Expand Down
7 changes: 1 addition & 6 deletions pluginmanager/context_imp.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,7 @@ func (p *ContextImp) MetricSerializeToPB(log *protocol.Log) {

func (p *ContextImp) SaveCheckPoint(key string, value []byte) error {
logger.Debug(p.ctx, "save checkpoint, key", key, "value", string(value))
configName := p.GetConfigName()
l := len(configName)
if l > 2 && configName[l-2:] == "/1" {
configName = configName[:l-2]
}
return CheckPointManager.SaveCheckpoint(configName, key, value)
return CheckPointManager.SaveCheckpoint(p.GetConfigName(), key, value)
}

func (p *ContextImp) GetCheckPoint(key string) (value []byte, exist bool) {
Expand Down
2 changes: 1 addition & 1 deletion pluginmanager/logstore_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ func createLogstoreConfig(project string, logstore string, configName string, lo
logstoreC := &LogstoreConfig{
ProjectName: project,
LogstoreName: logstore,
ConfigName: configName,
ConfigName: config.GetRealConfigName(configName),
LogstoreKey: logstoreKey,
Context: contextImp,
configDetailHash: fmt.Sprintf("%x", md5.Sum([]byte(jsonStr))), //nolint:gosec
Expand Down
Loading