Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CWS] remove commit check from btfhub sync #33096

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions .github/workflows/cws-btfhub-sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ on:
required: false
default: 'main'
type: string
force_refresh:
description: 'Force refresh of the constants'
required: false
default: 'false'
type: boolean
schedule:
- cron: '30 4 * * 5' # at 4:30 UTC on Friday

Expand Down Expand Up @@ -83,19 +78,11 @@ jobs:
echo "ARTIFACT_NAME=constants-${{ matrix.cone }}" | tr '/' '-' >> $GITHUB_OUTPUT

- name: Sync constants
if: ${{ !inputs.force_refresh }}
env:
ARTIFACT_NAME: ${{ steps.artifact-name.outputs.ARTIFACT_NAME }}
run: |
inv -e security-agent.generate-btfhub-constants --archive-path=./dev/dist/archive --output-path=./"$ARTIFACT_NAME".json

- name: Force sync constants
if: ${{ inputs.force_refresh }}
env:
ARTIFACT_NAME: ${{ steps.artifact-name.outputs.ARTIFACT_NAME }}
run: |
inv -e security-agent.generate-btfhub-constants --archive-path=./dev/dist/archive --output-path=./"$ARTIFACT_NAME".json --force-refresh

- name: Upload artifact
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
with:
Expand Down
1 change: 0 additions & 1 deletion pkg/security/probe/constantfetch/btfhub.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ func newKernelInfos(kv *kernel.Version) (*kernelInfos, error) {
// BTFHubConstants represents all the information required for identifying
// a unique btf file from BTFHub
type BTFHubConstants struct {
Commit string `json:"commit"`
Constants []map[string]uint64 `json:"constants"`
Kernels []BTFHubKernel `json:"kernels"`
}
Expand Down
1 change: 0 additions & 1 deletion pkg/security/probe/constantfetch/btfhub/constants.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 4 additions & 45 deletions pkg/security/probe/constantfetch/btfhub/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,11 @@ import (
func main() {
var archiveRootPath string
var constantOutputPath string
var forceRefresh bool
var combineConstants bool
var cpuPprofPath string

flag.StringVar(&archiveRootPath, "archive-root", "", "Root path of BTFHub archive")
flag.StringVar(&constantOutputPath, "output", "", "Output path for JSON constants")
flag.BoolVar(&forceRefresh, "force-refresh", false, "Force refresh of the constants")
flag.BoolVar(&combineConstants, "combine", false, "Don't read btf files, but read constants")
flag.StringVar(&cpuPprofPath, "cpu-prof", "", "Path to the CPU profile to generate")
flag.Parse()
Expand Down Expand Up @@ -81,21 +79,7 @@ func main() {
}
fmt.Printf("btfhub-archive: commit %s\n", archiveCommit)

preAllocHint := 0

if !forceRefresh {
// skip if commit is already the most recent
currentConstants, err := getCurrentConstants(constantOutputPath)
if err == nil && currentConstants.Commit != "" {
if currentConstants.Commit == archiveCommit {
fmt.Printf("already at most recent archive commit")
return
}
preAllocHint = len(currentConstants.Kernels)
}
}

twCollector := newTreeWalkCollector(preAllocHint)
twCollector := newTreeWalkCollector()

var wg sync.WaitGroup
// github actions runner have only 2 cores
Expand All @@ -118,8 +102,6 @@ func main() {

export := twCollector.finish()

export.Commit = archiveCommit

if err := outputConstants(&export, constantOutputPath); err != nil {
panic(err)
}
Expand Down Expand Up @@ -173,16 +155,7 @@ func combineConstantFiles(archiveRootPath string) (constantfetch.BTFHubConstants
return constantfetch.BTFHubConstants{}, errors.New("no json file found")
}

lastCommit := ""
for _, file := range files {
if lastCommit != "" && file.Commit != lastCommit {
return constantfetch.BTFHubConstants{}, errors.New("multiple different commits in constant files")
}
}

res := constantfetch.BTFHubConstants{
Commit: lastCommit,
}
res := constantfetch.BTFHubConstants{}

for _, file := range files {
offset := len(res.Constants)
Expand All @@ -197,20 +170,6 @@ func combineConstantFiles(archiveRootPath string) (constantfetch.BTFHubConstants
return res, nil
}

func getCurrentConstants(path string) (*constantfetch.BTFHubConstants, error) {
cjson, err := os.ReadFile(path)
if err != nil {
return nil, err
}

var currentConstants constantfetch.BTFHubConstants
if err := json.Unmarshal(cjson, &currentConstants); err != nil {
return nil, err
}

return &currentConstants, nil
}

func getCommitSha(cwd string) (string, error) {
cmd := exec.Command("git", "rev-parse", "HEAD")
cmd.Dir = cwd
Expand All @@ -231,10 +190,10 @@ type treeWalkCollector struct {
queryChan chan extractionQuery
}

func newTreeWalkCollector(preAllocHint int) *treeWalkCollector {
func newTreeWalkCollector() *treeWalkCollector {
return &treeWalkCollector{
counter: 0,
results: make([]extractionResult, 0, preAllocHint),
results: make([]extractionResult, 0),
cache: make(map[string]map[string]uint64),
queryChan: make(chan extractionQuery),
}
Expand Down
5 changes: 2 additions & 3 deletions tasks/security_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,10 +591,9 @@ def single_run(ctx, table_url, output_file, output_string_file, abis=None):


@task
def generate_btfhub_constants(ctx, archive_path, force_refresh=False, output_path=DEFAULT_BTFHUB_CONSTANTS_PATH):
force_refresh_opt = "-force-refresh" if force_refresh else ""
def generate_btfhub_constants(ctx, archive_path, output_path=DEFAULT_BTFHUB_CONSTANTS_PATH):
ctx.run(
f"go run -tags linux_bpf,btfhubsync ./pkg/security/probe/constantfetch/btfhub/ -archive-root {archive_path} -output {output_path} {force_refresh_opt}",
f"go run -tags linux_bpf,btfhubsync ./pkg/security/probe/constantfetch/btfhub/ -archive-root {archive_path} -output {output_path}",
)


Expand Down
Loading