Skip to content

Commit e654f53

Browse files
committed
Try without old rt profile
Signed-off-by: Kateryna Nezdolii <kateryna.nezdolii@gmail.com>
1 parent 50f0fa6 commit e654f53

14 files changed

Lines changed: 829 additions & 48 deletions

File tree

.github/workflows/ci-check-coverage.yaml

Lines changed: 52 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ jobs:
3333
uses: google-github-actions/auth@v2
3434
with:
3535
credentials_json: ${{ secrets.CI_CILIUM_PROXY_SA_KEY }}
36+
- name: set up google cloud sdk
37+
uses: 'google-github-actions/setup-gcloud@v2'
38+
with:
39+
version: '>= 507.0.0'
3640
- name: Install deps (for C++)
3741
shell: bash
3842
run: |
@@ -45,46 +49,56 @@ jobs:
4549
sudo apt-add-repository -y "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-18 main" && \
4650
sudo apt-get update && \
4751
sudo apt-get install -y --no-install-recommends \
48-
clang-18 clangd-18 clang-tidy-18 clang-tools-18 llvm-18-dev lldb-18 lld-18 clang-format-18 libc++-18-dev libc++abi-18-dev && \
52+
clang-18 clangd-18 clang-tidy-18 clang-tools-18 llvm-18-dev lldb-18 lld-18 clang-format-18 libc++-18-dev libc++abi-18-dev libclang-rt-18-dev lcov && \
4953
sudo apt-get purge --auto-remove && \
5054
sudo apt-get clean && \
5155
sudo rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
5256
cp /usr/lib/llvm-18/bin/llvm-cov /usr/local/bin
5357
cp /usr/lib/llvm-18/bin/llvm-profdata /usr/local/bin
54-
#libclang_rt.profile is not installed from deb repo, doing this hack for now...
55-
sudo mkdir -p /usr/lib/llvm-18/lib/clang/18/lib/linux/
56-
sudo cp /usr/lib/llvm-15/lib/clang/15.0.7/lib/linux/libclang_rt.profile-x86_64.a /usr/lib/llvm-18/lib/clang/18/lib/linux/
57-
clang --version
58-
llvm-config --version
59-
# - name: Install Go
60-
# uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
61-
# with:
62-
# # renovate: datasource=golang-version depName=go
63-
# go-version: 1.24.6
64-
# - name: Sync crate lockfile with bazel
65-
# shell: bash
66-
# run: |
67-
# CARGO_BAZEL_ISOLATED=0 CARGO_BAZEL_REPIN=1 bazel sync --only=crate_index
68-
# - name: Build proxylib
69-
# shell: bash
70-
# run: |
71-
# go version
72-
# # go mod tidy
73-
# # go mod vendor
74-
# # test -z "$(git status --porcelain)" || (echo "please run 'go mod tidy && go mod vendor', and submit your changes"; exit 1)
75-
# make -C proxylib
76-
# - name: Build test deps
77-
# shell: bash
78-
# run: |
79-
# BAZEL_BUILD_OPTS="${BAZEL_BUILD_OPTS} --remote_cache=https://storage.googleapis.com/cilium-proxy-bazel-remote-cache --google_default_credentials" BAZEL_TEST_OPTS="--test_timeout=300 --local_test_jobs=1 --flaky_test_attempts=3" make envoy-test-deps
80-
# - name: Generate coverage data
81-
# shell: bash
82-
# run: |
83-
# echo "Generating bazel coverage: "
84-
# ./tests/run_bazel_coverage.sh
85-
86-
#TODO(nezdolik)
87-
# - name: Display coverage data
88-
89-
90-
58+
- name: Install Go
59+
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
60+
with:
61+
# renovate: datasource=golang-version depName=go
62+
go-version: 1.24.6
63+
- name: Sync crate lockfile with bazel
64+
shell: bash
65+
run: |
66+
CARGO_BAZEL_ISOLATED=0 CARGO_BAZEL_REPIN=1 bazel sync --only=crate_index
67+
- name: Build proxylib
68+
shell: bash
69+
run: |
70+
go version
71+
make -C proxylib
72+
- name: Build test deps
73+
shell: bash
74+
run: |
75+
BAZEL_BUILD_OPTS="${BAZEL_BUILD_OPTS} --remote_cache=${{ vars.GCS_ARTIFACT_BUCKET_REMOTE_CACHE }} --google_default_credentials" BAZEL_TEST_OPTS="--test_timeout=300 --local_test_jobs=1 --flaky_test_attempts=3" make envoy-test-deps
76+
- name: Generate coverage data
77+
shell: bash
78+
run: |
79+
echo "Generating bazel coverage: "
80+
./tests/run_bazel_coverage.sh
81+
ls -la /home/runner/work/cilium-proxy/cilium-proxy/generated/coverage/
82+
- name: Upload (sync) to GCS bucket
83+
if: '!cancelled()'
84+
shell: bash
85+
run: |
86+
UPLOAD_DIR="/home/runner/work/cilium-proxy/cilium-proxy/generated/coverage/"
87+
SHA=${{ github.sha }}
88+
BUCKET_PATH="${{ vars.GCS_ARTIFACT_BUCKET_COVERAGE }}/${SHA:0:7}/coverage"
89+
echo "Uploading to gs://$BUCKET_PATH ..."
90+
gsutil \
91+
-mq rsync \
92+
-dr "$UPLOAD_DIR" \
93+
"gs://$BUCKET_PATH"
94+
echo "Artifacts uploaded to: https://storage.googleapis.com/$BUCKET_PATH/html/index.html" >&2
95+
strategy:
96+
fail-fast: false
97+
matrix:
98+
include:
99+
- target: coverage
100+
name: Coverage
101+
diskspace-hack: true
102+
diskspace-hack-paths: |
103+
/opt/hostedtoolcache
104+
/usr/local/lib/android

