Skip to content

Commit

Permalink
format eBPF plugin sources (#1984)
Browse files Browse the repository at this point in the history
  • Loading branch information
yyuuttaaoo authored Dec 19, 2024
1 parent 7f391fb commit 08a6bc4
Show file tree
Hide file tree
Showing 25 changed files with 1,023 additions and 927 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ DisableFormat: false
IndentWrappedFunctionNames: false
MacroBlockBegin: ''
MacroBlockEnd: ''
NamespaceIndentation: Inner
NamespaceIndentation: None
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
Expand Down
56 changes: 34 additions & 22 deletions core/ebpf/config.cpp → core/ebpf/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "ebpf/Config.h"

#include <string>
#include <unordered_set>

#include "logger/Logger.h"
#include "ebpf/config.h"
#include "common/ParamExtractor.h"
#include "common/Flags.h"
#include "common/ParamExtractor.h"
#include "logger/Logger.h"

DEFINE_FLAG_INT32(ebpf_receive_event_chan_cap, "ebpf receive kernel event queue size", 4096);
DEFINE_FLAG_BOOL(ebpf_admin_config_debug_mode, "ebpf admin config debug mode", false);
Expand Down Expand Up @@ -46,9 +47,9 @@ static const std::unordered_map<SecurityProbeType, std::unordered_set<std::strin
{SecurityProbeType::NETWORK, {"tcp_connect", "tcp_close", "tcp_sendmsg"}}};

