Skip to content

Commit b2ef3ef

Browse files
ddelnanok8sstormcenter-buildbot
authored andcommitted
Reduce boiler plate for Go container image C++ headers (pixie-io#2307)
Summary: Reduce boiler plate for Go container image C++ headers Previously, adding a new Go version required: 1. Creating new header files for each container type (grpc_server, grpc_client, tls_server, tls_client) 2. Adding BUILD.bazel entries for each new library 3. Updating test files with new #include statements These header files account for ~100-200 lines of boilerplate code per Go version (~50 lines for each grpc and tls client/server pair) and add overhead when upgrading our Go version. This PR reduces this boilerplate by generating these files with a new Bazel macro `go_container_libraries`. This macro generates: - Individual C++ headers for each version (e.g., `go_1_24_grpc_server_container.h`) - Aggregate headers that include all versions for a given container type (e.g., `go_grpc_server_containers.h`, `go_tls_client_containers.h`) Relevant Issues: N/A Type of change: /kind cleanup Test Plan: Build should succeed Signed-off-by: Dom Del Nano <ddelnano@gmail.com> GitOrigin-RevId: ce714e6
1 parent e502caa commit b2ef3ef

5 files changed

Lines changed: 10 additions & 89 deletions

File tree

src/api/python/BUILD.bazel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ py_wheel(
3737
python_requires = ">=3.12, < 3.14",
3838
python_tag = "py3",
3939
requires = [
40-
"Authlib>=1.6.0,<1.7.0",
40+
"Authlib==1.5.1",
4141
"grpcio==1.76.0",
4242
"grpcio-tools==1.76.0",
4343
"protobuf==6.33.1",
4444
],
4545
strip_path_prefixes = ["src/api/python/"],
46-
version = "0.9.1",
46+
version = "0.9.0",
4747
deps = [
4848
"//src/api/python/pxapi:pxapi_library",
4949
"//src/api/python/pxapi/proto:pxapi_py_proto_library",

src/api/python/requirements.bazel.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
#
55
# pip-compile --allow-unsafe --generate-hashes --output-file=requirements.bazel.txt requirements.txt
66
#
7-
authlib==1.6.9 \
8-
--hash=sha256:d8f2421e7e5980cc1ddb4e32d3f5fa659cfaf60d8eaf3281ebed192e4ab74f04 \
9-
--hash=sha256:f08b4c14e08f0861dc18a32357b33fbcfd2ea86cfe3fe149484b4d764c4a0ac3
7+
authlib==1.5.1 \
8+
--hash=sha256:5cbc85ecb0667312c1cdc2f9095680bb735883b123fb509fde1e65b1c5df972e \
9+
--hash=sha256:8408861cbd9b4ea2ff759b00b6f02fd7d81ac5a56d0b2b22c08606c6049aae11
1010
# via -r requirements.txt
1111
cffi==2.0.0 \
1212
--hash=sha256:00bdf7acc5f795150faa6957054fbbca2439db2f775ce831222b66f192f03beb \

src/api/python/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Authlib>=1.6.0,<1.7.0
1+
Authlib==1.5.1
22
grpcio==1.76.0
33
grpcio-tools==1.76.0
44
protobuf==6.33.1

src/shared/metadata/cgroup_path_resolver.cc

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -70,24 +70,13 @@ StatusOr<std::vector<std::string>> CGroupBasePaths(std::string_view sysfs_path)
7070

7171
StatusOr<std::string> FindSelfCGroupProcs(std::string_view base_path) {
7272
int pid = getpid();
73-
std::error_code ec;
7473

75-
auto it = std::filesystem::recursive_directory_iterator(
76-
base_path, std::filesystem::directory_options::skip_permission_denied, ec);
77-
if (ec) {
78-
return error::Internal("Failed to iterate cgroup path: $0", ec.message());
79-
}
80-
81-
for (auto end = std::filesystem::recursive_directory_iterator(); it != end; it.increment(ec)) {
82-
if (ec) {
83-
ec.clear();
84-
continue;
85-
}
86-
if (it->path().filename() == "cgroup.procs") {
87-
std::string contents = ReadFileToString(it->path().string()).ValueOr("");
74+
for (auto& p : std::filesystem::recursive_directory_iterator(base_path)) {
75+
if (p.path().filename() == "cgroup.procs") {
76+
std::string contents = ReadFileToString(p.path().string()).ValueOr("");
8877
int contents_pid;
8978
if (absl::SimpleAtoi(contents, &contents_pid) && pid == contents_pid) {
90-
return it->path().string();
79+
return p.path().string();
9180
}
9281
}
9382
}

src/shared/metadata/cgroup_path_resolver_test.cc

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,11 @@
1616
* SPDX-License-Identifier: Apache-2.0
1717
*/
1818

19-
#include <sys/stat.h>
20-
#include <unistd.h>
21-
2219
#include <gtest/gtest.h>
2320

24-
#include <fstream>
2521
#include <string>
2622
#include <vector>
2723

28-
#include "src/common/testing/temp_dir.h"
2924
#include "src/common/testing/testing.h"
3025
#include "src/shared/metadata/cgroup_path_resolver.h"
3126

@@ -395,68 +390,5 @@ TEST(CGroupPathResolver, Cgroup2Format) {
395390
* 4. cgroup1+cgroup2 w/ cgroup1 succeeding
396391
*/
397392

398-
// Test that FindSelfCGroupProcs gracefully handles permission-denied directories
399-
// (e.g. CrowdStrike Falcon's sandbox.falcon) instead of crashing with an uncaught exception.
400-
TEST(FindSelfCGroupProcs, SkipsPermissionDeniedDirectories) {
401-
// This test requires running as non-root, since root bypasses permission checks.
402-
if (getuid() == 0) {
403-
GTEST_SKIP() << "Test requires non-root user";
404-
}
405-
406-
px::testing::TempDir tmp_dir;
407-
auto base_path = tmp_dir.path();
408-
409-
// Create a directory structure with an accessible cgroup.procs containing our PID,
410-
// and a restricted directory that simulates CrowdStrike Falcon's sandbox.
411-
auto accessible_dir = base_path / "kubepods" / "pod1234";
412-
std::filesystem::create_directories(accessible_dir);
413-
414-
// Write our PID to cgroup.procs so FindSelfCGroupProcs can find it.
415-
{
416-
std::ofstream ofs((accessible_dir / "cgroup.procs").string());
417-
ofs << getpid();
418-
}
419-
420-
// Create a restricted directory that the iterator cannot enter.
421-
auto restricted_dir = base_path / "system.slice" / "falcon-sensor.service" / "sandbox.falcon";
422-
std::filesystem::create_directories(restricted_dir);
423-
// Remove all permissions on the sandbox directory.
424-
chmod(restricted_dir.c_str(), 0000);
425-
426-
// FindSelfCGroupProcs should succeed and find our cgroup.procs,
427-
// skipping the restricted directory instead of throwing.
428-
ASSERT_OK_AND_ASSIGN(auto result, FindSelfCGroupProcs(base_path.string()));
429-
EXPECT_EQ(result, (accessible_dir / "cgroup.procs").string());
430-
431-
// Restore permissions so TempDir cleanup can remove it.
432-
chmod(restricted_dir.c_str(), 0755);
433-
}
434-
435-
// Test that FindSelfCGroupProcs returns NotFound (not a crash) when the only
436-
// cgroup.procs is behind a restricted directory.
437-
TEST(FindSelfCGroupProcs, ReturnsNotFoundWhenAllPathsRestricted) {
438-
if (getuid() == 0) {
439-
GTEST_SKIP() << "Test requires non-root user";
440-
}
441-
442-
px::testing::TempDir tmp_dir;
443-
auto base_path = tmp_dir.path();
444-
445-
// Put cgroup.procs inside a restricted directory so it's unreachable.
446-
auto restricted_dir = base_path / "restricted";
447-
std::filesystem::create_directories(restricted_dir);
448-
{
449-
std::ofstream ofs((restricted_dir / "cgroup.procs").string());
450-
ofs << getpid();
451-
}
452-
chmod(restricted_dir.c_str(), 0000);
453-
454-
// Should return NotFound, not crash.
455-
auto result = FindSelfCGroupProcs(base_path.string());
456-
EXPECT_NOT_OK(result);
457-
458-
chmod(restricted_dir.c_str(), 0755);
459-
}
460-
461393
} // namespace md
462394
} // namespace px

0 commit comments

Comments
 (0)