Skip to content

Commit

Permalink
pkg/hubble/parser: Decode observation point into enum
Browse files Browse the repository at this point in the history
Signed-off-by: Glib Smaga <code@gsmaga.com>
  • Loading branch information
glibsm authored and aanm committed Jun 16, 2020
1 parent f6994de commit 331aab4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/hubble/parser/threefour/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,15 @@ func (p *Parser) Decode(payload *pb.Payload, decoded *pb.Flow) error {
return fmt.Errorf("failed to parse trace: %v", err)
}
eventSubType = tn.ObsPoint

if tn.ObsPoint != 0 {
decoded.TraceObservationPoint = pb.TraceObservationPoint(tn.ObsPoint)
} else {
// specifically handle the zero value in the observation enum so the json
// export and the API don't carry extra meaning with the zero value
decoded.TraceObservationPoint = pb.TraceObservationPoint_TO_ENDPOINT
}

packetOffset = (int)(tn.DataOffset())
case monitorAPI.MessageTypePolicyVerdict:
pvn = &monitor.PolicyVerdictNotify{}
Expand Down
4 changes: 4 additions & 0 deletions pkg/hubble/parser/threefour/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ func TestL34Decode(t *testing.T) {
assert.Equal(t, &flowpb.TCPFlags{ACK: true}, f.L4.GetTCP().GetFlags())
assert.Equal(t, nodeName, f.GetNodeName())

assert.Equal(t, flowpb.TraceObservationPoint_FROM_HOST, f.GetTraceObservationPoint())

// ICMP packet so no ports until that support is merged into master
//
//SOURCE DESTINATION TYPE SUMMARY
Expand Down Expand Up @@ -229,6 +231,8 @@ func TestL34Decode(t *testing.T) {
assert.Equal(t, flowpb.Verdict_FORWARDED, f.GetVerdict())
assert.Equal(t, (*flowpb.TCPFlags)(nil), f.L4.GetTCP().GetFlags())
assert.Equal(t, nodeName, f.GetNodeName())

assert.Equal(t, flowpb.TraceObservationPoint_FROM_ENDPOINT, f.GetTraceObservationPoint())
}

func BenchmarkL34Decode(b *testing.B) {
Expand Down

0 comments on commit 331aab4

Please sign in to comment.