Skip to content

Commit

Permalink
feat: memcached support
Browse files Browse the repository at this point in the history
  • Loading branch information
boolsatellite authored and rvql committed Oct 10, 2024
1 parent 2e636bf commit 6819c04
Show file tree
Hide file tree
Showing 15 changed files with 21,106 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ target/
/agent/src/ebpf/samples/rust/socket-tracer/target
/agent/src/ebpf/samples/rust/socket-tracer/src/ebpf.rs
/agent/src/ebpf/.flamegraph.pl

/agent/src/ebpf/kernel/*.tmp



2 changes: 2 additions & 0 deletions agent/crates/public/src/l7_protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ pub enum L7Protocol {
MySQL = 60,
PostgreSQL = 61,
Oracle = 62,
Memcached = 63,

// NoSQL
Redis = 80,
Expand Down Expand Up @@ -113,6 +114,7 @@ impl From<String> for L7Protocol {
"mongodb" => Self::MongoDB,
"postgresql" => Self::PostgreSQL,
"redis" => Self::Redis,
"memcached" => Self::Memcached,
"kafka" => Self::Kafka,
"mqtt" => Self::MQTT,
"amqp" => Self::AMQP,
Expand Down
Binary file not shown.
20,307 changes: 20,307 additions & 0 deletions agent/resources/test/flow_generator/memcached/memcached-userdata.result

Large diffs are not rendered by default.

Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
MemcachedInfo { msg_type: Request request: set foo 0 0 3 req_size: 15 result: err_msg: res_size: 0 rtt: 0 } is_memcached: true
parse failed Memcached log parse failed: Unhandled command `bar`
MemcachedInfo { msg_type: Response request: req_size: 0 result: STORED err_msg: res_size: 8 rtt: 2197111 } is_memcached: true
MemcachedInfo { msg_type: Request request: get foo req_size: 9 result: err_msg: res_size: 0 rtt: 0 } is_memcached: true
MemcachedInfo { msg_type: Response request: req_size: 0 result: VALUE foo 0 3 err_msg: res_size: 25 rtt: 109 } is_memcached: true
parse failed Memcached log parse failed: Unhandled command `quit`
7 changes: 4 additions & 3 deletions agent/src/common/l7_protocol_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ use crate::{
flow_generator::{
protocol_logs::{
fastcgi::FastCGIInfo, pb_adapter::L7ProtocolSendLog, AmqpInfo, BrpcInfo, DnsInfo,
DubboInfo, HttpInfo, KafkaInfo, MongoDBInfo, MqttInfo, MysqlInfo, NatsInfo,
OpenWireInfo, OracleInfo, PostgreInfo, PulsarInfo, RedisInfo, SofaRpcInfo, SomeIpInfo,
TarsInfo, TlsInfo, ZmtpInfo,
DubboInfo, HttpInfo, KafkaInfo, MemcachedInfo, MongoDBInfo, MqttInfo, MysqlInfo,
NatsInfo, OpenWireInfo, OracleInfo, PostgreInfo, PulsarInfo, RedisInfo, SofaRpcInfo,
SomeIpInfo, TarsInfo, TlsInfo, ZmtpInfo,
},
AppProtoHead, LogMessageType, Result,
},
Expand Down Expand Up @@ -83,6 +83,7 @@ all_protocol_info!(
SofaRpcInfo(SofaRpcInfo),
TlsInfo(TlsInfo),
SomeIpInfo(SomeIpInfo),
MemcachedInfo(MemcachedInfo),
CustomInfo(CustomInfo),
// add new protocol info below
);
Expand Down
9 changes: 5 additions & 4 deletions agent/src/common/l7_protocol_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ use crate::flow_generator::protocol_logs::plugin::custom_wrap::CustomWrapLog;
use crate::flow_generator::protocol_logs::plugin::get_custom_log_parser;
use crate::flow_generator::protocol_logs::sql::ObfuscateCache;
use crate::flow_generator::protocol_logs::{
AmqpLog, BrpcLog, DnsLog, DubboLog, HttpLog, KafkaLog, MongoDBLog, MqttLog, MysqlLog, NatsLog,
OpenWireLog, OracleLog, PostgresqlLog, PulsarLog, RedisLog, SofaRpcLog, SomeIpLog, TarsLog,
TlsLog, ZmtpLog,
AmqpLog, BrpcLog, DnsLog, DubboLog, HttpLog, KafkaLog, MemcachedLog, MongoDBLog, MqttLog,
MysqlLog, NatsLog, OpenWireLog, OracleLog, PostgresqlLog, PulsarLog, RedisLog, SofaRpcLog,
SomeIpLog, TarsLog, TlsLog, ZmtpLog,
};

use crate::flow_generator::{LogMessageType, Result};
Expand Down Expand Up @@ -183,7 +183,8 @@ impl_protocol_parser! {
ZMTP(ZmtpLog),
OpenWire(OpenWireLog),
TLS(TlsLog),
SomeIp(SomeIpLog)
SomeIp(SomeIpLog),
Memcached(MemcachedLog),
// add protocol below
}
}
Expand Down
7 changes: 5 additions & 2 deletions agent/src/flow_generator/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

use std::str::Utf8Error;
use std::{borrow::Cow, str::Utf8Error};

use public::l7_protocol::L7Protocol;
use thiserror::Error;
Expand Down Expand Up @@ -104,7 +104,10 @@ pub enum Error {
#[error("so plugin parse fail")]
SoParseFail,
#[error("{proto:?} log parse failed: {reason}")]
L7LogParseFailed { proto: L7Protocol, reason: String },
L7LogParseFailed {
proto: L7Protocol,
reason: Cow<'static, str>,
},
#[error("insufficient payload length")]
InsufficientPayloadLength,
#[error("unsupported SOME/IP message type")]
Expand Down
4 changes: 2 additions & 2 deletions agent/src/flow_generator/protocol_logs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ pub use rpc::{
SofaRpcLog, SomeIpInfo, SomeIpLog, TarsInfo, TarsLog, SOFA_NEW_RPC_TRACE_CTX_KEY,
};
pub use sql::{
MongoDBInfo, MongoDBLog, MysqlInfo, MysqlLog, OracleInfo, OracleLog, PostgreInfo,
PostgresqlLog, RedisInfo, RedisLog,
MemcachedInfo, MemcachedLog, MongoDBInfo, MongoDBLog, MysqlInfo, MysqlLog, OracleInfo,
OracleLog, PostgreInfo, PostgresqlLog, RedisInfo, RedisLog,
};
pub use tls::{TlsInfo, TlsLog};

Expand Down
2 changes: 1 addition & 1 deletion agent/src/flow_generator/protocol_logs/rpc/tars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ impl L7ProtocolParserInterface for TarsLog {
let mut info = TarsInfo::parse(payload, param)
.ok_or(Error::L7LogParseFailed {
proto: L7Protocol::Tars,
reason: "parse result empty".to_owned(),
reason: "parse result empty".into(),
})?
.1;

Expand Down
Loading

0 comments on commit 6819c04

Please sign in to comment.