Skip to content

Commit

Permalink
Send discovery time from sniffer (#57)
Browse files Browse the repository at this point in the history
* Send discovery time with intents
  • Loading branch information
NetanelBollag authored Jan 15, 2023
1 parent 3e0140c commit a75c841
Show file tree
Hide file tree
Showing 16 changed files with 421 additions and 190 deletions.
35 changes: 14 additions & 21 deletions src/mapper/pkg/clouduploader/cloud_upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,31 +48,24 @@ func (c *CloudUploader) uploadDiscoveredIntents(ctx context.Context) {
return
}

var intents []cloudclient.IntentInput
for service, serviceIntents := range c.intentsHolder.GetIntentsPerService(nil) {
for _, serviceIntent := range serviceIntents {
var intent cloudclient.IntentInput
intent.ClientName = lo.ToPtr(service.Name)
intent.Namespace = lo.ToPtr(service.Namespace)
intent.ServerName = lo.ToPtr(serviceIntent.Name)
intent.ServerNamespace = lo.ToPtr(serviceIntent.Namespace)

intents = append(intents, intent)
var discoveredIntents []*cloudclient.DiscoveredIntentInput
for _, intent := range c.intentsHolder.GetIntents(nil) {
var discoveredIntent cloudclient.IntentInput
discoveredIntent.ClientName = lo.ToPtr(intent.Source.Name)
discoveredIntent.Namespace = lo.ToPtr(intent.Source.Namespace)
discoveredIntent.ServerName = lo.ToPtr(intent.Destination.Name)
discoveredIntent.ServerNamespace = lo.ToPtr(intent.Destination.Namespace)

input := &cloudclient.DiscoveredIntentInput{
DiscoveredAt: lo.ToPtr(intent.Timestamp),
Intent: &discoveredIntent,
}
}

if len(intents) == 0 {
return
discoveredIntents = append(discoveredIntents, input)
}

var discoveredIntents []*cloudclient.DiscoveredIntentInput
for _, intent := range intents {
input := cloudclient.DiscoveredIntentInput{
Intent: lo.ToPtr(intent),
DiscoveredAt: lo.ToPtr(time.Now()),
}

discoveredIntents = append(discoveredIntents, lo.ToPtr(input))
if len(discoveredIntents) == 0 {
return
}

uploadSuccess := client.ReportDiscoveredIntents(discoveredIntents)
Expand Down
6 changes: 6 additions & 0 deletions src/mapper/pkg/clouduploader/cloud_uploader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ import (
"github.com/stretchr/testify/suite"
"golang.org/x/oauth2"
"testing"
"time"
)

var (
testTimestamp = time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC)
)

type CloudUploaderTestSuite struct {
Expand Down Expand Up @@ -50,6 +55,7 @@ func (s *CloudUploaderTestSuite) addIntent(source string, srcNamespace string, d
s.intentsHolder.AddIntent(
model.OtterizeServiceIdentity{Name: source, Namespace: srcNamespace},
model.OtterizeServiceIdentity{Name: destination, Namespace: dstNamespace},
testTimestamp,
)
}

Expand Down
106 changes: 75 additions & 31 deletions src/mapper/pkg/graph/generated/generated.go

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

17 changes: 13 additions & 4 deletions src/mapper/pkg/graph/model/models_gen.go

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

Loading

0 comments on commit a75c841

Please sign in to comment.