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

Improve bpf log and bugs fix #364

Merged
merged 3 commits into from
May 27, 2024
Merged

Improve bpf log and bugs fix #364

merged 3 commits into from
May 27, 2024

Conversation

bfforever
Copy link
Member

@bfforever bfforever commented May 24, 2024

What type of PR is this?
/kind feature

What this PR does / why we need it:
Improve ipaddr format of bpf log.
And Fix xdsClient workloadController nil pointer bug when Kmesh mode is Ads.

Which issue(s) this PR fixes:
Fixes 358

Special notes for your reviewer:

In ads mode:
bpf_log_1

In workload mode:
bpf_log_2

Does this PR introduce a user-facing change?:


Signed-off-by: kangmingfa <1640528278@qq.com>
@codecov-commenter
Copy link

codecov-commenter commented May 24, 2024

Codecov Report

Attention: Patch coverage is 0% with 2 lines in your changes are missing coverage. Please review.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Flag Coverage Δ
unittests 31.64% <0.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
pkg/controller/controller.go 0.00% <0.00%> (ø)

@bfforever bfforever force-pushed the main branch 2 times, most recently from 2ec65f5 to 28ab28f Compare May 24, 2024 09:09
@@ -377,13 +377,13 @@ int route_config_manager(ctx_buff_t *ctx)

virt_host = virtual_host_match(route_config, &addr, ctx);
if (!virt_host) {
BPF_LOG(ERR, ROUTER_CONFIG, "failed to match virtual host, addr=%u\n", addr.ipv4);
BPF_LOG(ERR, ROUTER_CONFIG, "failed to match virtual host, addr=%pI4h\n", &addr.ipv4);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it just easy to find the faulty object with address? Does need another identity?

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe it could find which clusterIP service is failed when do virt host match. But this pr is just to change the ipaddr format of bpf log.

Copy link
Collaborator

Choose a reason for hiding this comment

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

ok

@@ -72,7 +72,9 @@ func (c *Controller) Start() error {
}

c.client = NewXdsClient(c.mode, c.bpfWorkloadObj)
c.client.workloadController.Processor.Sm = secertManager
if c.client.workloadController != nil {
c.client.workloadController.Processor.Sm = secertManager
Copy link
Contributor

Choose a reason for hiding this comment

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

The PR also contains a bug fix. Supplement the description in the PR title and description.

Copy link
Member Author

Choose a reason for hiding this comment

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

okay

@bfforever bfforever changed the title Improve bpf log Improve bpf log and fix xdsClient workloadController nil pointer bug in ads mode May 24, 2024
@bfforever bfforever changed the title Improve bpf log and fix xdsClient workloadController nil pointer bug in ads mode Improve bpf log and bugs fix May 24, 2024
@@ -199,7 +199,7 @@ int filter_chain_manager(ctx_buff_t *ctx)
/* filter match */
ret = filter_chain_filter_match(filter_chain, &addr, ctx, &filter, &filter_idx);
if (ret != 0) {
BPF_LOG(ERR, FILTERCHAIN, "no match filter, addr=%u\n", addr.ipv4);
BPF_LOG(ERR, FILTERCHAIN, "no match filter, addr=%pI4\n", &addr.ipv4);
Copy link
Contributor

Choose a reason for hiding this comment

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

%pI4 -> %pI4h

reason is direct access would not be print ipaddr when pass `&ctx->remote_ipv4` to bpf_trace_printk */
#define DECLARE_VAR_IPV4(t, ctx_ip, name) \
__u32 name = 0; \
if ((int)(BPF_LOGTYPE_##t) == BPF_DEBUG_ON) { \
Copy link
Contributor

Choose a reason for hiding this comment

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

how to format ipv6 addr

Copy link
Member

Choose a reason for hiding this comment

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

This macro seems not a must

Copy link
Member Author

Choose a reason for hiding this comment

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

how to format ipv6 addr
It may need to define another macro to get ipv6, then pass ipv6 pointer to bpf_trace_printk using format %pI6c.
#https://www.kernel.org/doc/html/v4.20/core-api/printk-formats.html#ipv6-addresses

Copy link
Member Author

Choose a reason for hiding this comment

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

This macro seems not a must

I consider using the macro to avoid defining ip variable when prog need to print the ipaddr info of bpf context, it could reduce code lines.
Also when one of ebpf prog's debug is off, it need not to get ip info from bpf context.

reason is direct access would not be print ipaddr when pass `&ctx->remote_ipv4` to bpf_trace_printk */
#define DECLARE_VAR_IPV4(t, ctx_ip, name) \
__u32 name = 0; \
if ((int)(BPF_LOGTYPE_##t) == BPF_DEBUG_ON) { \
Copy link
Member

Choose a reason for hiding this comment

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

can we remove this, imagine we may change the BPF_LOGTYPE_ from DEBUG to ERROR, what will happen if this is used by another caller for printing error

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

bfforever added 2 commits May 27, 2024 12:54
Signed-off-by: kangmingfa <1640528278@qq.com>
Signed-off-by: kangmingfa <1640528278@qq.com>
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 5f56179 into kmesh-net:main May 27, 2024
3 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.

Improve bpf log
6 participants