WORKSPACE

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ git_repository(
4949
# // clang-format on
5050
)
5151

52+
load("//bazel:repo.bzl", "cilium_proxy_repo")
53+
54+
cilium_proxy_repo()
55+
5256
#
5357
# Bazel does not do transitive dependencies, so we must basically
5458
# include all of Envoy's WORKSPACE file below, with the following

bazel/repo.bzl

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# `@cilium_proxy_repo` repository rule for managing the repo and querying its metadata.
2+
3+
def _cilium_proxy_repo_impl(repository_ctx):
4+
"""This provides information about the Envoy repository
5+
6+
You can access the current project and api versions and the path to the repository in
7+
.bzl/BUILD files as follows:
8+
9+
```starlark
10+
load("@cilium_proxy_repo//:version.bzl", "VERSION", "API_VERSION")
11+
```
12+
13+
`*VERSION` can be used to derive version-specific rules and can be passed
14+
to the rules.
15+
16+
The `VERSION`s and also the local `PATH` to the repo can be accessed in
17+
python libraries/binaries. By adding `@cilium_proxy_repo` to `deps` they become
18+
importable through the `cilium_proxy_repo` namespace.
19+
20+
As the `PATH` is local to the machine, it is generally only useful for
21+
jobs that will run locally.
22+
23+
This can be useful, for example, for bazel run jobs to run bazel queries that cannot be run
24+
within the constraints of a `genquery`, or that otherwise need access to the repository
25+
files.
26+
27+
Project and repo data can be accessed in JSON format using `@cilium_proxy_repo//:project`, eg:
28+
29+
```starlark
30+
load("@aspect_bazel_lib//lib:jq.bzl", "jq")
31+
32+
jq(
33+
name = "project_version",
34+
srcs = ["@cilium_proxy_repo//:data"],
35+
out = "version.txt",
36+
args = ["-r"],
37+
filter = ".version",
38+
)
39+
40+
```
41+
42+
"""
43+
repo_version_path = repository_ctx.path(repository_ctx.attr.envoy_version)
44+
api_version_path = repository_ctx.path(repository_ctx.attr.envoy_api_version)
45+
version = repository_ctx.read(repo_version_path).strip()
46+
api_version = repository_ctx.read(api_version_path).strip()
47+
repository_ctx.file("version.bzl", "VERSION = '%s'\nAPI_VERSION = '%s'" % (version, api_version))
48+
repository_ctx.file("path.bzl", "PATH = '%s'" % repo_version_path.dirname)
49+
repository_ctx.file("__init__.py", "PATH = '%s'\nVERSION = '%s'\nAPI_VERSION = '%s'" % (repo_version_path.dirname, version, api_version))
50+
repository_ctx.file("WORKSPACE", "")
51+
repository_ctx.file("BUILD", '''
52+
load("@rules_python//python:defs.bzl", "py_library")
53+
load("@rules_python//python/entry_points:py_console_script_binary.bzl", "py_console_script_binary")
54+
load("//:path.bzl", "PATH")
55+
56+
py_library(
57+
name = "cilium_proxy_repo",
58+
srcs = ["__init__.py"],
59+
visibility = ["//visibility:public"],
60+
)
61+
62+
''')
63+
64+
_cilium_proxy_repo = repository_rule(
65+
implementation = _cilium_proxy_repo_impl,
66+
attrs = {
67+
#todo(nezdolik) add cilium version
68+
"envoy_version": attr.label(default = "@envoy//:VERSION.txt"),
69+
"envoy_api_version": attr.label(default = "@envoy//:API_VERSION.txt"),
70+
},
71+
)
72+
73+
def cilium_proxy_repo():
74+
if "cilium_proxy_repo" not in native.existing_rules().keys():
75+
_cilium_proxy_repo(name = "cilium_proxy_repo")

