1 Star 0 Fork 1

SmartSmallBoy/loongcollector_cpp

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
app_config
application
checkpoint
cix
collection_pipeline
common
config
config_server/protocol
constants
container_manager
ebpf
file_server
go_pipeline
host_monitor
logger
metadata
models
monitor
parser
plugin
prometheus
protobuf
protobuf_public/models
provider
runner
task_pipeline
tools
unittest
app_config
batch
checkpoint
common
compression
config
container_manager
controller
ebpf
event
event_handler
file_source
flusher
host_monitor
input
instance_config
log_pb
logger
metadata
models
monitor
pipeline
plugin
polling
processor
prometheus
provider
queue
reader
route
sender
serializer
spl
task_pipeline
CMakeLists.txt
Unittest.h
UnittestHelper.h
add_test_arg.py
loop_ut.bat
loop_ut.sh
report_failure.sh
run_ut.bat
run_ut.sh
xmake.lua
xmake
xmake_modules
.clang-format
.clang-tidy
.clangd
.gitignore
CMakeLists.txt
LICENSE
README.en.md
README.md
dependencies.cmake
links.cmake
logtail.cpp
logtail_windows.cpp
options.cmake
sudo_gdb.sh
utils.cmake
xmake.lua
Clone or Download
UnittestHelper.h 3.41 KB
Copy Edit Raw Blame History
/*
* Copyright 2022 iLogtail Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdlib.h>
#include <sys/errno.h>
#include <sys/utsname.h>
#include <string>
#include "logger/Logger.h"
#include "protobuf/sls/sls_logs.pb.h"
namespace logtail {
class UnitTestHelper {
public:
static std::pair<std::string, bool> GetLogTag(const sls_logs::LogGroup* logGroupPB, const std::string& key) {
auto tags = logGroupPB->logtags();
for (auto iter = tags.begin(); iter != tags.end(); ++iter) {
if (iter->key() == key) {
return std::make_pair(iter->value(), true);
}
}
return std::make_pair(std::string(), false);
}
static bool LogTagExisted(const sls_logs::LogGroup* logGroupPB, const std::string& key) {
auto findRst = GetLogTag(logGroupPB, key);
return findRst.second;
}
static bool LogTagMatched(const sls_logs::LogGroup* logGroupPB, const std::string& key, const std::string& value) {
auto findRst = GetLogTag(logGroupPB, key);
return findRst.second && findRst.first == value;
}
static std::pair<std::string, bool> GetLogKey(const sls_logs::Log* logPB, const std::string& key) {
const ::google::protobuf::RepeatedPtrField< ::sls_logs::Log_Content>& contents = logPB->contents();
for (auto iter = contents.begin(); iter != contents.end(); ++iter) {
if (iter->key() == key) {
return std::make_pair(iter->value(), true);
}
}
return std::make_pair(std::string(), false);
}
static bool LogKeyExisted(const sls_logs::Log* logPB, const std::string& key) {
auto findRst = GetLogKey(logPB, key);
return findRst.second;
}
static bool LogKeyMatched(const sls_logs::Log* logPB, const std::string& key, const std::string& value) {
auto findRst = GetLogKey(logPB, key);
return findRst.second && findRst.first == value;
}
static bool GetKernelVersion(int& mainVersion, int& subVersion) {
struct utsname buf;
if (uname(&buf) != 0) {
LOG_ERROR(sLogger, ("failed to get linux kernel version, errno", errno));
return false;
}
std::string releaseVersion(buf.release);
size_t pos = releaseVersion.find_first_of('-');
if (pos == std::string::npos) {
LOG_ERROR(sLogger, ("failed to get linux kernel version, release info", releaseVersion));
return false;
}
size_t mainPos = releaseVersion.find_first_of('.');
if (mainPos != std::string::npos) {
mainVersion = atoi(releaseVersion.substr(0, mainPos).c_str());
}
size_t subPos = releaseVersion.find_first_of('.', mainPos + 1);
if (subPos != std::string::npos) {
subVersion = atoi(releaseVersion.substr(mainPos + 1, subPos - mainPos).c_str());
}
return true;
}
};
} // namespace logtail
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/SmartSmallBoy/loongcollector_cpp.git
git@gitee.com:SmartSmallBoy/loongcollector_cpp.git
SmartSmallBoy
loongcollector_cpp
loongcollector_cpp
master

Search