Skip to content

Commit 1aff759

Browse files
committed
flow summary shows drops/forwards and increase flow limit
Signed-off-by: Hunter Gregory <[email protected]>
1 parent 2f8321c commit 1aff759

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

ai/pkg/analysis/flows/types.go

+26
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,37 @@ type Connection struct {
2020
type FlowSummary map[string]*Connection
2121

2222
func (fs FlowSummary) FormatForLM() string {
23+
// FIXME hacky right now
24+
forwards := fs.connStrings(flowpb.Verdict_FORWARDED)
25+
drops := fs.connStrings(flowpb.Verdict_DROPPED)
26+
other := fs.connStrings(flowpb.Verdict_VERDICT_UNKNOWN)
27+
28+
return fmt.Sprintf("SUCCESSFUL CONNECTIONS:\n%s\n\nDROPPED CONNECTIONS:\n%s\n\nOTHER CONNECTIONS:\n%s", forwards, drops, other)
29+
}
30+
31+
func (fs FlowSummary) connStrings(verdict flowpb.Verdict) string {
2332
connStrings := make([]string, 0, len(fs))
2433
for _, conn := range fs {
34+
match := false
35+
for _, f := range conn.Flows {
36+
// FIXME hacky right now
37+
if f.GetVerdict() == verdict || (verdict == flowpb.Verdict_VERDICT_UNKNOWN && f.GetVerdict() != flowpb.Verdict_FORWARDED && f.GetVerdict() != flowpb.Verdict_DROPPED) {
38+
match = true
39+
break
40+
}
41+
}
42+
43+
if !match {
44+
continue
45+
}
46+
2547
connString := fmt.Sprintf("Connection: %s -> %s, Number of Flows: %d", conn.Pod1, conn.Pod2, len(conn.Flows))
2648
connStrings = append(connStrings, connString)
2749
}
2850

51+
if len(connStrings) == 0 {
52+
return "none"
53+
}
54+
2955
return strings.Join(connStrings, "\n")
3056
}

ai/pkg/retrieval/flows/retriever.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"time"
88

99
"github.com/microsoft/retina/ai/pkg/retrieval/flows/client"
10+
"github.com/microsoft/retina/ai/pkg/util"
1011

1112
flowpb "github.com/cilium/cilium/api/v1/flow"
1213
observerpb "github.com/cilium/cilium/api/v1/observer"
@@ -88,7 +89,7 @@ func (r *Retriever) Observe(ctx context.Context, maxFlows int) ([]*flowpb.Flow,
8889

8990
func flowsRequest() *observerpb.GetFlowsRequest {
9091
return &observerpb.GetFlowsRequest{
91-
Number: 200,
92+
Number: util.MaxFlowsFromHubbleRelay,
9293
Follow: false,
9394
Whitelist: []*flowpb.FlowFilter{},
9495
Blacklist: nil,

ai/pkg/scenarios/flows/handler.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
flowanalysis "github.com/microsoft/retina/ai/pkg/analysis/flows"
99
"github.com/microsoft/retina/ai/pkg/lm"
1010
flowretrieval "github.com/microsoft/retina/ai/pkg/retrieval/flows"
11+
"github.com/microsoft/retina/ai/pkg/util"
1112

1213
"github.com/sirupsen/logrus"
1314
"k8s.io/client-go/kubernetes"
@@ -58,7 +59,7 @@ func (h *Handler) Handle(ctx context.Context, question string, chat lm.ChatHisto
5859
return "", fmt.Errorf("error initializing flow retriever: %w", err)
5960
}
6061

61-
flows, err := h.r.Observe(ctx, 50)
62+
flows, err := h.r.Observe(ctx, util.MaxFlowsToAnalyze)
6263
if err != nil {
6364
return "", fmt.Errorf("error observing flows: %w", err)
6465
}

0 commit comments

Comments
 (0)