Skip to content

Commit

Permalink
intg netobserv agent with new api to get udn mapping
Browse files Browse the repository at this point in the history
Signed-off-by: Mohamed Mahmoud <[email protected]>
  • Loading branch information
msherif1234 committed Dec 19, 2024
1 parent 48eb61b commit c775cf8
Show file tree
Hide file tree
Showing 9 changed files with 167 additions and 129 deletions.
2 changes: 1 addition & 1 deletion pkg/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func FlowsAgent(cfg *Config) (*Flows, error) {
m := metrics.NewMetrics(metricsSettings)

var s *ovnobserv.SampleDecoder
if cfg.EnableNetworkEventsMonitoring {
if cfg.EnableNetworkEventsMonitoring || cfg.EnableUDNMapping {
if !kernel.IsKernelOlderThan("5.14.0") {
if s, err = ovnobserv.NewSampleDecoderWithDefaultCollector(context.Background(), networkEventsDBPath,
networkEventsOwnerName, cfg.NetworkEventsMonitoringGroupID); err != nil {
Expand Down
3 changes: 2 additions & 1 deletion pkg/agent/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ type Config struct {
EbpfProgramManagerMode bool `env:"EBPF_PROGRAM_MANAGER_MODE" envDefault:"false"`
// BpfManBpfFSPath user configurable ebpf manager mount path
BpfManBpfFSPath string `env:"BPFMAN_BPF_FS_PATH" envDefault:"/run/netobserv/maps"`

// EnableUDNMapping to allow mapping pod's interface to udn label
EnableUDNMapping bool `env:"ENABLE_UDN_MAPPING" envDefault:"false"`
/* Deprecated configs are listed below this line
* See manageDeprecatedConfigs function for details
*/
Expand Down
5 changes: 5 additions & 0 deletions pkg/decode/decode_protobuf.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,14 @@ func RecordToMap(fr *model.Record) config.GenericMap {
interfaces = append(interfaces, fr.Interface)
directions = append(directions, int(fr.ID.Direction))
}

out["Interfaces"] = interfaces
out["IfDirections"] = directions

if len(fr.UdnList) != 0 {
out["Udns"] = fr.UdnList
}

if fr.Metrics.EthProtocol == uint16(ethernet.EtherTypeIPv4) || fr.Metrics.EthProtocol == uint16(ethernet.EtherTypeIPv6) {
out["SrcAddr"] = model.IP(fr.ID.SrcIp).String()
out["DstAddr"] = model.IP(fr.ID.DstIp).String()
Expand Down
3 changes: 3 additions & 0 deletions pkg/decode/decode_protobuf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ func TestPBFlowToMap(t *testing.T) {
{
Interface: "5e6e92caa1d51cf",
Direction: pbflow.Direction_INGRESS,
Udn: "",
},
{
Interface: "eth0",
Direction: pbflow.Direction_EGRESS,
Udn: "",
},
},
EthProtocol: 2048,
Expand Down Expand Up @@ -121,6 +123,7 @@ func TestPBFlowToMap(t *testing.T) {
"TimeFlowStartMs": someTime.UnixMilli(),
"TimeFlowEndMs": someTime.UnixMilli(),
"Interfaces": []string{"5e6e92caa1d51cf", "eth0"},
"Udns": []string{"", ""},
"AgentIP": "10.9.8.7",
"Flags": uint16(0x100),
"PktDropBytes": uint64(200),
Expand Down
2 changes: 2 additions & 0 deletions pkg/exporter/converters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ func TestConversions(t *testing.T) {
{"5e6e92caa1d51cf": 0},
{"eth0": 1},
},
UdnList: []string{"", ""},
TimeFlowStart: someTime,
TimeFlowEnd: someTime,
AgentIP: net.IPv4(0x0a, 0x0b, 0x0c, 0x0d),
Expand All @@ -438,6 +439,7 @@ func TestConversions(t *testing.T) {
"TimeFlowEndMs": someTime.UnixMilli(),
"Interfaces": []string{"5e6e92caa1d51cf", "eth0"},
"AgentIP": "10.11.12.13",
"Udns": []string{"", ""},
},
},
}
Expand Down
1 change: 1 addition & 0 deletions pkg/model/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ type Record struct {
TimeFlowRtt time.Duration
DupList []map[string]uint8
NetworkMonitorEventsMD []config.GenericMap
UdnList []string
}

func NewRecord(
Expand Down
259 changes: 134 additions & 125 deletions pkg/pbflow/flow.pb.go

Large diffs are not rendered by default.

20 changes: 18 additions & 2 deletions pkg/pbflow/proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,25 @@ func FlowToPB(fr *model.Record, s *ovnobserv.SampleDecoder) *Record {
pbflowRecord.DupList = make([]*DupMapEntry, 0)
for _, m := range fr.DupList {
for key, value := range m {
pbflowRecord.DupList = append(pbflowRecord.DupList, &DupMapEntry{
entry := DupMapEntry{
Interface: key,
Direction: Direction(value),
})
}
if s != nil {
m, err := s.GetInterfaceUDNs()
if err == nil {
if v, ok := m[entry.Interface]; ok {
entry.Udn = v
protoLog.Debugf("Mapping interface %s to UDN %s", entry.Interface, v)
} else {
protoLog.Debugf("Failed to map interface %s to UDN", entry.Interface)
}
} else {
protoLog.Debugf("Failed to convert interface %s to UDN, err %s", entry.Interface, err)
}
}

pbflowRecord.DupList = append(pbflowRecord.DupList, &entry)
}
}
}
Expand Down Expand Up @@ -222,6 +237,7 @@ func PBToFlow(pb *Record) *model.Record {
intf := entry.Interface
dir := uint8(entry.Direction)
out.DupList = append(out.DupList, map[string]uint8{intf: dir})
out.UdnList = append(out.UdnList, entry.Udn)
}
}
if len(pb.GetNetworkEventsMetadata()) != 0 {
Expand Down
1 change: 1 addition & 0 deletions proto/flow.proto
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ message Records {
message DupMapEntry {
string interface = 1;
Direction direction = 2;
string udn = 3;
}

message NetworkEvent {
Expand Down

0 comments on commit c775cf8

Please sign in to comment.