Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Abingcbc committed Jan 10, 2025
1 parent f99bcb1 commit dfed5d9
Show file tree
Hide file tree
Showing 52 changed files with 693 additions and 1,074 deletions.
1 change: 0 additions & 1 deletion core/common/CircularBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

#include "MemoryBarrier.h"
#include "Semaphore.h"
#include "common/TimeUtil.h"

namespace logtail {

Expand Down
55 changes: 55 additions & 0 deletions core/common/ParamExtractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,59 @@ bool IsValidMap(const Json::Value& config, const string& key, string& errorMsg)
return true;
}


string ParseDefaultAddedTag(const Json::Value* config,
const string& configField,
const string& defaultTagKeyValue,
const PipelineContext& context,
const string& pluginType) {
string errorMsg;
string customTagKey = DEFAULT_CONFIG_TAG_KEY_VALUE;
if (config && config->isMember(configField)) {
if (!GetOptionalStringParam(*config, configField, customTagKey, errorMsg)) {
PARAM_WARNING_DEFAULT(context.GetLogger(),
context.GetAlarm(),
errorMsg,
"__default__",
pluginType,
context.GetConfigName(),
context.GetProjectName(),
context.GetLogstoreName(),
context.GetRegion());
}
if (customTagKey == DEFAULT_CONFIG_TAG_KEY_VALUE) {
return defaultTagKeyValue;
}
return customTagKey;
}
return defaultTagKeyValue;
}

string ParseOptionalTag(const Json::Value* config,
const string& configField,
const string& defaultTagKeyValue,
const PipelineContext& context,
const string& pluginType) {
string errorMsg;
string customTagKey;
if (config && config->isMember(configField)) {
if (!GetOptionalStringParam(*config, configField, customTagKey, errorMsg)) {
PARAM_WARNING_DEFAULT(context.GetLogger(),
context.GetAlarm(),
errorMsg,
"__default__",
pluginType,
context.GetConfigName(),
context.GetProjectName(),
context.GetLogstoreName(),
context.GetRegion());
}
if (customTagKey == DEFAULT_CONFIG_TAG_KEY_VALUE) {
return defaultTagKeyValue;
}
return customTagKey;
}
return "";
}

} // namespace logtail
14 changes: 12 additions & 2 deletions core/common/ParamExtractor.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
#include "json/json.h"

#include "common/StringTools.h"
#include "constants/TagConstants.h"
#include "logger/Logger.h"
#include "monitor/AlarmManager.h"
#include "pipeline/PipelineContext.h"

