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

feat: add ebpf plugins #2049

Open
wants to merge 87 commits into
base: dev/ebpf_observe
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 84 commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
d6e1030
add some utils
KayzzzZ Dec 27, 2024
04f6599
add protocol parser and aggregator
KayzzzZ Dec 27, 2024
d4aafbd
1. add some third party utils
KayzzzZ Jan 2, 2025
c290c30
update coolbpf and add driver layer framework
KayzzzZ Jan 2, 2025
feeb539
compile coolbpf and driver lib
KayzzzZ Jan 3, 2025
b575f94
export some functions for driver
KayzzzZ Jan 6, 2025
ca8b008
network observer start done ..
KayzzzZ Jan 8, 2025
bdd653d
network observer support log scenario
KayzzzZ Jan 8, 2025
a660ac8
fix enterprise compile
KayzzzZ Jan 8, 2025
0186592
update
KayzzzZ Jan 9, 2025
e9b9297
move id allocator
KayzzzZ Jan 9, 2025
96a4cca
format && add some framework
KayzzzZ Jan 13, 2025
cf01f07
update
KayzzzZ Jan 13, 2025
58962e7
update
KayzzzZ Jan 13, 2025
b438364
update
KayzzzZ Jan 16, 2025
697b82c
update
KayzzzZ Jan 16, 2025
58ad778
update
KayzzzZ Jan 17, 2025
497b097
add aggregator ut and setup aggregator for networksecurity & filesecu…
KayzzzZ Jan 17, 2025
fa8bee1
add some annotations
KayzzzZ Jan 17, 2025
6313b5e
add lock
KayzzzZ Jan 17, 2025
0374e83
add data handler
KayzzzZ Jan 17, 2025
08b5201
update
KayzzzZ Jan 18, 2025
cdf4ff3
update
KayzzzZ Jan 19, 2025
65cca2c
fix conflict
KayzzzZ Jan 19, 2025
3176f41
update
KayzzzZ Jan 19, 2025
978b903
flush span
KayzzzZ Jan 20, 2025
4d15e92
fix url path
KayzzzZ Jan 20, 2025
0f916e7
set to event tag instead of event group tag
KayzzzZ Jan 21, 2025
3545ec5
update
KayzzzZ Jan 21, 2025
10217de
clang format
KayzzzZ Jan 21, 2025
364dbc2
add some unittests
KayzzzZ Jan 22, 2025
96f80a9
clone event
KayzzzZ Jan 23, 2025
8c0850b
rebase main
KayzzzZ Jan 23, 2025
ed80d72
update coolbpf
KayzzzZ Jan 23, 2025
0c94a5a
fix
KayzzzZ Jan 26, 2025
823a4f1
update
KayzzzZ Feb 7, 2025
3a6b2b1
Update submodule coolbpf to commit c24d3993c16051c00d86eae063958898e4…
yyuuttaaoo Feb 7, 2025
9696ee8
try to fix compile failed with -std=c90
yyuuttaaoo Feb 7, 2025
68ba6eb
fix stadalone binary compile issue with compatible mode
yyuuttaaoo Feb 8, 2025
6ab0ab9
fix build script
yyuuttaaoo Feb 8, 2025
08afa01
Merge remote-tracking branch 'upstream/main' into ql/add-coolbpf
yyuuttaaoo Feb 8, 2025
3503e15
add some uts
KayzzzZ Feb 8, 2025
e99eee7
fix timer unittest
KayzzzZ Feb 10, 2025
6c56bf6
enable privileged
KayzzzZ Feb 10, 2025
272b8cc
fix ut
KayzzzZ Feb 11, 2025
5bc8c4b
fix log format string and remove useless files
yyuuttaaoo Feb 12, 2025
de7dae9
support arguments parse
KayzzzZ Feb 13, 2025
759e316
Merge remote-tracking branch 'upstream/dev/ebpf_observe' into ql/add-…
yyuuttaaoo Feb 14, 2025
5b004f7
1. remove some unsed structures
KayzzzZ Feb 14, 2025
f789fa7
remove unused files
KayzzzZ Feb 14, 2025
5789e6c
update coolbpf
KayzzzZ Feb 14, 2025
e35c616
use class method
KayzzzZ Feb 16, 2025
5090718
update
KayzzzZ Feb 16, 2025
9a99e40
lint codes
KayzzzZ Feb 16, 2025
d51d027
fix ut
KayzzzZ Feb 17, 2025
c0c218d
update cmake
KayzzzZ Feb 17, 2025
34e7ada
fix lint
KayzzzZ Feb 17, 2025
fd115c9
update coverage command
KayzzzZ Feb 17, 2025
dc312df
add some ut && modify core-ut pipeline config
KayzzzZ Feb 17, 2025
5350cd9
fix ut pipeline
KayzzzZ Feb 17, 2025
d45cd02
resolve warnings while build ebpf driver
yyuuttaaoo Feb 17, 2025
a69c57b
fix ut.yaml
yyuuttaaoo Feb 17, 2025
adc4b96
add some uts
KayzzzZ Feb 18, 2025
5a150cb
do not snprintf if log level won't record
yyuuttaaoo Feb 18, 2025
e10cafc
fix
KayzzzZ Feb 18, 2025
5f442c4
fix
KayzzzZ Feb 18, 2025
a499da6
fix
KayzzzZ Feb 18, 2025
c4c7dce
refine class names
yyuuttaaoo Feb 18, 2025
bc71222
fix build
KayzzzZ Feb 19, 2025
d327f0d
fix aggregator ut
KayzzzZ Feb 19, 2025
ed22b13
tag constants ref to data elements
KayzzzZ Feb 19, 2025
0d791d0
fix ut
KayzzzZ Feb 19, 2025
aad04a5
add id_allocator ut
KayzzzZ Feb 19, 2025
459a346
1. update coolbpf
KayzzzZ Feb 19, 2025
460aeba
fix Go Lint
yyuuttaaoo Feb 19, 2025
3573256
fix ut
KayzzzZ Feb 19, 2025
21078aa
lint data table
KayzzzZ Feb 19, 2025
692d829
reorg conn tracker and fix code style and add some ut to verify attri…
KayzzzZ Feb 20, 2025
57f2e10
fix ipv4/ipv6 print
yyuuttaaoo Feb 21, 2025
2e7a7d2
fix go build pipeline
yyuuttaaoo Feb 21, 2025
ece84d9
fix UT build
yyuuttaaoo Feb 24, 2025
576cd70
fix ut
yyuuttaaoo Feb 24, 2025
42e6e54
1. opt network observer
KayzzzZ Feb 24, 2025
58b1ee7
update
KayzzzZ Feb 25, 2025
4a206d3
fix argument parse and assign in ProcessCache
yyuuttaaoo Feb 26, 2025
36c0724
update
KayzzzZ Feb 26, 2025
66740be
update
KayzzzZ Feb 26, 2025
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
5 changes: 5 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
}
},
"initializeCommand": ".devcontainer/gen_env.sh",
"privileged": true,
"mounts": [
{ "source": "/sys", "target": "/sys", "type": "bind" },
{ "source": "/", "target": "/logtail_host", "type": "bind" }
],
"runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined" ],
"onCreateCommand": "sudo chown -R $(id -un):$(id -gn) /root",
"customizations": {
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build-core-ut.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ jobs:
run: docker build -t unittest_coverage -f ./docker/Dockerfile_coverage .

- name: Unit Test
run: docker run -v $(pwd):$(pwd) unittest_coverage bash -c "cd $(pwd) && make unittest_core"
run: docker run --privileged -v /sys:/sys -v /:/logtail_host -v $(pwd):$(pwd) unittest_coverage bash -c "cd $(pwd) && make unittest_core"

- name: Unit Test Coverage
run: docker run -v $(pwd):$(pwd) unittest_coverage bash -c "cd $(pwd)/core && gcovr --gcov-ignore-errors=no_working_dir_found --root . --json coverage.json --json-summary-pretty --json-summary summary.json -e \".*\.pb\.cc\" -e \".*\.pb\.h\" -e \".*unittest.*\" -e \".*sdk.*\" -e \".*logger.*\" -e \".*config_server.*\" -e \".*go_pipeline.*\" -e \".*application.*\" -e \".*runner.*\""
run: docker run -v $(pwd):$(pwd) unittest_coverage bash -c "cd $(pwd)/core && gcovr --gcov-ignore-parse-errors --merge-mode-functions=separate --gcov-ignore-errors=no_working_dir_found --root . --json coverage.json --json-summary-pretty --json-summary summary.json -e \".*\.pb\.cc\" -e \".*\.pb\.h\" -e \".*unittest.*\" -e \".*sdk.*\" -e \".*logger.*\" -e \".*config_server.*\" -e \".*go_pipeline.*\" -e \".*application.*\" -e \".*runner.*\" -e \".*_thirdparty.*\""

- name: Setup Python3.10
uses: actions/setup-python@v5
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/static-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ jobs:
with:
clang-format-version: '18'
check-path: 'core'
exclude-regex: 'common/xxhash|labels/Relabel\.cpp|ProcessorParseContainerLogNative\.cpp|FlusherSLS\.cpp'
exclude-regex: 'common/xxhash|labels/Relabel\.cpp|ProcessorParseContainerLogNative\.cpp|FlusherSLS\.cpp|_thirdparty|core/common/LRUCache\.h|core/common/queue/.*|core/common/magic_enum\.hpp'
include-regex: '.*\.(cpp|h)$'

- name: Go Plugin Lint
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "core/_thirdparty/coolbpf"]
path = core/_thirdparty/coolbpf
url = https://gitee.com/anolis/coolbpf.git
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ run:
# default value is empty list, but default dirs are skipped independently
# from this option's value (see skip-dirs-use-default).
skip-dirs:
- (^|/)core($|/)
- (^|/)vendor($|/)
- (^|/)external($|/)
# todo delete or polish packages
Expand Down
8 changes: 6 additions & 2 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ endif ()
# To be compatible with low version Linux.
if (ENABLE_COMPATIBLE_MODE)
message(STATUS "Enable compatible mode.")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c90")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,--wrap=memcpy")
add_definitions(-DENABLE_COMPATIBLE_MODE)
endif ()
Expand Down Expand Up @@ -127,7 +126,7 @@ set(SUB_DIRECTORIES_LIST
protobuf/sls protobuf/models
file_server file_server/event file_server/event_handler file_server/event_listener file_server/reader file_server/polling
prometheus prometheus/labels prometheus/schedulers prometheus/async prometheus/component
ebpf ebpf/observer ebpf/security ebpf/handler
ebpf ebpf/util ebpf/util/sampler ebpf/protocol/http ebpf/protocol ebpf/plugin/file_security ebpf/plugin/network_observer ebpf/plugin/process_security ebpf/plugin/network_security ebpf/plugin ebpf/observer ebpf/security
parser
)
if (LINUX)
Expand All @@ -145,6 +144,7 @@ endif()

