-
Notifications
You must be signed in to change notification settings - Fork 24
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
New 'node-agent' that listens to pod events and loads eBPF programs #224
Conversation
b751a18
to
df51970
Compare
Co-authored-by: Ori Shavit <[email protected]>
438e380
to
e2cea47
Compare
df7bcf4
to
4b891d7
Compare
4b891d7
to
74d471c
Compare
f929652
to
554bbf6
Compare
564e82f
to
efff59c
Compare
- only handle pods on the same node - fix a crash where accessing a static var before it is initialized
@@ -0,0 +1,20 @@ | |||
FROM --platform=$TARGETPLATFORM golang:1.22.1 AS ebpf-buildenv |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we still need this? it's not referenced anywhere and AFAIU bpfman is no longer in use
var sectionsToSearchForSymbol []*elf.Section | ||
|
||
for i := range f.Sections { | ||
if f.Sections[i].Flags == elf.SHF_ALLOC+elf.SHF_EXECINSTR { | ||
sectionsToSearchForSymbol = append(sectionsToSearchForSymbol, f.Sections[i]) | ||
} | ||
} | ||
|
||
if len(sectionsToSearchForSymbol) == 0 { | ||
return 0, fmt.Errorf("symbol %q not found in file - no sections to search", symbol) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider splitting this to a dedicated function getSectionsToSearchForSymbol(f) ([]*elf.Section)
for readability and to shorten SymbolToOffset
.
var executableSection *elf.Section | ||
|
||
// Find what section the symbol is in by checking the executable section's addr space. | ||
for m := range sectionsToSearchForSymbol { | ||
sectionStart := sectionsToSearchForSymbol[m].Addr | ||
sectionEnd := sectionStart + sectionsToSearchForSymbol[m].Size | ||
if symbol.Value >= sectionStart && symbol.Value < sectionEnd { | ||
executableSection = sectionsToSearchForSymbol[m] | ||
break | ||
} | ||
} | ||
|
||
if executableSection == nil { | ||
return 0, errors.New("could not find symbol in executable sections of binary") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here - consider splitting to a dedicated function findExecutableSection(sectionsToSearchForSymbol, symbol) *elf.Section
.
This will also help with replacing the break
with a return
(which will help readability).
"github.com/otterize/network-mapper/src/bintools/bininfo" | ||
) | ||
|
||
// FunctionMetadata used to attach a uprobe to a function. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// FunctionMetadata used to attach a uprobe to a function. | |
// FunctionMetadata used to attach a uprobe to a function. |
if cErr == nil { | ||
err = cErr | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would you really want to fail the entire flow if Close() failed? perhaps just log and continue
}, nil | ||
} | ||
|
||
func (e *EventReader) Start() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using context.Context to be able to trigger graceful shutdown here.
if containerInfo.ExecutableInfo.Language == bininfo.SourceLanguageNodeJs { | ||
err := r.tracer.AttachToOpenSSL(containerInfo) | ||
if err != nil { | ||
return errors.Wrap(err) | ||
} | ||
} else if containerInfo.ExecutableInfo.Language == bininfo.SourceLanguageGoLang { | ||
err := r.tracer.AttachToGoTls(containerInfo) | ||
if err != nil { | ||
return errors.Wrap(err) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider using switch containerInfo.ExecutableInfo.Language
, which is more idiomatic here.
printHttpRequests = false | ||
) | ||
|
||
func init() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we typically use viper
rather than raw env vars, which provides better control over argument types etc. Consider switching to it, both for consistency with other portions of our application, and for better code. you can take a look at the sniffer code for a relatively simple example.
|
||
EnvPodKey = "pod" | ||
EnvNamespaceKey = "namespace" | ||
|
||
// experimental features | ||
|
||
EnableEBPFKey = "experimental-ebpf" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be called enable-ebpf
(the experimental portion can go into description), or enable-ebpf-experimental
if you really insist on including the experimental part in the flag name.
@@ -37,6 +37,7 @@ func main() { | |||
}) | |||
errgrp, errGroupCtx := errgroup.WithContext(signals.SetupSignalHandler()) | |||
clusterUID := clusterutils.GetOrCreateClusterUID(errGroupCtx) | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert this
Please see the contributing guidelines for how to create and submit a high-quality PR for this repo. This template is based on Auth0's excellent template.
Description
Describe the purpose of this PR along with any background information and the impacts of the proposed change. For the benefit of the community, please do not assume prior context.
Provide details that support your chosen implementation, including: breaking changes, alternatives considered, changes to the API, etc.
References
Include any links supporting this change such as a:
If there are no references, simply delete this section.
Testing
Describe how this can be tested by reviewers. Be specific about anything not tested and reasons why. If this library has unit and/or integration testing, tests should be added for new functionality and existing tests should complete without errors.
Please include any manual steps for testing end-to-end or functionality not covered by unit/integration tests.
Also include details of the environment this PR was developed in (language/platform/browser version).
Checklist