bool InitObserverNetworkOptionInner(const Json::Value& probeConfig,
nami::ObserverNetworkOption& thisObserverNetworkOption,
const PipelineContext* mContext,
const std::string& sName) {
nami::ObserverNetworkOption& thisObserverNetworkOption,
const PipelineContext* mContext,
const std::string& sName) {
std::string errorMsg;
// EnableEvent (Optional)
if (!GetOptionalBoolParam(probeConfig, "EnableLog", thisObserverNetworkOption.mEnableLog, errorMsg)) {
Expand Down Expand Up @@ -84,7 +85,8 @@ bool InitObserverNetworkOptionInner(const Json::Value& probeConfig,
mContext->GetRegion());
}
// MeterHandlerType (Optional)
if (!GetOptionalStringParam(probeConfig, "MeterHandlerType", thisObserverNetworkOption.mMeterHandlerType, errorMsg)) {
if (!GetOptionalStringParam(
probeConfig, "MeterHandlerType", thisObserverNetworkOption.mMeterHandlerType, errorMsg)) {
PARAM_WARNING_IGNORE(mContext->GetLogger(),
mContext->GetAlarm(),
errorMsg,
Expand Down Expand Up @@ -158,7 +160,10 @@ bool InitObserverNetworkOptionInner(const Json::Value& probeConfig,
return true;
}

bool ExtractProbeConfig(const Json::Value& config, const PipelineContext* mContext, const std::string& sName, Json::Value& probeConfig) {
bool ExtractProbeConfig(const Json::Value& config,
const PipelineContext* mContext,
const std::string& sName,
Json::Value& probeConfig) {
std::string errorMsg;
if (!IsValidMap(config, "ProbeConfig", errorMsg)) {
PARAM_ERROR_RETURN(mContext->GetLogger(),
Expand All @@ -174,7 +179,7 @@ bool ExtractProbeConfig(const Json::Value& config, const PipelineContext* mConte
return true;
}

bool InitObserverNetworkOption(const Json::Value& config,
bool InitObserverNetworkOption(const Json::Value& config,
nami::ObserverNetworkOption& thisObserverNetworkOption,
const PipelineContext* mContext,
const std::string& sName) {
Expand Down Expand Up @@ -393,13 +398,13 @@ bool SecurityOptions::Init(SecurityProbeType probeType,
}
default:
PARAM_WARNING_IGNORE(mContext->GetLogger(),
mContext->GetAlarm(),
"Unknown security eBPF probe type",
sName,
mContext->GetConfigName(),
mContext->GetProjectName(),
mContext->GetLogstoreName(),
mContext->GetRegion());
mContext->GetAlarm(),
"Unknown security eBPF probe type",
sName,
mContext->GetConfigName(),
mContext->GetProjectName(),
mContext->GetLogstoreName(),
mContext->GetRegion());
}
thisSecurityOption.filter_ = thisFilter;
GetSecurityProbeDefaultCallName(probeType, thisSecurityOption.call_names_);
Expand All @@ -413,20 +418,27 @@ void eBPFAdminConfig::LoadEbpfConfig(const Json::Value& confJson) {
// receive_event_chan_cap (Optional)
mReceiveEventChanCap = INT32_FLAG(ebpf_receive_event_chan_cap);
// admin_config (Optional)
mAdminConfig = AdminConfig{BOOL_FLAG(ebpf_admin_config_debug_mode), STRING_FLAG(ebpf_admin_config_log_level), BOOL_FLAG(ebpf_admin_config_push_all_span)};
mAdminConfig = AdminConfig{BOOL_FLAG(ebpf_admin_config_debug_mode),
STRING_FLAG(ebpf_admin_config_log_level),
BOOL_FLAG(ebpf_admin_config_push_all_span)};
// aggregation_config (Optional)
mAggregationConfig = AggregationConfig{INT32_FLAG(ebpf_aggregation_config_agg_window_second)};
// converage_config (Optional)
mConverageConfig = ConverageConfig{STRING_FLAG(ebpf_converage_config_strategy)};
// sample_config (Optional)
mSampleConfig = SampleConfig{STRING_FLAG(ebpf_sample_config_strategy), {DOUBLE_FLAG(ebpf_sample_config_config_rate)}};
mSampleConfig
= SampleConfig{STRING_FLAG(ebpf_sample_config_strategy), {DOUBLE_FLAG(ebpf_sample_config_config_rate)}};
// socket_probe_config (Optional)
mSocketProbeConfig = SocketProbeConfig{INT32_FLAG(ebpf_socket_probe_config_slow_request_threshold_ms), INT32_FLAG(ebpf_socket_probe_config_max_conn_trackers), INT32_FLAG(ebpf_socket_probe_config_max_band_width_mb_per_sec), INT32_FLAG(ebpf_socket_probe_config_max_raw_record_per_sec)};
mSocketProbeConfig = SocketProbeConfig{INT32_FLAG(ebpf_socket_probe_config_slow_request_threshold_ms),
INT32_FLAG(ebpf_socket_probe_config_max_conn_trackers),
INT32_FLAG(ebpf_socket_probe_config_max_band_width_mb_per_sec),
INT32_FLAG(ebpf_socket_probe_config_max_raw_record_per_sec)};
// profile_probe_config (Optional)
mProfileProbeConfig = ProfileProbeConfig{INT32_FLAG(ebpf_profile_probe_config_profile_sample_rate), INT32_FLAG(ebpf_profile_probe_config_profile_upload_duration)};
mProfileProbeConfig = ProfileProbeConfig{INT32_FLAG(ebpf_profile_probe_config_profile_sample_rate),
INT32_FLAG(ebpf_profile_probe_config_profile_upload_duration)};
// process_probe_config (Optional)
mProcessProbeConfig = ProcessProbeConfig{BOOL_FLAG(ebpf_process_probe_config_enable_oom_detect)};
}

} // ebpf
} // logtail
} // namespace ebpf
} // namespace logtail
12 changes: 6 additions & 6 deletions core/ebpf/config.h → core/ebpf/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@

#pragma once

#include <string>
#include <json/json.h>

#include <string>
#include <variant>
#include <vector>

#include "pipeline/PipelineContext.h"
#include "ebpf/include/export.h"
#include "pipeline/PipelineContext.h"


namespace logtail {
Expand All @@ -29,7 +30,7 @@ namespace ebpf {
///////////////////// /////////////////////

enum class ObserverType { PROCESS, FILE, NETWORK };
bool InitObserverNetworkOption(const Json::Value& config,
bool InitObserverNetworkOption(const Json::Value& config,
nami::ObserverNetworkOption& thisObserverNetworkOption,
const PipelineContext* mContext,
const std::string& sName);
Expand Down Expand Up @@ -129,8 +130,7 @@ class eBPFAdminConfig {
#ifdef APSARA_UNIT_TEST_MAIN
friend class eBPFServerUnittest;
#endif

};

} // ebpf
} // logtail
} // namespace ebpf
} // namespace logtail
Loading

0 comments on commit 08a6bc4

Please sign in to comment.