diff --git a/WORKSPACE b/WORKSPACE index 01f96533a72..76d63c7ddcf 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -297,3 +297,12 @@ maven_install( load("@px_deps//:defs.bzl", px_deps_pinned_maven_install = "pinned_maven_install") px_deps_pinned_maven_install() + +pip_parse( + name = "mongodb_bpf_test_requirements", + requirements_lock = "//src/stirling/source_connectors/socket_tracer/testing/containers/mongodb:requirements.bazel.txt", +) + +load("@mongodb_bpf_test_requirements//:requirements.bzl", mongodb_bpf_test_install_deps = "install_deps") + +mongodb_bpf_test_install_deps() diff --git a/bazel/container_images.bzl b/bazel/container_images.bzl index d28f492737d..f0778e122e4 100644 --- a/bazel/container_images.bzl +++ b/bazel/container_images.bzl @@ -278,3 +278,11 @@ def stirling_test_images(): repository = "google-samples/microservices-demo/emailservice", digest = "sha256:d42ee712cbb4806a8b922e303a5e6734f342dfb6c92c81284a289912165b7314", ) + + # Tag: mongo:7.0 + # Arch: linux/amd64 + _container_image( + name = "mongo_7_0", + repository = "mongo", + digest = "sha256:19b2e5c91f92c7b18113a1501c5a5fe52b71a6c6d2a5232eeebb4f2abacae04a", + ) diff --git a/src/stirling/source_connectors/socket_tracer/BUILD.bazel b/src/stirling/source_connectors/socket_tracer/BUILD.bazel index b908d2a30bf..68cc339a387 100644 --- a/src/stirling/source_connectors/socket_tracer/BUILD.bazel +++ b/src/stirling/source_connectors/socket_tracer/BUILD.bazel @@ -579,3 +579,18 @@ pl_cc_bpf_test( "//src/stirling/source_connectors/socket_tracer/testing/container_images:rabbitmq_producer_container", ], ) + +pl_cc_bpf_test( + name = "mongodb_trace_bpf_test", + timeout = "moderate", + srcs = ["mongodb_trace_bpf_test.cc"], + tags = ["requires_bpf"], + deps = [ + ":cc_library", + "//src/common/testing/test_utils:cc_library", + "//src/stirling/source_connectors/socket_tracer/testing:cc_library", + "//src/stirling/source_connectors/socket_tracer/testing/container_images:mongodb_client_container", + "//src/stirling/source_connectors/socket_tracer/testing/container_images:mongodb_container", + "//src/stirling/testing:cc_library", + ], +) diff --git a/src/stirling/source_connectors/socket_tracer/bcc_bpf/socket_trace.c b/src/stirling/source_connectors/socket_tracer/bcc_bpf/socket_trace.c index ba5df955dde..c77e03b857b 100644 --- a/src/stirling/source_connectors/socket_tracer/bcc_bpf/socket_trace.c +++ b/src/stirling/source_connectors/socket_tracer/bcc_bpf/socket_trace.c @@ -312,7 +312,7 @@ static __inline void update_traffic_class(struct conn_info_t* conn_info, struct protocol_message_t inferred_protocol = infer_protocol(buf, count, conn_info); // Could not infer the traffic. - if (inferred_protocol.protocol == kProtocolUnknown || conn_info->protocol == kProtocolMongo) { + if (inferred_protocol.protocol == kProtocolUnknown) { return; } diff --git a/src/stirling/source_connectors/socket_tracer/mongodb_trace_bpf_test.cc b/src/stirling/source_connectors/socket_tracer/mongodb_trace_bpf_test.cc new file mode 100644 index 00000000000..84f47982729 --- /dev/null +++ b/src/stirling/source_connectors/socket_tracer/mongodb_trace_bpf_test.cc @@ -0,0 +1,140 @@ +/* + * Copyright 2018- The Pixie 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. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +#include + +#include + +#include "src/common/base/base.h" +#include "src/common/exec/exec.h" +#include "src/common/testing/testing.h" +#include "src/shared/types/column_wrapper.h" +#include "src/shared/types/types.h" +#include "src/stirling/core/data_table.h" +#include "src/stirling/core/output.h" +#include "src/stirling/source_connectors/socket_tracer/mongodb_table.h" +#include "src/stirling/source_connectors/socket_tracer/protocols/mongodb/types.h" +#include "src/stirling/source_connectors/socket_tracer/testing/container_images/mongodb_client_container.h" +#include "src/stirling/source_connectors/socket_tracer/testing/container_images/mongodb_container.h" +#include "src/stirling/source_connectors/socket_tracer/testing/protocol_checkers.h" +#include "src/stirling/source_connectors/socket_tracer/testing/socket_trace_bpf_test_fixture.h" +#include "src/stirling/testing/common.h" +#include "src/stirling/utils/linux_headers.h" + +namespace px { +namespace stirling { + +namespace mongodb = protocols::mongodb; + +using ::px::stirling::testing::FindRecordIdxMatchesPID; +using ::px::stirling::testing::FindRecordsMatchingPID; +using ::px::stirling::testing::GetTargetRecords; +using ::px::stirling::testing::SocketTraceBPFTestFixture; + +using ::testing::AllOf; +using ::testing::Eq; +using ::testing::Field; +using ::testing::HasSubstr; + +void Init() { + // Enable mongodb tracing. + FLAGS_stirling_enable_mongodb_tracing = true; + + // Turn off CQL and NATS tracing to give some BPF instructions back for MongoDB. + // This is required for older kernels with only 4096 BPF instructions. + FLAGS_stirling_enable_cass_tracing = false; + FLAGS_stirling_enable_nats_tracing = false; +} + +class MongoDBTraceTest : public SocketTraceBPFTestFixture { + protected: + MongoDBTraceTest() { + Init(); + PX_CHECK_OK(mongodb_server_.Run(std::chrono::seconds{120})); + } + + void RunMongoDBClient() { + mongodb_client_.Run( + std::chrono::seconds{120}, + {absl::Substitute("--network=container:$0", mongodb_server_.container_name())}); + } + + ::px::stirling::testing::MongoDBClientContainer mongodb_client_; + ::px::stirling::testing::MongoDBContainer mongodb_server_; +}; + +auto EqMongoDBMsgType(const protocols::mongodb::Frame& f) { + return Field(&protocols::mongodb::Frame::op_msg_type, Eq(f.op_msg_type)); +} + +auto ContainsMongoDBMsgBody(const protocols::mongodb::Frame& f) { + return Field(&protocols::mongodb::Frame::frame_body, HasSubstr(f.frame_body)); +} + +auto EqMongoDBRecord(const protocols::mongodb::Record& r) { + return AllOf(Field(&protocols::mongodb::Record::req, EqMongoDBMsgType(r.req)), + Field(&protocols::mongodb::Record::resp, EqMongoDBMsgType(r.resp)), + Field(&protocols::mongodb::Record::req, ContainsMongoDBMsgBody(r.req)), + Field(&protocols::mongodb::Record::resp, ContainsMongoDBMsgBody(r.resp))); +} + +mongodb::Record RecordOpMsg(std::string req_cmd, std::string resp_status, std::string req_body, + std::string resp_body) { + mongodb::Record r = {}; + r.req.op_msg_type = req_cmd; + r.req.frame_body = req_body; + r.resp.op_msg_type = resp_status; + r.resp.frame_body = resp_body; + return r; +} + +//----------------------------------------------------------------------------- +// Test Scenarios +//----------------------------------------------------------------------------- + +TEST_F(MongoDBTraceTest, Capture) { + // Initiate the mongo transactions. + StartTransferDataThread(); + RunMongoDBClient(); + StopTransferDataThread(); + + // Grab the data from Stirling. + std::vector tablets = ConsumeRecords(SocketTraceConnector::kMongoDBTableNum); + ASSERT_NOT_EMPTY_AND_GET_RECORDS(const types::ColumnWrapperRecordBatch& record_batch, tablets); + + std::vector server_records = + GetTargetRecords(record_batch, mongodb_server_.process_pid()); + + mongodb::Record opMsgInsert = RecordOpMsg("insert", "ok: {$numberDouble: 1.0}", "foo", "ok"); + mongodb::Record opMsgFind1 = RecordOpMsg("find", "cursor", "find", "foo"); + mongodb::Record opMsgUpdate = RecordOpMsg("update", "ok: {$numberDouble: 1.0}", "bar", "ok"); + mongodb::Record opMsgFind2 = RecordOpMsg("find", "cursor", "find", "bar"); + mongodb::Record opMsgDelete = RecordOpMsg("delete", "ok: {$numberDouble: 1.0}", "bar", "ok"); + + EXPECT_THAT(server_records, Contains(EqMongoDBRecord(opMsgInsert))); + EXPECT_THAT(server_records, Contains(EqMongoDBRecord(opMsgFind1))); + EXPECT_THAT(server_records, Contains(EqMongoDBRecord(opMsgUpdate))); + EXPECT_THAT(server_records, Contains(EqMongoDBRecord(opMsgFind2))); + EXPECT_THAT(server_records, Contains(EqMongoDBRecord(opMsgDelete))); +} + +} // namespace stirling +} // namespace px diff --git a/src/stirling/source_connectors/socket_tracer/protocols/mongodb/types.h b/src/stirling/source_connectors/socket_tracer/protocols/mongodb/types.h index e7faeee525a..03cd533edb9 100644 --- a/src/stirling/source_connectors/socket_tracer/protocols/mongodb/types.h +++ b/src/stirling/source_connectors/socket_tracer/protocols/mongodb/types.h @@ -191,6 +191,9 @@ struct ProtocolTraits : public BaseProtocolTraits { }; } // namespace mongodb + +template <> +mongodb::stream_id_t GetStreamID(mongodb::Frame* frame); } // namespace protocols } // namespace stirling } // namespace px diff --git a/src/stirling/source_connectors/socket_tracer/socket_trace_connector.cc b/src/stirling/source_connectors/socket_tracer/socket_trace_connector.cc index 7e2b152ad7f..cf480d8ce33 100644 --- a/src/stirling/source_connectors/socket_tracer/socket_trace_connector.cc +++ b/src/stirling/source_connectors/socket_tracer/socket_trace_connector.cc @@ -114,7 +114,7 @@ DEFINE_int32(stirling_enable_amqp_tracing, "If true, stirling will trace and process AMQP messages."); DEFINE_int32(stirling_enable_mongodb_tracing, gflags::Int32FromEnv("PX_STIRLING_ENABLE_MONGODB_TRACING", - px::stirling::TraceMode::On), + px::stirling::TraceMode::OnForNewerKernel), "If true, stirling will trace and process MongoDB messages"); DEFINE_bool(stirling_disable_golang_tls_tracing, gflags::BoolFromEnv("PX_STIRLING_DISABLE_GOLANG_TLS_TRACING", false), @@ -265,7 +265,7 @@ void SocketTraceConnector::InitProtocolTransferSpecs() { kMuxTableNum, {kRoleClient, kRoleServer}, TRANSFER_STREAM_PROTOCOL(mux)}}, - {kProtocolMongo, TransferSpec{px::stirling::TraceMode::Off, + {kProtocolMongo, TransferSpec{FLAGS_stirling_enable_mongodb_tracing, kMongoDBTableNum, {kRoleClient, kRoleServer}, TRANSFER_STREAM_PROTOCOL(mongodb)}}, diff --git a/src/stirling/source_connectors/socket_tracer/testing/container_images/BUILD.bazel b/src/stirling/source_connectors/socket_tracer/testing/container_images/BUILD.bazel index 934009dea6d..d4a6a251445 100644 --- a/src/stirling/source_connectors/socket_tracer/testing/container_images/BUILD.bazel +++ b/src/stirling/source_connectors/socket_tracer/testing/container_images/BUILD.bazel @@ -141,6 +141,26 @@ pl_cc_test_library( deps = ["//src/common/testing/test_utils:cc_library"], ) +pl_cc_test_library( + name = "mongodb_client_container", + srcs = [], + hdrs = ["mongodb_client_container.h"], + data = [ + "//src/stirling/source_connectors/socket_tracer/testing/containers/mongodb:client_image.tar", + ], + deps = ["//src/common/testing/test_utils:cc_library"], +) + +pl_cc_test_library( + name = "mongodb_container", + srcs = [], + hdrs = ["mongodb_container.h"], + data = [ + "//src/stirling/source_connectors/socket_tracer/testing/containers:mongodb_image.tar", + ], + deps = ["//src/common/testing/test_utils:cc_library"], +) + pl_cc_test_library( name = "mysql_container", srcs = [], diff --git a/src/stirling/source_connectors/socket_tracer/testing/container_images/mongodb_client_container.h b/src/stirling/source_connectors/socket_tracer/testing/container_images/mongodb_client_container.h new file mode 100644 index 00000000000..2ae4244b0a6 --- /dev/null +++ b/src/stirling/source_connectors/socket_tracer/testing/container_images/mongodb_client_container.h @@ -0,0 +1,45 @@ +/* + * Copyright 2018- The Pixie 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. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include + +#include "src/common/testing/test_environment.h" +#include "src/common/testing/test_utils/container_runner.h" + +namespace px { +namespace stirling { +namespace testing { + +class MongoDBClientContainer : public ContainerRunner { + public: + MongoDBClientContainer() + : ContainerRunner(::px::testing::BazelRunfilePath(kBazelImageTar), kContainerNamePrefix, + kReadyMessage) {} + + private: + static constexpr std::string_view kBazelImageTar = + "src/stirling/source_connectors/socket_tracer/testing/containers/mongodb/client_image.tar"; + static constexpr std::string_view kContainerNamePrefix = "mongodb_client"; + static constexpr std::string_view kReadyMessage = "Starting MongoDB client"; +}; + +} // namespace testing +} // namespace stirling +} // namespace px diff --git a/src/stirling/source_connectors/socket_tracer/testing/container_images/mongodb_container.h b/src/stirling/source_connectors/socket_tracer/testing/container_images/mongodb_container.h new file mode 100644 index 00000000000..7750ec32d3c --- /dev/null +++ b/src/stirling/source_connectors/socket_tracer/testing/container_images/mongodb_container.h @@ -0,0 +1,45 @@ +/* + * Copyright 2018- The Pixie 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. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include + +#include "src/common/testing/test_environment.h" +#include "src/common/testing/test_utils/container_runner.h" + +namespace px { +namespace stirling { +namespace testing { + +class MongoDBContainer : public ContainerRunner { + public: + MongoDBContainer() + : ContainerRunner(::px::testing::BazelRunfilePath(kBazelImageTar), kContainerNamePrefix, + kReadyMessage) {} + + private: + static constexpr std::string_view kBazelImageTar = + "src/stirling/source_connectors/socket_tracer/testing/containers/mongodb_image.tar"; + static constexpr std::string_view kContainerNamePrefix = "mongodb_server"; + static constexpr std::string_view kReadyMessage = "Waiting for connections"; +}; + +} // namespace testing +} // namespace stirling +} // namespace px diff --git a/src/stirling/source_connectors/socket_tracer/testing/containers/BUILD.bazel b/src/stirling/source_connectors/socket_tracer/testing/containers/BUILD.bazel index 1174a83d9c1..bbdafff556a 100644 --- a/src/stirling/source_connectors/socket_tracer/testing/containers/BUILD.bazel +++ b/src/stirling/source_connectors/socket_tracer/testing/containers/BUILD.bazel @@ -145,3 +145,8 @@ container_image( name = "productcatalogservice_v0_2_0", base = "@productcatalogservice_v0_2_0//image", ) + +container_image( + name = "mongodb_image", + base = "@mongo_7_0//image", +) diff --git a/src/stirling/source_connectors/socket_tracer/testing/containers/mongodb/BUILD.bazel b/src/stirling/source_connectors/socket_tracer/testing/containers/mongodb/BUILD.bazel new file mode 100644 index 00000000000..824d98bed81 --- /dev/null +++ b/src/stirling/source_connectors/socket_tracer/testing/containers/mongodb/BUILD.bazel @@ -0,0 +1,29 @@ +# Copyright 2018- The Pixie 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. +# +# SPDX-License-Identifier: Apache-2.0 + +load("@io_bazel_rules_docker//python3:image.bzl", "py3_image") +load("@mongodb_bpf_test_requirements//:requirements.bzl", "requirement") + +package(default_visibility = ["//src/stirling:__subpackages__"]) + +py3_image( + name = "client_image", + srcs = ["client.py"], + main = "client.py", + deps = [ + requirement("pymongo"), + ], +) diff --git a/src/stirling/source_connectors/socket_tracer/testing/containers/mongodb/client.py b/src/stirling/source_connectors/socket_tracer/testing/containers/mongodb/client.py new file mode 100644 index 00000000000..af25efa9d9d --- /dev/null +++ b/src/stirling/source_connectors/socket_tracer/testing/containers/mongodb/client.py @@ -0,0 +1,41 @@ +# Copyright 2018- The Pixie 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. +# +# SPDX-License-Identifier: Apache-2.0 + +import pymongo + +print("Starting MongoDB client") + +client = pymongo.MongoClient("mongodb://localhost:27017/?timeoutMS=2000") + +db = client["db"] +collection = db["name"] + +# Insert document +doc = {"name": "foo"} +collection.insert_one(doc) + +# Find document +collection.find_one() + +# Update document +new_doc = {"$set": {"name": "bar"}} +resp = collection.update_one(doc, new_doc) + +# Find updated document +resp = collection.find_one() + +# Delete document +resp = collection.delete_one({"name": "bar"}) diff --git a/src/stirling/source_connectors/socket_tracer/testing/containers/mongodb/requirements.bazel.txt b/src/stirling/source_connectors/socket_tracer/testing/containers/mongodb/requirements.bazel.txt new file mode 100644 index 00000000000..e0de30fe5f6 --- /dev/null +++ b/src/stirling/source_connectors/socket_tracer/testing/containers/mongodb/requirements.bazel.txt @@ -0,0 +1,93 @@ +# +# This file is autogenerated by pip-compile with Python 3.10 +# by the following command: +# +# pip-compile --generate-hashes --output-file=requirements.bazel.txt requirements.txt +# +dnspython==2.4.2 \ + --hash=sha256:57c6fbaaeaaf39c891292012060beb141791735dbb4004798328fc2c467402d8 \ + --hash=sha256:8dcfae8c7460a2f84b4072e26f1c9f4101ca20c071649cb7c34e8b6a93d58984 + # via pymongo +pymongo==4.5.0 \ + --hash=sha256:076afa0a4a96ca9f77fec0e4a0d241200b3b3a1766f8d7be9a905ecf59a7416b \ + --hash=sha256:08819da7864f9b8d4a95729b2bea5fffed08b63d3b9c15b4fea47de655766cf5 \ + --hash=sha256:0a1f26bc1f5ce774d99725773901820dfdfd24e875028da4a0252a5b48dcab5c \ + --hash=sha256:0f4b125b46fe377984fbaecf2af40ed48b05a4b7676a2ff98999f2016d66b3ec \ + --hash=sha256:1240edc1a448d4ada4bf1a0e55550b6292420915292408e59159fd8bbdaf8f63 \ + --hash=sha256:152259f0f1a60f560323aacf463a3642a65a25557683f49cfa08c8f1ecb2395a \ + --hash=sha256:168172ef7856e20ec024fe2a746bfa895c88b32720138e6438fd765ebd2b62dd \ + --hash=sha256:1b1d7d9aabd8629a31d63cd106d56cca0e6420f38e50563278b520f385c0d86e \ + --hash=sha256:1d40ad09d9f5e719bc6f729cc6b17f31c0b055029719406bd31dde2f72fca7e7 \ + --hash=sha256:21b953da14549ff62ea4ae20889c71564328958cbdf880c64a92a48dda4c9c53 \ + --hash=sha256:23cc6d7eb009c688d70da186b8f362d61d5dd1a2c14a45b890bd1e91e9c451f2 \ + --hash=sha256:2988ef5e6b360b3ff1c6d55c53515499de5f48df31afd9f785d788cdacfbe2d3 \ + --hash=sha256:2a0aade2b11dc0c326ccd429ee4134d2d47459ff68d449c6d7e01e74651bd255 \ + --hash=sha256:2b0176f9233a5927084c79ff80b51bd70bfd57e4f3d564f50f80238e797f0c8a \ + --hash=sha256:2d4fa1b01fa7e5b7bb8d312e3542e211b320eb7a4e3d8dc884327039d93cb9e0 \ + --hash=sha256:3236cf89d69679eaeb9119c840f5c7eb388a2110b57af6bb6baf01a1da387c18 \ + --hash=sha256:33faa786cc907de63f745f587e9879429b46033d7d97a7b84b37f4f8f47b9b32 \ + --hash=sha256:37df8f6006286a5896d1cbc3efb8471ced42e3568d38e6cb00857277047b0d63 \ + --hash=sha256:3a7166d57dc74d679caa7743b8ecf7dc3a1235a9fd178654dddb2b2a627ae229 \ + --hash=sha256:3d79ae3bb1ff041c0db56f138c88ce1dfb0209f3546d8d6e7c3f74944ecd2439 \ + --hash=sha256:3e33064f1984db412b34d51496f4ea785a9cff621c67de58e09fb28da6468a52 \ + --hash=sha256:3fa3648e4f1e63ddfe53563ee111079ea3ab35c3b09cd25bc22dadc8269a495f \ + --hash=sha256:40d5f6e853ece9bfc01e9129b228df446f49316a4252bb1fbfae5c3c9dedebad \ + --hash=sha256:41771b22dd2822540f79a877c391283d4e6368125999a5ec8beee1ce566f3f82 \ + --hash=sha256:435228d3c16a375274ac8ab9c4f9aef40c5e57ddb8296e20ecec9e2461da1017 \ + --hash=sha256:44ee985194c426ddf781fa784f31ffa29cb59657b2dba09250a4245431847d73 \ + --hash=sha256:465fd5b040206f8bce7016b01d7e7f79d2fcd7c2b8e41791be9632a9df1b4999 \ + --hash=sha256:496c9cbcb4951183d4503a9d7d2c1e3694aab1304262f831d5e1917e60386036 \ + --hash=sha256:49dce6957598975d8b8d506329d2a3a6c4aee911fa4bbcf5e52ffc6897122950 \ + --hash=sha256:4c42748ccc451dfcd9cef6c5447a7ab727351fd9747ad431db5ebb18a9b78a4d \ + --hash=sha256:505f8519c4c782a61d94a17b0da50be639ec462128fbd10ab0a34889218fdee3 \ + --hash=sha256:53f2dda54d76a98b43a410498bd12f6034b2a14b6844ca08513733b2b20b7ad8 \ + --hash=sha256:56320c401f544d762fc35766936178fbceb1d9261cd7b24fbfbc8fb6f67aa8a5 \ + --hash=sha256:58a63a26a1e3dc481dd3a18d6d9f8bd1d576cd1ffe0d479ba7dd38b0aeb20066 \ + --hash=sha256:5caee7bd08c3d36ec54617832b44985bd70c4cbd77c5b313de6f7fce0bb34f93 \ + --hash=sha256:631492573a1bef2f74f9ac0f9d84e0ce422c251644cd81207530af4aa2ee1980 \ + --hash=sha256:63d8019eee119df308a075b8a7bdb06d4720bf791e2b73d5ab0e7473c115d79c \ + --hash=sha256:6422b6763b016f2ef2beedded0e546d6aa6ba87910f9244d86e0ac7690f75c96 \ + --hash=sha256:681f252e43b3ef054ca9161635f81b730f4d8cadd28b3f2b2004f5a72f853982 \ + --hash=sha256:6d64878d1659d2a5bdfd0f0a4d79bafe68653c573681495e424ab40d7b6d6d41 \ + --hash=sha256:74c0da07c04d0781490b2915e7514b1adb265ef22af039a947988c331ee7455b \ + --hash=sha256:7591a3beea6a9a4fa3080d27d193b41f631130e3ffa76b88c9ccea123f26dc59 \ + --hash=sha256:76a262c41c1a7cbb84a3b11976578a7eb8e788c4b7bfbd15c005fb6ca88e6e50 \ + --hash=sha256:77cfff95c1fafd09e940b3fdcb7b65f11442662fad611d0e69b4dd5d17a81c60 \ + --hash=sha256:8027c9063579083746147cf401a7072a9fb6829678076cd3deff28bb0e0f50c8 \ + --hash=sha256:80a167081c75cf66b32f30e2f1eaee9365af935a86dbd76788169911bed9b5d5 \ + --hash=sha256:840eaf30ccac122df260b6005f9dfae4ac287c498ee91e3e90c56781614ca238 \ + --hash=sha256:8543253adfaa0b802bfa88386db1009c6ebb7d5684d093ee4edc725007553d21 \ + --hash=sha256:89b3f2da57a27913d15d2a07d58482f33d0a5b28abd20b8e643ab4d625e36257 \ + --hash=sha256:8e559116e4128630ad3b7e788e2e5da81cbc2344dee246af44471fa650486a70 \ + --hash=sha256:9aff6279e405dc953eeb540ab061e72c03cf38119613fce183a8e94f31be608f \ + --hash=sha256:9c04b9560872fa9a91251030c488e0a73bce9321a70f991f830c72b3f8115d0d \ + --hash=sha256:9d2346b00af524757576cc2406414562cced1d4349c92166a0ee377a2a483a80 \ + --hash=sha256:a253b765b7cbc4209f1d8ee16c7287c4268d3243070bf72d7eec5aa9dfe2a2c2 \ + --hash=sha256:a8127437ebc196a6f5e8fddd746bd0903a400dc6b5ae35df672dd1ccc7170a2a \ + --hash=sha256:b25f7bea162b3dbec6d33c522097ef81df7c19a9300722fa6853f5b495aecb77 \ + --hash=sha256:b33c17d9e694b66d7e96977e9e56df19d662031483efe121a24772a44ccbbc7e \ + --hash=sha256:b4fe46b58010115514b842c669a0ed9b6a342017b15905653a5b1724ab80917f \ + --hash=sha256:b520aafc6cb148bac09ccf532f52cbd31d83acf4d3e5070d84efe3c019a1adbf \ + --hash=sha256:b5bbb87fa0511bd313d9a2c90294c88db837667c2bda2ea3fa7a35b59fd93b1f \ + --hash=sha256:b6d2a56fc2354bb6378f3634402eec788a8f3facf0b3e7d468db5f2b5a78d763 \ + --hash=sha256:bbd705d5f3c3d1ff2d169e418bb789ff07ab3c70d567cc6ba6b72b04b9143481 \ + --hash=sha256:bc5d8c3647b8ae28e4312f1492b8f29deebd31479cd3abaa989090fb1d66db83 \ + --hash=sha256:c3c3525ea8658ee1192cdddf5faf99b07ebe1eeaa61bf32821126df6d1b8072b \ + --hash=sha256:c9a9a39b7cac81dca79fca8c2a6479ef4c7b1aab95fad7544cc0e8fd943595a2 \ + --hash=sha256:cd4c8d6aa91d3e35016847cbe8d73106e3d1c9a4e6578d38e2c346bfe8edb3ca \ + --hash=sha256:cf62da7a4cdec9a4b2981fcbd5e08053edffccf20e845c0b6ec1e77eb7fab61d \ + --hash=sha256:d67225f05f6ea27c8dc57f3fa6397c96d09c42af69d46629f71e82e66d33fa4f \ + --hash=sha256:dfcd2b9f510411de615ccedd47462dae80e82fdc09fe9ab0f0f32f11cf57eeb5 \ + --hash=sha256:e1f61355c821e870fb4c17cdb318669cfbcf245a291ce5053b41140870c3e5cc \ + --hash=sha256:e249190b018d63c901678053b4a43e797ca78b93fb6d17633e3567d4b3ec6107 \ + --hash=sha256:e2654d1278384cff75952682d17c718ecc1ad1d6227bb0068fd826ba47d426a5 \ + --hash=sha256:e57d859b972c75ee44ea2ef4758f12821243e99de814030f69a3decb2aa86807 \ + --hash=sha256:e5a27f348909235a106a3903fc8e70f573d89b41d723a500869c6569a391cff7 \ + --hash=sha256:ead4f19d0257a756b21ac2e0e85a37a7245ddec36d3b6008d5bfe416525967dc \ + --hash=sha256:f076b779aa3dc179aa3ed861be063a313ed4e48ae9f6a8370a9b1295d4502111 \ + --hash=sha256:f1bb3a62395ffe835dbef3a1cbff48fbcce709c78bd1f52e896aee990928432b \ + --hash=sha256:f2227a08b091bd41df5aadee0a5037673f691e2aa000e1968b1ea2342afc6880 \ + --hash=sha256:f3754acbd7efc7f1b529039fcffc092a15e1cf045e31f22f6c9c5950c613ec4d \ + --hash=sha256:fe48f50fb6348511a3268a893bfd4ab5f263f5ac220782449d03cd05964d1ae7 \ + --hash=sha256:fff7d17d30b2cd45afd654b3fc117755c5d84506ed25fda386494e4e0a3416e1 + # via -r requirements.txt diff --git a/src/stirling/source_connectors/socket_tracer/testing/containers/mongodb/requirements.txt b/src/stirling/source_connectors/socket_tracer/testing/containers/mongodb/requirements.txt new file mode 100644 index 00000000000..78cf745f085 --- /dev/null +++ b/src/stirling/source_connectors/socket_tracer/testing/containers/mongodb/requirements.txt @@ -0,0 +1 @@ +pymongo==4.5.0 diff --git a/src/stirling/source_connectors/socket_tracer/testing/protocol_checkers.cc b/src/stirling/source_connectors/socket_tracer/testing/protocol_checkers.cc index 8951cad7143..273e3dba17c 100644 --- a/src/stirling/source_connectors/socket_tracer/testing/protocol_checkers.cc +++ b/src/stirling/source_connectors/socket_tracer/testing/protocol_checkers.cc @@ -27,6 +27,7 @@ namespace testing { namespace http = protocols::http; namespace mux = protocols::mux; +namespace mongodb = protocols::mongodb; //----------------------------------------------------------------------------- // HTTP Checkers @@ -64,6 +65,22 @@ std::vector ToRecordVector(const types::ColumnWrapperRec return result; } +template <> +std::vector ToRecordVector(const types::ColumnWrapperRecordBatch& rb, + const std::vector& indices) { + std::vector result; + + for (const auto& idx : indices) { + mongodb::Record r; + r.req.op_msg_type = std::string(rb[kMongoDBReqCmdIdx]->Get(idx)); + r.req.frame_body = std::string(rb[kMongoDBReqBodyIdx]->Get(idx)); + r.resp.op_msg_type = std::string(rb[kMongoDBRespStatusIdx]->Get(idx)); + r.resp.frame_body = std::string(rb[kMongoDBRespBodyIdx]->Get(idx)); + result.push_back(r); + } + return result; +} + template <> std::vector GetTargetRecords(const types::ColumnWrapperRecordBatch& record_batch, int32_t pid) { @@ -80,6 +97,14 @@ std::vector GetTargetRecords(const types::ColumnWrapperRecordBatch& return ToRecordVector(record_batch, target_record_indices); } +template <> +std::vector GetTargetRecords(const types::ColumnWrapperRecordBatch& record_batch, + int32_t pid) { + std::vector target_record_indices = + FindRecordIdxMatchesPID(record_batch, kMongoDBUPIDIdx, pid); + return ToRecordVector(record_batch, target_record_indices); +} + } // namespace testing } // namespace stirling } // namespace px diff --git a/src/stirling/source_connectors/socket_tracer/testing/protocol_checkers.h b/src/stirling/source_connectors/socket_tracer/testing/protocol_checkers.h index f17d7bf0eb0..e2b60eb2102 100644 --- a/src/stirling/source_connectors/socket_tracer/testing/protocol_checkers.h +++ b/src/stirling/source_connectors/socket_tracer/testing/protocol_checkers.h @@ -27,8 +27,10 @@ #include "src/shared/types/column_wrapper.h" #include "src/stirling/source_connectors/socket_tracer/http_table.h" +#include "src/stirling/source_connectors/socket_tracer/mongodb_table.h" #include "src/stirling/source_connectors/socket_tracer/mux_table.h" #include "src/stirling/source_connectors/socket_tracer/protocols/http/types.h" +#include "src/stirling/source_connectors/socket_tracer/protocols/mongodb/types.h" #include "src/stirling/source_connectors/socket_tracer/protocols/mux/types.h" namespace px {