-
Notifications
You must be signed in to change notification settings - Fork 49
NETOBSERV-2364: Typo in packet record map name used with bpfman #811
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package maps | ||
|
|
||
| // Map names | ||
| var Maps = []string{ | ||
| "direct_flows", | ||
| "aggregated_flows", | ||
| "additional_flow_metrics", | ||
| "packet_record", | ||
| "dns_flows", | ||
| "global_counters", | ||
| "filter_map", | ||
| "peer_filter_map", | ||
| "ipsec_ingress_map", | ||
| "ipsec_egress_map", | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| package maps | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "errors" | ||
| "fmt" | ||
| "os" | ||
| "reflect" | ||
| "regexp" | ||
| "sort" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/netobserv/netobserv-ebpf-agent/pkg/ebpf" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestMapNamesMatchEBPFDefinitions(t *testing.T) { | ||
| // Extract map names from netobserv-ebpf-agent/pkg/ebpf | ||
| ebpfMaps := extractEBPFMapNames() | ||
|
|
||
| // Get map names from our package | ||
| packageMaps := Maps | ||
|
|
||
| // Sort both slices for comparison | ||
| sort.Strings(ebpfMaps) | ||
| sort.Strings(packageMaps) | ||
| fmt.Printf("eBPF maps: %+v\n", ebpfMaps) | ||
| fmt.Printf("Package maps: %+v\n", packageMaps) | ||
|
|
||
| // Verify they match | ||
| assert.Equal(t, ebpfMaps, packageMaps, | ||
| "Map names in pkg/maps/maps.go do not match eBPF definitions in bpf/maps_definition.h") | ||
| } | ||
|
|
||
| func TestMapNamesMatchBcMk(t *testing.T) { | ||
| // Extract map names from .mk/bc.mk | ||
| bcMaps, err := extractBcMkMapNames("../../.mk/bc.mk") | ||
| require.NoError(t, err, "Failed to extract map names from .mk/bc.mk") | ||
|
|
||
| // Get map names from our package | ||
| packageMaps := Maps | ||
|
|
||
| // Sort both slices for comparison | ||
| sort.Strings(bcMaps) | ||
| sort.Strings(packageMaps) | ||
| fmt.Printf("bc.mk maps: %+v\n", bcMaps) | ||
| fmt.Printf("Package maps: %+v\n", packageMaps) | ||
|
|
||
| // Verify they match | ||
| assert.Equal(t, bcMaps, packageMaps, | ||
| "Map names in pkg/maps/maps.go do not match definitions in .mk/bc.mk.\n"+ | ||
| "If you've added/removed maps, please update both files.") | ||
| } | ||
|
|
||
| // extractBcMkMapNames parses the .mk/bc.mk file and extracts map names from the MAPS JSON | ||
| func extractBcMkMapNames(filePath string) ([]string, error) { | ||
| content, err := os.ReadFile(filePath) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| // Find the MAPS definition block | ||
| mapsRegex := regexp.MustCompile(`define MAPS\s*\n((.|\s)*?)\nendef`) | ||
| matches := mapsRegex.FindStringSubmatch(string(content)) | ||
|
|
||
| if len(matches) < 2 { | ||
| return nil, errors.New("Could not find MAPS definition in .mk/bc.mk") | ||
| } | ||
|
|
||
| // Extract the JSON content | ||
| jsonContent := strings.TrimSpace(matches[1]) | ||
|
|
||
| // Parse JSON to extract map names | ||
| var mapsData map[string]string | ||
| if err := json.Unmarshal([]byte(jsonContent), &mapsData); err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| // Extract just the map names (keys) | ||
| var mapNames []string | ||
| for mapName := range mapsData { | ||
| mapNames = append(mapNames, mapName) | ||
| } | ||
|
|
||
| return mapNames, nil | ||
| } | ||
|
|
||
| // extractEBPFMapNames extracts map names from the compiled eBPF agent | ||
| func extractEBPFMapNames() []string { | ||
| var maps []string | ||
| mapType := reflect.ValueOf(ebpf.BpfMapSpecs{}) | ||
| for i := 0; i < mapType.NumField(); i++ { | ||
| val := reflect.Indirect(mapType) | ||
| mapName := val.Type().Field(i).Tag.Get("ebpf") | ||
|
|
||
| if mapName != "" { | ||
| maps = append(maps, mapName) | ||
| } | ||
| } | ||
|
|
||
| return maps | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
you should rune
make fmtto format all the files 😉