envoy.bazelrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ build:coverage --linkopt=-Wl,-s,--no-relax
262262
build:coverage --test_env=ENVOY_IP_TEST_VERSIONS=v4only
263263
build:coverage --define=dynamic_link_tests=false
264264
# Use custom report generator that also generates HTML
265-
build:coverage --coverage_report_generator=@envoy//tools/coverage:report_generator
265+
build:coverage --coverage_report_generator=//tools/coverage:cilium_report_generator
266266

267267
build:test-coverage --test_arg="-l trace"
268268
build:test-coverage --test_arg="--log-path /dev/null"

tests/BUILD

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
load("@aspect_bazel_lib//lib:yq.bzl", "yq")
12
load(
23
"@envoy//bazel:envoy_build_system.bzl",
34
"envoy_cc_test",
@@ -18,6 +19,14 @@ api_cc_py_proto_library(
1819
srcs = ["bpf_metadata.proto"],
1920
)
2021

22+
yq(
23+
name = "coverage_config",
24+
srcs = [":coverage.yaml"],
25+
outs = ["cilium_coverage_config.json"],
26+
args = ["-o=json"],
27+
visibility = ["//visibility:public"],
28+
)
29+
2130
envoy_cc_test_library(
2231
name = "accesslog_server_lib",
2332
srcs = ["accesslog_server.cc"],

tests/coverage.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
thresholds:
2+
total: 95.0
3+
per_directory: 95.0
4+
5+
directories:
6+
cilium: 95.0
7+
linux: 95.0

tests/run_bazel_coverage.sh

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,24 @@ else
4242
COVERAGE_TARGETS=(//tests/...)
4343
fi
4444

45-
BAZEL_COVERAGE_OPTIONS=(--heap_dump_on_oom)
45+
BAZEL_COVERAGE_OPTIONS=()
46+
BAZEL_COVERAGE_OPTIONS+=(--heap_dump_on_oom)
47+
BAZEL_COVERAGE_OPTIONS+=(--action_env=BAZEL_USE_LLVM_NATIVE_COVERAGE=1)
48+
BAZEL_COVERAGE_OPTIONS+=(--combined_report=lcov)
49+
BAZEL_COVERAGE_OPTIONS+=(--coverage_report_generator=//tools/coverage:cilium_report_generator)
50+
BAZEL_COVERAGE_OPTIONS+=(--experimental_use_llvm_covmap)
51+
BAZEL_COVERAGE_OPTIONS+=(--experimental_generate_llvm_lcov)
52+
BAZEL_COVERAGE_OPTIONS+=(--experimental_split_coverage_postprocessing)
53+
BAZEL_COVERAGE_OPTIONS+=(--experimental_fetch_all_coverage_outputs)
54+
BAZEL_COVERAGE_OPTIONS+=(--collect_code_coverage)
55+
BAZEL_COVERAGE_OPTIONS+=(--remote_download_minimal)
56+
BAZEL_COVERAGE_OPTIONS+=(--copt=-DNDEBUG)
57+
BAZEL_COVERAGE_OPTIONS+=(--build_tests_only)
58+
#from envoy
59+
BAZEL_COVERAGE_OPTIONS+=(--experimental_repository_cache_hardlinks)
60+
BAZEL_COVERAGE_OPTIONS+=(--verbose_failures)
61+
BAZEL_COVERAGE_OPTIONS+=(--experimental_generate_json_trace_profile)
62+
BAZEL_COVERAGE_OPTIONS+=(--action_env=GCOV=llvm-profdata)
4663
BAZEL_VALIDATE_OPTIONS=()
4764

4865

@@ -53,6 +70,9 @@ BAZEL_BUILD_OPTIONS+=("--google_default_credentials")
5370

5471
COVERAGE_DIR="${SRCDIR}/generated/coverage"
5572

73+
COVERAGE_DATA="${COVERAGE_DIR}/coverage.dat"
74+
75+
5676
run_coverage() {
5777
echo "Running bazel coverage with:"
5878
echo " Options: ${BAZEL_BUILD_OPTIONS[*]} ${BAZEL_COVERAGE_OPTIONS[*]}"
@@ -68,15 +88,25 @@ run_coverage() {
6888
fi
6989
}
7090

71-
render_coverage_results() {
72-
declare -r COVERAGE_DIR="${SRCDIR}"/generated/coverage
73-
declare -r COVERAGE_SUMMARY="${COVERAGE_DIR}/coverage_summary.txt"
74-
mkdir -p "${COVERAGE_DIR}"
75-
genhtml bazel-out/_coverage/_coverage_report.dat --output-directory="${COVERAGE_DIR}" | tee "${COVERAGE_SUMMARY}"
91+
unpack_coverage_results() {
92+
rm -rf "${COVERAGE_DIR}"
93+
mkdir -p "${COVERAGE_DIR}"
94+
rm -f bazel-out/_coverage/_coverage_report.tar.zst
95+
mv bazel-out/_coverage/_coverage_report.dat bazel-out/_coverage/_coverage_report.tar.zst
96+
bazel run "${BAZEL_BUILD_OPTIONS[@]}" --nobuild_tests_only @envoy//tools/zstd -- -d -c "${PWD}/bazel-out/_coverage/_coverage_report.tar.zst" \
97+
| tar -xf - -C "${COVERAGE_DIR}"
98+
COVERAGE_JSON="${COVERAGE_DIR}/coverage.json"
7699
}
77100

78-
101+
validate_coverage() {
102+
bazel run \
103+
"${BAZEL_BUILD_OPTIONS[@]}" \
104+
"${BAZEL_VALIDATE_OPTIONS[@]}" \
105+
--nobuild_tests_only \
106+
//tools/coverage:validate \
107+
"$COVERAGE_JSON"
108+
}
79109

80110
run_coverage
81-
render_coverage_results
82-
111+
unpack_coverage_results
112+
validate_coverage

tools/coverage/BUILD

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
load("@aspect_bazel_lib//lib:jq.bzl", "jq")
2+
load("@cilium_proxy_repo//:path.bzl", "PATH")
3+
load("@rules_shell//shell:sh_binary.bzl", "sh_binary")
4+
load("@envoy//bazel:envoy_build_system.bzl", "envoy_package")
5+
6+
licenses(["notice"]) # Apache 2
7+
8+
envoy_package()
9+
10+
exports_files(glob(["templates/*.html"]))
11+
12+
genrule(
13+
name = "grcov",
14+
srcs = ["@grcov"],
15+
outs = ["grcov_bin"],
16+
cmd = "cp $< $@ && chmod +x $@",
17+
executable = True,
18+
visibility = ["//visibility:public"],
19+
)
20+
21+
jq(
22+
name = "grcov_config",
23+
srcs = [],
24+
out = "grcov_config.json",
25+
args = [
26+
"-sR",
27+
"--arg",
28+
"macros",
29+
"$(location :templates/macros.html)",
30+
"--arg",
31+
"base",
32+
"$(location :templates/base.html)",
33+
"--arg",
34+
"index",
35+
"$(location :templates/index.html)",
36+
],
37+
data = [
38+
":templates/base.html",
39+
":templates/index.html",
40+
":templates/macros.html",
41+
],
42+
expand_args = True,
43+
filter = """
44+
{templates: {
45+
"base.html": $base,
46+
"index.html": $index,
47+
"macros.html": $macros}}
48+
""",
49+
)
50+
51+
# This is a bit of a hack, and totally non-hermetic
52+
# grcov needs access to the source files, so the path
53+
# is injected here. This means CoverageReportGenerator cannot
54+
# run remote.
55+
genrule(
56+
name = "cilium_report_generator_script",
57+
srcs = ["report_generator.sh.template"],
58+
outs = ["report_generator.sh"],
59+
cmd = "sed 's|@@WORKSPACE_PATH@@|$$(realpath %s)|g' $< > $@" % PATH,
60+
)
61+
62+
label_flag(
63+
name = "config",
64+
build_setting_default = "//tests:coverage_config",
65+
visibility = ["//visibility:public"],
66+
)
67+
68+
sh_binary(
69+
name = "cilium_report_generator",
70+
srcs = [":cilium_report_generator_script"],
71+
data = [
72+
":config",
73+
":filter.jq",
74+
":grcov_bin",
75+
":grcov_config",
76+
":templates/base.html",
77+
":templates/index.html",
78+
":templates/macros.html",
79+
"@envoy//tools/zstd",
80+
"@jq_toolchains//:resolved_toolchain",
81+
],
82+
toolchains = ["@jq_toolchains//:resolved_toolchain"],
83+
visibility = ["//visibility:public"],
84+
)
85+
86+
sh_binary(
87+
name = "validate",
88+
srcs = [":validate.sh"],
89+
data = [
90+
":config",
91+
"@jq_toolchains//:resolved_toolchain",
92+
],
93+
env = {
94+
"JQ_BIN": "$(JQ_BIN)",
95+
"COVERAGE_CONFIG": "$(location :config)",
96+
},
97+
toolchains = ["@jq_toolchains//:resolved_toolchain"],
98+
visibility = ["//visibility:public"],
99+
)

0 commit comments

Comments
 (0)