-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7a7d9a2
commit 00192b6
Showing
7 changed files
with
96 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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,11 @@ | ||
##@ dev helpers | ||
|
||
.PHONY: flows-mock | ||
flows-mock: build ## Run flow capture using mocks | ||
./build/network-observability-cli get-flows --mock true | ||
tput reset | ||
|
||
.PHONY: packets-mock | ||
packets-mock: build ## Run packet capture using mocks | ||
./build/network-observability-cli get-packets --mock true | ||
tput reset |
This file contains 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 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 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,66 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"math/rand" | ||
"time" | ||
|
||
"github.com/netobserv/flowlogs-pipeline/pkg/config" | ||
"github.com/netobserv/flowlogs-pipeline/pkg/pipeline/write/grpc" | ||
"github.com/netobserv/flowlogs-pipeline/pkg/pipeline/write/grpc/genericmap" | ||
"google.golang.org/protobuf/types/known/anypb" | ||
) | ||
|
||
func sendMock(ch chan struct{}, client genericmap.CollectorClient) { | ||
|
||
gm := config.GenericMap{ | ||
"DstAddr": fmt.Sprintf("10.0.0.%d", rand.Intn(255)), | ||
"DstPort": rand.Intn(9999), | ||
"Proto": rand.Intn(255), | ||
"SrcAddr": fmt.Sprintf("10.0.0.%d", rand.Intn(255)), | ||
"SrcPort": rand.Intn(9999), | ||
"SrcK8S_Name": fmt.Sprintf("Pod-%d", rand.Intn(100)), | ||
"SrcK8S_Namespace": fmt.Sprintf("Namespace-%d", rand.Intn(100)), | ||
"SrcK8S_Type": "Pod", | ||
"TimeFlowEndMs": time.Now().UnixMilli(), | ||
} | ||
value, err := json.Marshal(gm) | ||
if err != nil { | ||
log.Error(err) | ||
return | ||
} | ||
_, err = client.Send(context.Background(), &genericmap.Flow{ | ||
GenericMap: &anypb.Any{ | ||
Value: value, | ||
}, | ||
}) | ||
if err != nil { | ||
log.Error(err) | ||
return | ||
} | ||
|
||
time.Sleep(10 * time.Millisecond) | ||
ch <- struct{}{} | ||
} | ||
|
||
func MockForever() { | ||
wait := make(chan struct{}) | ||
|
||
for !collectorStarted { | ||
log.Info("Waiting for collector to start...") | ||
time.Sleep(1 * time.Second) | ||
} | ||
|
||
for _, port := range ports { | ||
cc, err := grpc.ConnectClient("127.0.0.1", port) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
for { | ||
go sendMock(wait, cc.Client()) | ||
<-wait | ||
} | ||
} | ||
} |
This file contains 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 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 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