Skip to content

Commit e23c409

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

14 files changed

Lines changed: 832 additions & 48 deletions

File tree

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

Lines changed: 55 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,59 @@ 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+
# go mod tidy
72+
# go mod vendor
73+
# test -z "$(git status --porcelain)" || (echo "please run 'go mod tidy && go mod vendor', and submit your changes"; exit 1)
74+
make -C proxylib
75+
- name: Build test deps
76+
shell: bash
77+
run: |
78+
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
79+
- name: Generate coverage data
80+
shell: bash
81+
run: |
82+
echo "Generating bazel coverage: "
83+
./tests/run_bazel_coverage.sh
84+
ls -la /home/runner/work/cilium-proxy/cilium-proxy/generated/coverage/
85+
- name: Upload (sync) to GCS bucket
86+
if: '!cancelled()'
87+
shell: bash
88+
run: |
89+
UPLOAD_DIR="/home/runner/work/cilium-proxy/cilium-proxy/generated/coverage/"
90+
SHA=${{ github.sha }}
91+
BUCKET_PATH="${{ vars.GCS_ARTIFACT_BUCKET_COVERAGE }}/${SHA:0:7}/coverage"
92+
echo "Uploading to gs://$BUCKET_PATH ..."
93+
gsutil \
94+
-mq rsync \
95+
-dr "$UPLOAD_DIR" \
96+
"gs://$BUCKET_PATH"
97+
echo "Artifacts uploaded to: https://storage.googleapis.com/$BUCKET_PATH/html/index.html" >&2
98+
strategy:
99+
fail-fast: false
100+
matrix:
101+
include:
102+
- target: coverage
103+
name: Coverage
104+
diskspace-hack: true
105+
diskspace-hack-paths: |
106+
/opt/hostedtoolcache
107+
/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

0 commit comments

Comments
 (0)