# Module includes & set files.
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_directories("${DEPS_INCLUDE_ROOT}/coolbpf")

foreach (DIR_NAME ${SUB_DIRECTORIES_LIST})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/${DIR_NAME})
Expand Down Expand Up @@ -221,6 +221,9 @@ endif ()
# Generate independent libraries.
add_subdirectory(go_pipeline)
add_subdirectory(common)
# Build eBPF dependencies
set(EBPF_DIRVER_TARGET "EbpfDriver")
add_subdirectory(ebpf/driver)

# Link libraries.
if(BUILD_LOGTAIL OR BUILD_LOGTAIL_SHARED_LIBRARY)
Expand All @@ -230,6 +233,7 @@ if(BUILD_LOGTAIL OR BUILD_LOGTAIL_SHARED_LIBRARY)
all_link(${LOGTAIL_TARGET})
common_link(${LOGTAIL_TARGET})
target_link_libraries(${LOGTAIL_TARGET} provider)
add_dependencies(${LOGTAIL_TARGET} install_coolbpf)
endif()

# Logtail UT.
Expand Down
1 change: 1 addition & 0 deletions core/_thirdparty/coolbpf
Submodule coolbpf added at 242d3b
3 changes: 3 additions & 0 deletions core/app_config/AppConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ DEFINE_FLAG_STRING(metrics_report_method,
DEFINE_FLAG_STRING(operator_service, "loong collector operator service", "");
DEFINE_FLAG_INT32(operator_service_port, "loong collector operator service port", 8888);
DEFINE_FLAG_INT32(k8s_meta_service_port, "loong collector operator service port", 9000);

DEFINE_FLAG_STRING(singleton_service, "loong collector singleton service", "loongcollector-singleton");
DEFINE_FLAG_INT32(singleton_port, "loong collector singleton service port", 8899);
DEFINE_FLAG_STRING(_pod_name_, "agent pod name", "");

DEFINE_FLAG_STRING(app_info_file, "", "app_info.json");
Expand Down
28 changes: 28 additions & 0 deletions core/collection_pipeline/serializer/SLSSerializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "json/json.h"

#include "Logger.h"
#include "collection_pipeline/serializer/JsonSerializer.h"
#include "common/Flags.h"
#include "common/compression/CompressType.h"
Expand Down Expand Up @@ -119,6 +120,19 @@ bool SLSEventGroupSerializer::Serialize(BatchedEvents&& group, string& res, stri
case PipelineEvent::Type::METRIC: {
for (size_t i = 0; i < group.mEvents.size(); ++i) {
const auto& e = group.mEvents[i].Cast<MetricEvent>();
if (SHOULD_LOG_DEBUG(sLogger)) {
for (auto tag = e.TagsBegin(); tag != e.TagsEnd(); tag++) {
LOG_DEBUG(
sLogger,
("event tags for metricname", e.GetName().data())(tag->first.data(), tag->second.data()));
}
for (auto tag = group.mTags.mInner.begin(); tag != group.mTags.mInner.end(); tag++) {
LOG_DEBUG(
sLogger,
("group tags for metricname", e.GetName().data())(tag->first.data(), tag->second.data()));
}
}

if (e.GetTimestamp() < 1e9) {
LOG_WARNING(sLogger,
("metric event timestamp is less than 1e9", "discard event")(
Expand All @@ -127,6 +141,8 @@ bool SLSEventGroupSerializer::Serialize(BatchedEvents&& group, string& res, stri
}
if (e.Is<UntypedSingleValue>()) {
metricEventContentCache[i].first = to_string(e.GetValue<UntypedSingleValue>()->mValue);
// should not happen
LOG_ERROR(sLogger, ("config", mFlusher->GetContext().GetConfigName())("metricname", e.GetName()));
} else {
// untyped multi value is not supported
LOG_WARNING(sLogger,
Expand All @@ -150,6 +166,18 @@ bool SLSEventGroupSerializer::Serialize(BatchedEvents&& group, string& res, stri
case PipelineEvent::Type::SPAN:
for (size_t i = 0; i < group.mEvents.size(); ++i) {
const auto& e = group.mEvents[i].Cast<SpanEvent>();
if (SHOULD_LOG_DEBUG(sLogger)) {
for (auto tag = e.TagsBegin(); tag != e.TagsEnd(); tag++) {
LOG_DEBUG(sLogger,
("event tags for spanname", std::string(e.GetName()))(std::string(tag->first),
std::string(tag->second)));
}
for (auto tag = group.mTags.mInner.begin(); tag != group.mTags.mInner.end(); tag++) {
LOG_DEBUG(sLogger,
("group tags for spanname", std::string(e.GetName()))(std::string(tag->first),
std::string(tag->second)));
}
}
size_t contentSZ = 0;
contentSZ += GetLogContentSize(DEFAULT_TRACE_TAG_TRACE_ID.size(), e.GetTraceId().size());
contentSZ += GetLogContentSize(DEFAULT_TRACE_TAG_SPAN_ID.size(), e.GetSpanId().size());
Expand Down
94 changes: 94 additions & 0 deletions core/common/CapabilityUtil.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// Copyright 2023 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 "CapabilityUtil.h"

#include <array>
#include <stdexcept>
#include <string>

namespace logtail {

static const std::array<std::string, 41> CAPABILITY_STRINGS = {{"CAP_CHOWN",
"DAC_OVERRIDE",
"CAP_DAC_READ_SEARCH",
"CAP_FOWNER",
"CAP_FSETID",
"CAP_KILL",
"CAP_SETGID",
"CAP_SETUID",
"CAP_SETPCAP",
"CAP_LINUX_IMMUTABLE",
"CAP_NET_BIND_SERVICE",
"CAP_NET_BROADCAST",
"CAP_NET_ADMIN",
"CAP_NET_RAW",
"CAP_IPC_LOCK",
"CAP_IPC_OWNER",
"CAP_SYS_MODULE",
"CAP_SYS_RAWIO",
"CAP_SYS_CHROOT",
"CAP_SYS_PTRACE",
"CAP_SYS_PACCT",
"CAP_SYS_ADMIN",
"CAP_SYS_BOOT",
"CAP_SYS_NICE",
"CAP_SYS_RESOURCE",
"CAP_SYS_TIME",
"CAP_SYS_TTY_CONFIG",
"CAP_MKNOD",
"CAP_LEASE",
"CAP_AUDIT_WRITE",
"CAP_AUDIT_CONTROL",
"CAP_SETFCAP",
"CAP_MAC_OVERRIDE",
"CAP_MAC_ADMIN",
"CAP_SYSLOG",
"CAP_WAKE_ALARM",
"CAP_BLOCK_SUSPEND",
"CAP_AUDIT_READ",
"CAP_PERFMON",
"CAP_BPF",
"CAP_CHECKPOINT_RESTORE"}};

static constexpr int32_t CAP_LAST_CAP = 40;

const std::string& GetCapability(int32_t capInt) {
if (capInt < 0 || capInt > CAP_LAST_CAP) {
throw std::invalid_argument("invalid capability value " + std::to_string(capInt));
}
return CAPABILITY_STRINGS[capInt];
}

std::string GetCapabilities(uint64_t capInt) {
if (capInt == 0) {
return "";
}

std::string result;
result.reserve(CAP_LAST_CAP * 16);

for (uint64_t i = 0; i <= CAP_LAST_CAP; ++i) {
if ((1ULL << i) & capInt) {
if (!result.empty()) {
result.append(1, ' ');
}
result.append(CAPABILITY_STRINGS[i]);
}
}

return result;
}

} // namespace logtail
25 changes: 25 additions & 0 deletions core/common/CapabilityUtil.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2023 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.

#pragma once

#include <string>

namespace logtail {

std::string GetCapabilities(uint64_t capInt);

const std::string& GetCapability(int32_t capInt);

} // namespace logtail
Loading
Loading