#define PARAM_ERROR_RETURN(logger, alarm, msg, module, config, project, logstore, region) \
if (module.empty()) { \
Expand Down Expand Up @@ -325,6 +327,14 @@ bool IsValidList(const Json::Value& config, const std::string& key, std::string&

bool IsValidMap(const Json::Value& config, const std::string& key, std::string& errorMsg);

bool IsKeyExist(const Json::Value& config, const std::string& key);

std::string ParseDefaultAddedTag(const Json::Value* config,
const std::string& configField,
const std::string& defaultTagKeyValue,
const PipelineContext& context,
const std::string& pluginType);
std::string ParseOptionalTag(const Json::Value* config,
const std::string& configField,
const std::string& defaultTagKeyValue,
const PipelineContext& context,
const std::string& pluginType);
} // namespace logtail
83 changes: 0 additions & 83 deletions core/common/TagConstants.h

This file was deleted.

36 changes: 36 additions & 0 deletions core/constants/TagConstants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,29 @@

namespace logtail {

const std::string& TagKeyToString(TagKey key) {
static const std::vector<std::string> TagKeyDefaultValue = {
DEFAULT_LOG_TAG_FILE_OFFSET,
DEFAULT_LOG_TAG_FILE_INODE,
DEFAULT_LOG_TAG_FILE_PATH,
DEFAULT_LOG_TAG_NAMESPACE,
DEFAULT_LOG_TAG_POD_NAME,
DEFAULT_LOG_TAG_POD_UID,
DEFAULT_LOG_TAG_CONTAINER_NAME,
DEFAULT_LOG_TAG_CONTAINER_IP,
DEFAULT_LOG_TAG_IMAGE_NAME,
DEFAULT_LOG_TAG_HOST_NAME,
DEFAULT_LOG_TAG_HOST_ID,
DEFAULT_LOG_TAG_CLOUD_PROVIDER,
#ifndef __ENTERPRISE__
DEFAULT_LOG_TAG_HOST_IP,
#else
DEFAULT_LOG_TAG_USER_DEFINED_ID,
#endif
};
return TagKeyDefaultValue[key];
}

////////////////////////// COMMON ////////////////////////
const std::string DEFAULT_TAG_NAMESPACE = "namespace";
const std::string DEFAULT_TAG_HOST_NAME = "host_name";
Expand All @@ -26,6 +49,8 @@ const std::string DEFAULT_TAG_CONTAINER_NAME = "container_name";
const std::string DEFAULT_TAG_CONTAINER_IP = "container_ip";
const std::string DEFAULT_TAG_IMAGE_NAME = "image_name";

const std::string DEFAULT_CONFIG_TAG_KEY_VALUE = "__default__";

////////////////////////// LOG ////////////////////////
#ifndef __ENTERPRISE__ // 开源版
const std::string DEFAULT_LOG_TAG_HOST_NAME = DEFAULT_TAG_HOST_NAME;
Expand All @@ -38,8 +63,11 @@ const std::string DEFAULT_LOG_TAG_IMAGE_NAME = DEFAULT_TAG_IMAGE_NAME;
const std::string DEFAULT_LOG_TAG_FILE_OFFSET = "file_offset";
const std::string DEFAULT_LOG_TAG_FILE_INODE = "file_inode";
const std::string DEFAULT_LOG_TAG_FILE_PATH = "file_path";
const std::string DEFAULT_LOG_TAG_TOPIC = "topic";

const std::string DEFAULT_LOG_TAG_HOST_IP = DEFAULT_TAG_HOST_IP;
const std::string DEFAULT_LOG_TAG_HOST_ID = "host_id";
const std::string DEFAULT_LOG_TAG_CLOUD_PROVIDER = "cloud_provider";
#else
const std::string DEFAULT_LOG_TAG_HOST_NAME = "__hostname__";
const std::string DEFAULT_LOG_TAG_NAMESPACE = "_namespace_";
Expand All @@ -51,10 +79,18 @@ const std::string DEFAULT_LOG_TAG_IMAGE_NAME = "_image_name_";
const std::string DEFAULT_LOG_TAG_FILE_OFFSET = "__file_offset__";
const std::string DEFAULT_LOG_TAG_FILE_INODE = "__inode__";
const std::string DEFAULT_LOG_TAG_FILE_PATH = "__path__";
const std::string DEFAULT_LOG_TAG_TOPIC = "__topic__";
const std::string DEFAULT_LOG_TAG_HOST_ID = "__host_id__";
const std::string DEFAULT_LOG_TAG_CLOUD_PROVIDER = "__cloud_provider__";

const std::string DEFAULT_LOG_TAG_USER_DEFINED_ID = "__user_defined_id__";
#endif

const std::string LOG_RESERVED_KEY_SOURCE = "__source__";
const std::string LOG_RESERVED_KEY_TOPIC = "__topic__";
const std::string LOG_RESERVED_KEY_MACHINE_UUID = "__machine_uuid__";
const std::string LOG_RESERVED_KEY_PACKAGE_ID = "__pack_id__";

////////////////////////// METRIC ////////////////////////
const std::string DEFAULT_METRIC_TAG_NAMESPACE = DEFAULT_TAG_NAMESPACE;
const std::string DEFAULT_METRIC_TAG_POD_NAME = DEFAULT_TAG_POD_NAME;
Expand Down
34 changes: 34 additions & 0 deletions core/constants/TagConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,35 @@

#pragma once
#include <string>
#include <vector>

namespace logtail {

enum TagKey : int {
FILE_OFFSET_KEY,
FILE_INODE_TAG_KEY,
FILE_PATH_TAG_KEY,
K8S_NAMESPACE_TAG_KEY,
K8S_POD_NAME_TAG_KEY,
K8S_POD_UID_TAG_KEY,
CONTAINER_NAME_TAG_KEY,
CONTAINER_IP_TAG_KEY,
CONTAINER_IMAGE_NAME_TAG_KEY,
HOST_NAME,
HOST_ID,
CLOUD_PROVIDER,
#ifndef __ENTERPRISE__
HOST_IP,
#else
AGENT_TAG,
#endif
};

const std::string& TagKeyToString(TagKey key);

////////////////////////// COMMON ////////////////////////
extern const std::string DEFAULT_CONFIG_TAG_KEY_VALUE;

////////////////////////// LOG ////////////////////////
extern const std::string DEFAULT_LOG_TAG_HOST_NAME;
extern const std::string DEFAULT_LOG_TAG_NAMESPACE;
Expand All @@ -30,12 +56,20 @@ extern const std::string DEFAULT_LOG_TAG_IMAGE_NAME;
extern const std::string DEFAULT_LOG_TAG_FILE_OFFSET;
extern const std::string DEFAULT_LOG_TAG_FILE_INODE;
extern const std::string DEFAULT_LOG_TAG_FILE_PATH;
extern const std::string DEFAULT_LOG_TAG_TOPIC;
extern const std::string DEFAULT_LOG_TAG_HOST_ID;
extern const std::string DEFAULT_LOG_TAG_CLOUD_PROVIDER;
#ifndef __ENTERPRISE__
extern const std::string DEFAULT_LOG_TAG_HOST_IP;
#else
extern const std::string DEFAULT_LOG_TAG_USER_DEFINED_ID;
#endif

extern const std::string LOG_RESERVED_KEY_SOURCE;
extern const std::string LOG_RESERVED_KEY_TOPIC;
extern const std::string LOG_RESERVED_KEY_MACHINE_UUID;
extern const std::string LOG_RESERVED_KEY_PACKAGE_ID;

////////////////////////// METRIC ////////////////////////
extern const std::string DEFAULT_METRIC_TAG_NAMESPACE;
extern const std::string DEFAULT_METRIC_TAG_POD_NAME;
Expand Down
Loading

0 comments on commit dfed5d9

Please sign in to comment.