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

More concise naming scheme for BpfPrograms #37

Merged
merged 2 commits into from
Jul 9, 2024

Conversation

anfredette
Copy link
Contributor

Create a shorter unique name for BpfProgram objects. For *Programs, the name is <*Program name>-<random string>. For BpfApplications, the unique name is <BpfApplication name>-<bpf program type>-<random string>.

Then, the identifying info for BpfProgram that used to be in the name is stored in the BpfProgram object.

Fixes: #28

@anfredette
Copy link
Contributor Author

The new names look like the following:

$ kubectl get bpfprograms.bpfman.io 
NAME                                        TYPE          STATUS         AGE
bpfapplication-sample-kprobe-e9584268       application   bpfmanLoaded   7m56s
bpfapplication-sample-tc-5c64641c           application   bpfmanLoaded   7m49s
bpfapplication-sample-tracepoint-1f1a61a1   application   bpfmanLoaded   7m51s
bpfapplication-sample-uprobe-72e8858d       application   bpfmanLoaded   6m34s
bpfapplication-sample-uprobe-b4fde6c2       application   bpfmanLoaded   6m26s
bpfapplication-sample-xdp-f3ef4383          application   bpfmanLoaded   6m18s
fentry-example-cd940fa0                     fentry        bpfmanLoaded   6m45s
fexit-example-fd53742b                      fexit         bpfmanLoaded   7m45s
kprobe-example-f24ff1d3                     kprobe        bpfmanLoaded   7m36s
tc-pass-all-nodes-563ab6b1                  tc            bpfmanLoaded   7m16s
tracepoint-example-4a04a14a                 tracepoint    bpfmanLoaded   7m26s
uprobe-example-17e5ab9b                     uprobe        bpfmanLoaded   6m55s
uprobe-example-containers-9412fff0          uprobe        bpfmanLoaded   6m48s
uprobe-example-containers-d6b84e71          uprobe        bpfmanLoaded   6m51s
xdp-pass-all-nodes-c6626947                 xdp           bpfmanLoaded   7m5s```

Copy link

codecov bot commented Jul 8, 2024

Codecov Report

Attention: Patch coverage is 66.43357% with 48 lines in your changes missing coverage. Please review.

Project coverage is 27.40%. Comparing base (b3c925c) to head (5b85c5d).
Report is 1 commits behind head on main.

Files Patch % Lines
controllers/bpfman-agent/application-program.go 29.41% 24 Missing ⚠️
controllers/bpfman-agent/uprobe-program.go 35.29% 11 Missing ⚠️
controllers/bpfman-agent/common.go 88.33% 5 Missing and 2 partials ⚠️
controllers/bpfman-agent/fentry-program.go 80.00% 1 Missing ⚠️
controllers/bpfman-agent/fexit-program.go 80.00% 1 Missing ⚠️
controllers/bpfman-agent/kprobe-program.go 80.00% 1 Missing ⚠️
controllers/bpfman-agent/tc-program.go 80.00% 1 Missing ⚠️
controllers/bpfman-agent/tracepoint-program.go 80.00% 1 Missing ⚠️
controllers/bpfman-agent/xdp-program.go 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #37      +/-   ##
==========================================
+ Coverage   26.92%   27.40%   +0.48%     
==========================================
  Files          81       81              
  Lines        6897     6965      +68     
==========================================
+ Hits         1857     1909      +52     
- Misses       4856     4870      +14     
- Partials      184      186       +2     
Flag Coverage Δ
unittests 27.40% <66.43%> (+0.48%) ⬆️

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Create a shorter unique name for BpfProgram objects. For *Programs, the
name is <*Program name>-<random string>.  For BpfApplications, the
unique name is <BpfApplication name>-<bpf program type>-<random string>.

Then, the identifying info for BpfProgram that used to be in the name
is stored in the BpfProgram object.

Fixes: bpfman#28

Signed-off-by: Andre Fredette <[email protected]>
Signed-off-by: Andre Fredette <[email protected]>
existingBpfPrograms[bpfProg.GetName()] = bpfProg
key := bpfProgKey{
appProgId: bpfProg.GetLabels()[internal.AppProgramId],
attachPoint: bpfProg.GetAnnotations()[internal.BpfProgramAttachPoint],
Copy link
Contributor

Choose a reason for hiding this comment

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

just curious why u need both progId and attachement point as key, progId should be unique right ?

Copy link
Contributor Author

@anfredette anfredette Jul 9, 2024

Choose a reason for hiding this comment

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

Not exactly. I'm trying to use appProgId to uniquely identify a single program item within a BpfApplication. For this, I'm currently using program type plus all or a portion of the attach point. In some cases (Fentry, Fexit, Kprobe) it's the whole attach point. In the case of uprobes, it's the FunctionName (I think I should also add the target), but it can actually be attached to the same point in multiple containers (each one results in a separate BpfProgram object). In the case of tracepoint, it's the first tracepoint on the list. In the case of XDP, it's the first interface on the list. In the case of TC, it's the first interface on the list plus the direction. This kind of works because we've said that there will only ever be one program of a given type per attach point. However, that may not hold true for everyone, and for the program types where there is a list of attach points, I wonder if we'd ever have two programs of the same type that have different lists, but the first item is the same. That probably won't happen with our applications, but I don't know if we can rule it out. My assumption is that we'll need to change something in the future to make this 100% unique. One Idea I have is to have the operator controller generate a unique ID for each program. Another is to require that the user provide a unique name/id for each program in a BpfApplication.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So, to summarize, the appProgId should uniquely identify a program item in a BpfApplication, and the following set of info uniquely identifies a BpfProgram object that was created for it:

Labels:

  • internal.BpfProgramOwner
  • internal.AppProgramId
  • internal.K8sHostLabel

Annotation:

  • internal.BpfProgramAttachPoint

I put the attach point in an annotation because we don't need to use it in a search, and it can be a longer string if needed.

Copy link
Contributor

Choose a reason for hiding this comment

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

if u have more than one app we can't be sure they will provide unique id better to be done under the hood IMO

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, but I've been thinking about it and it might be a little tricky. It’s easy to generate appProgramIds the first time. For example, we could just use the index of the program item in the list. However, if the BpfApplication CRD is updated, and the user adds a new program, and/or deletes an existing one, I think we want to leave the unchanged programs alone. I.e., we don’t want to unload and reload everything. We just want to handle the changes. To do this, I think we want to keep the same appProgramId for the existing programs and generate new ones for any new programs. To do this, I think we'll need to compare the old and new CRD versions and keep the existing appProgramId for the programs that are the same, and generate new ones for any new programs. To do this, we’ll need to identify what constitutes a new program vs. an existing program. For example, the CRD can be updated with some new attach points for an XDP program. We probably want to be able to keep the existing programs in place and only reconcile the changes.

I was thinking that what I have in this PR is a good enough for now and provides the structure for a more complicated solution later.

@msherif1234
Copy link
Contributor

/LGTM

@mergify mergify bot merged commit 3906a80 into bpfman:main Jul 9, 2024
12 checks passed
msherif1234 pushed a commit to msherif1234/bpfman-operator that referenced this pull request Oct 30, 2024
…/ocp-bpfman-operator-bundle

Update ocp-bpfman-operator-bundle to 69e5089
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Develop a more concise naming scheme for BpfPrograms
2 participants