Skip to content

Commit 65a3860

Browse files
authored
chore(pipelines/xcover): add scope parameter (#2558)
* chore(pipelines/xcover): add scope parameter The scope profile parameter allows to scope the tracing to just the project functions. It is now supported for Go binaries, scoping to the Go module by default using the .go.buildinfo ELF section. Signed-off-by: Massimiliano Giovagnoli <massimiliano.giovagnoli@chainguard.dev> * chore(pipelines/xcover): rm docs for sys_resource cap Signed-off-by: Massimiliano Giovagnoli <massimiliano.giovagnoli@chainguard.dev> --------- Signed-off-by: Massimiliano Giovagnoli <massimiliano.giovagnoli@chainguard.dev>
1 parent a730cb0 commit 65a3860

5 files changed

Lines changed: 58 additions & 2 deletions

File tree

e2e-tests/xcover-nopkg-test.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ package:
77
capabilities:
88
add:
99
- CAP_SYS_ADMIN
10-
- CAP_SYS_RESOURCE
1110

1211
test:
1312
environment:
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package:
2+
name: crane
3+
version: "0.20.3"
4+
epoch: 3
5+
description: Tests the xcover project function scope on a Go binary
6+
7+
capabilities:
8+
add:
9+
- CAP_SYS_ADMIN
10+
11+
test:
12+
environment:
13+
contents:
14+
packages:
15+
- jq
16+
- crane
17+
pipeline:
18+
- uses: xcover/profile
19+
with:
20+
executable-path: /usr/bin/crane
21+
scope: project
22+
- runs: |
23+
crane version || exit 1
24+
crane --help
25+
- runs: |
26+
crane manifest chainguard/static | jq '.schemaVersion' | grep '2' || exit 1
27+
- runs: |
28+
crane ls chainguard/static | grep -E 'latest|v[0-9]+.[0-9]+.[0-9]+' || exit 1
29+
- runs: |
30+
crane digest chainguard/static:latest && echo "Image exists" || exit 1
31+
- runs: |
32+
crane pull chainguard/static:latest static_latest.tar || exit 1
33+
[ -f static_latest.tar ] || exit 1
34+
- uses: xcover/stop
35+
- runs: |
36+
# Project scope must keep only crane's own Go module functions
37+
# (github.com/google/go-containerregistry/...) plus root main.* funcs.
38+
# Any Go stdlib or third-party dependency symbol means scope leaked,
39+
# i.e. the pipeline did not actually apply scope=project.
40+
mod="github.com/google/go-containerregistry"
41+
jq -r '.funcs_traced[]' xcover-report.json > traced.txt
42+
[ -s traced.txt ] || { echo "no functions traced"; exit 1; }
43+
leaked=$(grep -vE "^(main\\.|${mod}[/.])" traced.txt || true)
44+
if [ -n "$leaked" ]; then
45+
echo "project scope leaked non-project functions:"
46+
echo "$leaked" | head -20
47+
exit 1
48+
fi
49+
echo "all $(wc -l < traced.txt) traced functions are project-scoped"
50+
- uses: xcover/ensure
51+
with:
52+
min-coverage: 10

examples/test-xcover.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ update:
4040
capabilities:
4141
add:
4242
- CAP_SYS_ADMIN
43-
- CAP_SYS_RESOURCE
4443

4544
test:
4645
environment:

pkg/build/pipelines/xcover/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Start the coverage profile with the xcover tool
3232
| include-functions | false | The function symbols to include in profiling as a regular expression. When set, only matching symbols are profiled. | |
3333
| log-level | false | The log level of the xcover profile command. | info |
3434
| package | false | The xcover package | xcover |
35+
| scope | false | The function scope to profile: "binary" (all functions) or "project" (project module only). The "project" scope is only supported by Go binaries and is a no-op for others. | project |
3536
| verbose | false | Enable verbosity of the xcover profile command. It prints out all the functions being traced real-time. | false |
3637
| wait-timeout | false | The maximum amount of time to wait for the xcover profiler to be ready for profiling, in seconds. | 60 |
3738

pkg/build/pipelines/xcover/profile.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ inputs:
1919
include-functions:
2020
description: The function symbols to include in profiling as a regular expression. When set, only matching symbols are profiled.
2121
required: false
22+
scope:
23+
description: 'The function scope to profile: "binary" (all functions) or "project" (project module only). The "project" scope is only supported by Go binaries and is a no-op for others.'
24+
required: false
25+
default: project
2226
log-level:
2327
description: The log level of the xcover profile command.
2428
required: false
@@ -40,6 +44,7 @@ pipeline:
4044
--path ${{inputs.executable-path}} \
4145
--exclude=${{inputs.exclude-functions}} \
4246
--include=${{inputs.include-functions}} \
47+
--scope=${{inputs.scope}} \
4348
--log-level=${{inputs.log-level}} \
4449
--verbose=${{inputs.verbose}} \
4550
--status \

0 commit comments

Comments
 (0)