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

Add support for SockLB events #816

Merged
merged 2 commits into from
Nov 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cmd/observe/flows.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ var verdicts = []string{
flowpb.Verdict_AUDIT.String(),
flowpb.Verdict_REDIRECTED.String(),
flowpb.Verdict_ERROR.String(),
flowpb.Verdict_TRACED.String(),
flowpb.Verdict_TRANSLATED.String(),
}

// flowEventTypes are the valid event types supported by observe. This corresponds
Expand All @@ -67,6 +69,7 @@ var flowEventTypes = []string{
monitorAPI.MessageTypeNameL7,
monitorAPI.MessageTypeNamePolicyVerdict,
monitorAPI.MessageTypeNameTrace,
monitorAPI.MessageTypeNameTraceSock,
}

// flowEventTypeSubtypes is a map message types and all their subtypes.
Expand All @@ -89,6 +92,7 @@ var flowEventTypeSubtypes = map[string][]string{
},
monitorAPI.MessageTypeNameL7: nil,
monitorAPI.MessageTypeNamePolicyVerdict: nil,
monitorAPI.MessageTypeNameTraceSock: nil,
}

const (
Expand Down
6 changes: 2 additions & 4 deletions cmd/observe/flows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,15 @@ import (
func TestEventTypes(t *testing.T) {
// Make sure to keep event type slices in sync. Agent events, debug
// events and recorder captures have separate subcommands and are not
// supported in observe, and trace-sock events aren't supported in the API
// yet, thus the 4. See flowEventTypes godoc for details.
require.Len(t, flowEventTypes, len(monitorAPI.MessageTypeNames)-4)
// supported in observe, thus the 3. See flowEventTypes godoc for details.
require.Len(t, flowEventTypes, len(monitorAPI.MessageTypeNames)-3)
for _, v := range flowEventTypes {
require.Contains(t, monitorAPI.MessageTypeNames, v)
}
for k := range monitorAPI.MessageTypeNames {
switch k {
case monitorAPI.MessageTypeNameAgent,
monitorAPI.MessageTypeNameDebug,
monitorAPI.MessageTypeNameTraceSock,
monitorAPI.MessageTypeNameRecCapture:
continue
}
Expand Down
17 changes: 6 additions & 11 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/cilium/hubble
go 1.19

require (
github.com/cilium/cilium v1.13.0-rc1.0.20221006162552-c8fef6fbddf7
github.com/cilium/cilium v1.13.0-rc2.0.20221116111714-7a06e6282025
github.com/fatih/color v1.13.0
github.com/google/go-cmp v0.5.9
github.com/sirupsen/logrus v1.9.0
Expand All @@ -12,7 +12,7 @@ require (
github.com/spf13/pflag v1.0.6-0.20200504143853-81378bbcd8a1
github.com/spf13/viper v1.14.0
github.com/stretchr/testify v1.8.1
golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec
golang.org/x/sys v0.2.0
google.golang.org/grpc v1.51.0
google.golang.org/protobuf v1.28.1
gopkg.in/yaml.v2 v2.4.0
Expand Down Expand Up @@ -65,24 +65,19 @@ require (
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/sasha-s/go-deadlock v0.3.1 // indirect
github.com/shirou/gopsutil/v3 v3.22.8 // indirect
github.com/shirou/gopsutil/v3 v3.22.10 // indirect
github.com/spf13/afero v1.9.2 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/subosito/gotenv v1.4.1 // indirect
github.com/vishvananda/netlink v1.2.1-beta.2.0.20220608195807-1a118fe229fc // indirect
github.com/vishvananda/netns v0.0.0-20211101163701-50045581ed74 // indirect
github.com/yusufpapurcu/wmi v1.2.2 // indirect
go.mongodb.org/mongo-driver v1.10.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/dig v1.15.0 // indirect
go.uber.org/fx v1.18.1 // indirect
go.uber.org/multierr v1.8.0 // indirect
go.uber.org/zap v1.21.0 // indirect
golang.org/x/exp v0.0.0-20220602145555-4a0574d9293f // indirect
golang.org/x/net v0.0.0-20221014081412-f15817d10f9b // indirect
golang.org/x/exp v0.0.0-20221106115401-f9659909a136 // indirect
golang.org/x/net v0.1.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/text v0.4.0 // indirect
golang.org/x/time v0.0.0-20220609170525-579cf78fd858 // indirect
golang.org/x/time v0.2.0 // indirect
google.golang.org/genproto v0.0.0-20221024183307-1bc688fe9f3e // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
Expand Down
54 changes: 15 additions & 39 deletions go.sum

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions pkg/printer/color.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,11 @@ func (c colorer) verdictDropped(a interface{}) string {
func (c colorer) verdictAudit(a interface{}) string {
return c.yellow.Sprint(a)
}

func (c colorer) verdictTraced(a interface{}) string {
return c.yellow.Sprint(a)
}

func (c colorer) verdictTranslated(a interface{}) string {
return c.yellow.Sprint(a)
}
16 changes: 16 additions & 0 deletions pkg/printer/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,18 @@ func GetFlowType(f *pb.Flow) string {

case api.MessageTypeCapture:
return f.GetDebugCapturePoint().String()
case api.MessageTypeTraceSock:
switch f.GetSockXlatePoint() {
case pb.SocketTranslationPoint_SOCK_XLATE_POINT_POST_DIRECTION_FWD:
return "post-xlate-fwd"
case pb.SocketTranslationPoint_SOCK_XLATE_POINT_POST_DIRECTION_REV:
return "post-xlate-rev"
case pb.SocketTranslationPoint_SOCK_XLATE_POINT_PRE_DIRECTION_FWD:
return "pre-xlate-fwd"
case pb.SocketTranslationPoint_SOCK_XLATE_POINT_PRE_DIRECTION_REV:
return "pre-xlate-rev"
}
return f.GetSockXlatePoint().String()
}

return "UNKNOWN"
Expand All @@ -246,6 +258,10 @@ func (p Printer) getVerdict(f *pb.Flow) string {
msg = "AUDITED"
}
return p.color.verdictAudit(msg)
case pb.Verdict_TRACED:
return p.color.verdictTraced(msg)
case pb.Verdict_TRANSLATED:
return p.color.verdictTranslated(msg)
default:
return msg
}
Expand Down
26 changes: 26 additions & 0 deletions pkg/printer/printer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,32 @@ func Test_getFlowType(t *testing.T) {
},
want: "policy-verdict:none INGRESS",
},
{
name: "SockLB pre-translate",
args: args{
f: &pb.Flow{
Verdict: pb.Verdict_TRACED,
EventType: &pb.CiliumEventType{
Type: monitorAPI.MessageTypeTraceSock,
},
SockXlatePoint: pb.SocketTranslationPoint_SOCK_XLATE_POINT_PRE_DIRECTION_FWD,
},
},
want: "pre-xlate-fwd",
},
{
name: "SockLB post-translate",
args: args{
f: &pb.Flow{
Verdict: pb.Verdict_TRANSLATED,
EventType: &pb.CiliumEventType{
Type: monitorAPI.MessageTypeTraceSock,
},
SockXlatePoint: pb.SocketTranslationPoint_SOCK_XLATE_POINT_POST_DIRECTION_FWD,
},
},
want: "post-xlate-fwd",
},
{
name: "Debug Capture",
args: args{
Expand Down
16 changes: 16 additions & 0 deletions vendor/github.com/cilium/cilium/AUTHORS

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading