-
Notifications
You must be signed in to change notification settings - Fork 443
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: Creates a demo app running rabbitmq to test amqp bpf Test Plan: This can be tested via the full BPF test in another PR Reviewers: #third_party_approvers, #stirling, yzhao, vihang Reviewed By: #third_party_approvers, #stirling, yzhao, vihang Subscribers: vihang, rcheng, yzhao Signed-off-by: Vikranth Srivatsa <[email protected]> Differential Revision: https://phab.corp.pixielabs.ai/D11791 GitOrigin-RevId: 8045746
- Loading branch information
1 parent
9aa64f2
commit 8966ea0
Showing
11 changed files
with
315 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
src/stirling/source_connectors/socket_tracer/amqp_bpf_test.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
* 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 <gmock/gmock.h> | ||
#include <gtest/gtest.h> | ||
|
||
#include <regex> | ||
#include <string> | ||
|
||
#include <absl/strings/str_replace.h> | ||
|
||
#include "src/common/base/base.h" | ||
#include "src/common/exec/exec.h" | ||
#include "src/common/testing/test_utils/container_runner.h" | ||
#include "src/common/testing/testing.h" | ||
#include "src/stirling/source_connectors/socket_tracer/testing/container_images.h" | ||
#include "src/stirling/source_connectors/socket_tracer/testing/socket_trace_bpf_test_fixture.h" | ||
#include "src/stirling/testing/common.h" | ||
|
||
namespace px { | ||
namespace stirling { | ||
|
||
using ::px::stirling::testing::FindRecordIdxMatchesPID; | ||
using ::px::stirling::testing::SocketTraceBPFTestFixture; | ||
using ::px::testing::BazelRunfilePath; | ||
using ::testing::AllOf; | ||
using ::testing::Contains; | ||
using ::testing::Eq; | ||
using ::testing::Field; | ||
using ::testing::HasSubstr; | ||
using ::testing::StrEq; | ||
using ::px::operator<<; | ||
|
||
class AMQPTraceTest : public SocketTraceBPFTestFixture</* TClientSideTracing */ true> { | ||
protected: | ||
StatusOr<int32_t> GetPIDFromOutput(std::string_view out) { | ||
std::vector<std::string_view> lines = absl::StrSplit(out, "\n"); | ||
if (lines.empty()) { | ||
return error::Internal("Executed output (pid) from command."); | ||
} | ||
|
||
int32_t client_pid; | ||
if (!absl::SimpleAtoi(lines[0], &client_pid)) { | ||
return error::Internal("Could not extract PID."); | ||
} | ||
|
||
return client_pid; | ||
} | ||
|
||
void RunAll() { | ||
rabbitmq_server_.Run(std::chrono::seconds{120}); | ||
rabbitmq_consumer_.Run( | ||
std::chrono::seconds{120}, | ||
{absl::Substitute("--network=container:$0", rabbitmq_server_.container_name())}); | ||
|
||
rabbitmq_producer_.Run( | ||
std::chrono::seconds{120}, | ||
{absl::Substitute("--network=container:$0", rabbitmq_server_.container_name())}); | ||
} | ||
|
||
::px::stirling::testing::RabbitMQConsumer rabbitmq_consumer_; | ||
::px::stirling::testing::RabbitMQProducer rabbitmq_producer_; | ||
::px::stirling::testing::RabbitMQContainer rabbitmq_server_; | ||
}; | ||
|
||
struct AMQPTraceRecord { | ||
int64_t ts_ns = 0; | ||
std::string frame_type; | ||
std::string class_id; | ||
std::string method_id; | ||
std::string channel; | ||
|
||
std::string ToString() const { | ||
return absl::Substitute("ts_ns=$0 frame_type=$1 class_id=$2 method_id=$3 channel=$4", ts_ns, | ||
frame_type, class_id, method_id, channel); | ||
} | ||
}; | ||
|
||
TEST_F(AMQPTraceTest, AMQPCapture) { | ||
StartTransferDataThread(); | ||
RunAll(); | ||
StopTransferDataThread(); | ||
} | ||
|
||
} // namespace stirling | ||
} // namespace px |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/stirling/source_connectors/socket_tracer/testing/containers/amqp/BUILD.bazel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# 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("@amqp_bpf_test_requirements//:requirements.bzl", "requirement") | ||
load("@io_bazel_rules_docker//python3:image.bzl", "py3_image") | ||
|
||
package(default_visibility = ["//src/stirling:__subpackages__"]) | ||
|
||
py3_image( | ||
name = "consumer_image", | ||
srcs = ["consumer.py"], | ||
main = "consumer.py", | ||
deps = [ | ||
requirement("pika"), | ||
], | ||
) | ||
|
||
py3_image( | ||
name = "producer_image", | ||
srcs = ["producer.py"], | ||
main = "producer.py", | ||
deps = [ | ||
requirement("pika"), | ||
], | ||
) |
50 changes: 50 additions & 0 deletions
50
src/stirling/source_connectors/socket_tracer/testing/containers/amqp/consumer.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# 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 pika | ||
import sys | ||
import os | ||
|
||
connection = pika.BlockingConnection(pika.ConnectionParameters(host="localhost")) | ||
|
||
|
||
def main(queue_name="queue_1"): | ||
channel = connection.channel() | ||
channel.queue_declare(queue=queue_name) | ||
|
||
def callback(ch, method, properties, body): | ||
print("Received message") | ||
print(" [x] Received %r" % body) | ||
|
||
channel.basic_consume(queue=queue_name, on_message_callback=callback, auto_ack=True) | ||
print("Starting AMQP consumer", file=sys.stderr) | ||
print(" [*] Waiting for messages. To exit press CTRL+C") | ||
channel.start_consuming() | ||
|
||
|
||
def main_handler(queue_name): | ||
try: | ||
main(queue_name) | ||
except KeyboardInterrupt: | ||
print("Interrupted") | ||
try: | ||
sys.exit(0) | ||
except SystemExit: | ||
os._exit(0) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
35 changes: 35 additions & 0 deletions
35
src/stirling/source_connectors/socket_tracer/testing/containers/amqp/producer.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# 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 pika | ||
import time | ||
import sys | ||
|
||
connection = pika.BlockingConnection(pika.ConnectionParameters(host="localhost")) | ||
channel = connection.channel() | ||
|
||
|
||
channel.queue_declare(queue="queue_1") | ||
print("Starting AMQP producer", file=sys.stderr) | ||
|
||
try: | ||
while True: | ||
new_body = "hello" | ||
channel.basic_publish(exchange="", routing_key="queue_1", body=new_body) | ||
time.sleep(1) | ||
print("Completed") | ||
finally: | ||
connection.close() |
1 change: 1 addition & 0 deletions
1
src/stirling/source_connectors/socket_tracer/testing/containers/amqp/requirements.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pika==1.3.0 |