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

support dump workload bpf map #853

Merged
merged 5 commits into from
Sep 14, 2024

Conversation

Okabe-Rintarou-0
Copy link
Member

What type of PR is this?
feature

What this PR does / why we need it:

Which issue(s) this PR fixes:
Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?:


@Okabe-Rintarou-0
Copy link
Member Author

since we have some problems in ads bpf map deserialization, i first implemented the workload bpf map.
cc @hzxuzhonghu

@Okabe-Rintarou-0
Copy link
Member Author

WIP, exists some erros

Copy link

codecov bot commented Sep 14, 2024

Codecov Report

Attention: Patch coverage is 71.42857% with 24 lines in your changes missing coverage. Please review.

Project coverage is 52.86%. Comparing base (91a6110) to head (30126b4).
Report is 11 commits behind head on main.

Files with missing lines Patch % Lines
pkg/status/status_server.go 54.76% 17 Missing and 2 partials ⚠️
pkg/controller/workload/bpfcache/auth_policy.go 66.66% 2 Missing ⚠️
pkg/controller/workload/workload_processor.go 71.42% 2 Missing ⚠️
pkg/controller/workload/workload_controller.go 0.00% 1 Missing ⚠️
Files with missing lines Coverage Δ
pkg/controller/workload/bpfcache/backend.go 100.00% <100.00%> (ø)
pkg/controller/workload/bpfcache/common.go 100.00% <100.00%> (ø)
pkg/controller/workload/bpfcache/endpoint.go 85.71% <100.00%> (-0.88%) ⬇️
pkg/controller/workload/bpfcache/fake_map.go 83.05% <100.00%> (ø)
pkg/controller/workload/bpfcache/frontend.go 100.00% <100.00%> (ø)
pkg/controller/workload/bpfcache/service.go 100.00% <100.00%> (ø)
pkg/controller/workload/workload_controller.go 62.00% <0.00%> (ø)
pkg/controller/workload/bpfcache/auth_policy.go 50.00% <66.66%> (+16.66%) ⬆️
pkg/controller/workload/workload_processor.go 61.76% <71.42%> (-0.29%) ⬇️
pkg/status/status_server.go 38.18% <54.76%> (+5.00%) ⬆️

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 089540f...30126b4. Read the comment docs.

@hzxuzhonghu
Copy link
Member

Great. let me try

func (s *Server) bpfAdsMaps(w http.ResponseWriter, r *http.Request) {
client := s.xdsClient
if client == nil || client.AdsController == nil {
w.WriteHeader(http.StatusBadRequest)
fmt.Fprintf(w, "\t%s\n", "invalid ClientMode")
fmt.Fprint(w, invalidModeErrMessage)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also wrap it into a function like checkAdsMode()

@@ -257,7 +309,7 @@ func (s *Server) configDumpAds(w http.ResponseWriter, r *http.Request) {
client := s.xdsClient
if client == nil || client.AdsController == nil {
w.WriteHeader(http.StatusBadRequest)
fmt.Fprintf(w, "\t%s\n", "invalid ClientMode")
fmt.Fprint(w, invalidModeErrMessage)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Copy link
Member

@hzxuzhonghu hzxuzhonghu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall lgtm


func (c *Cache) WorkloadPolicyLookupAll() []WorkloadPolicy_value {
log.Debugf("WorkloadPolicyLookupAll")
return LookupAll[WorkloadPolicy_key, WorkloadPolicy_value](c.bpfMap.MapOfWlPolicy)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: WorkloadPolicy_key WorkloadPolicy_value should be camel format

@@ -0,0 +1,19 @@
package bpfcache
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copyright is missing

"github.com/cilium/ebpf"
)

func LookupAll[K any, V any](bpfMap *ebpf.Map) []V {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good generic function

@@ -46,6 +47,7 @@ const (
patternHelp = "/help"
patternOptions = "/options"
patternBpfAdsMaps = "/debug/bpf/ads"
patternBpfWorkloadMaps = "/debug/bpf/workload"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about /debug/config_dump/bpf/workload

and /debug/config_dump/bpf/ads

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems good

Copy link
Member

@hzxuzhonghu hzxuzhonghu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@kmesh-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: hzxuzhonghu

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kmesh-bot kmesh-bot merged commit 7c2bdbf into kmesh-net:main Sep 14, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants