Skip to content

Commit 83776a9

Browse files
authored
Report connections count between two workloads to Otterize cloud (#284)
1 parent 5d81d55 commit 83776a9

File tree

22 files changed

+785
-49
lines changed

22 files changed

+785
-49
lines changed

src/mapper/pkg/cloudclient/generated.go

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/mapper/pkg/cloudclient/schema.graphql

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,12 @@ enum ComponentType {
552552
NETWORK_MAPPER
553553
}
554554

555+
input ConnectionsCount {
556+
current: Int!
557+
removed: Int!
558+
added: Int!
559+
}
560+
555561
type CreateGitHubIntegrationResponse {
556562
integration: Integration!
557563
nextURL: String!
@@ -1427,6 +1433,7 @@ input IntentInput {
14271433
internet: InternetConfigInput
14281434
status: IntentStatusInput
14291435
resolutionData: String
1436+
connectionsCount: ConnectionsCount
14301437
}
14311438

14321439
input IntentRequestInput {
@@ -2340,6 +2347,12 @@ type Query {
23402347
clientServiceId: ID!
23412348
serverServiceId: ID!
23422349
): [NetworkPolicy!]!
2350+
""" Get edge connections count """
2351+
edgeConnectionsCount(
2352+
clientId: ID!
2353+
serverId: ID!
2354+
lastSeenAfter: Time!
2355+
): Int!
23432356
"""Get access log"""
23442357
accessLog(
23452358
filter: InputAccessLogFilter
@@ -2559,13 +2572,17 @@ enum RegulationCode {
25592572
ZERO_TRUST_EGRESS_ACCESS_COVERED
25602573
ZERO_TRUST_EXTERNAL_INGRESS_TAGGED
25612574
ZERO_TRUST_ALL_INTRA_CLUSTER_ACCESS_COVERED
2575+
THREAT_INTELLIGENCE
2576+
"""Detect known IOCs (IPs, domain names) against ingress and egress Internet traffic"""
2577+
THREAT_INTELLIGENCE_KNOWN_IOCS
25622578
}
25632579

25642580
enum RegulationStandard {
25652581
PCI_4_0
25662582
PII
25672583
HIPAA
25682584
ZERO_TRUST
2585+
THREAT_INTELLIGENCE
25692586
}
25702587

25712588
input ReportServiceMetadataInput {

src/mapper/pkg/clouduploader/cloud_upload.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ func (c *CloudUploader) NotifyIntents(ctx context.Context, intents []intentsstor
5858
Resources: httpResourceToHTTPConfInput(intent.Intent.HTTPResources),
5959
},
6060
}
61+
62+
if intent.ConnectionsCount != nil {
63+
toCloud.Intent.ConnectionsCount = intent.ConnectionsCount
64+
}
65+
6166
if intent.Intent.Client.PodOwnerKind != nil && intent.Intent.Client.PodOwnerKind.Kind != "" {
6267
toCloud.Intent.ClientWorkloadKind = lo.ToPtr(intent.Intent.Client.PodOwnerKind.Kind)
6368
}

src/mapper/pkg/clouduploader/cloud_uploader_test.go

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,11 @@ func (s *CloudUploaderTestSuite) addIntent(source string, srcNamespace string, d
4949
s.intentsHolder.AddIntent(
5050
testTimestamp,
5151
model.Intent{
52-
Client: &model.OtterizeServiceIdentity{Name: source, Namespace: srcNamespace},
53-
Server: &model.OtterizeServiceIdentity{Name: destination, Namespace: dstNamespace},
52+
Client: &model.OtterizeServiceIdentity{Name: source, Namespace: srcNamespace},
53+
Server: &model.OtterizeServiceIdentity{Name: destination, Namespace: dstNamespace},
54+
ResolutionData: lo.ToPtr("handleInternalTrafficTCPResult"),
5455
},
56+
[]int64{int64(20205)},
5557
)
5658
}
5759

@@ -75,12 +77,14 @@ func intentInput(clientName string, namespace string, serverName string, serverN
7577
}
7678

7779
return cloudclient.IntentInput{
78-
ClientName: nilIfEmpty(clientName),
79-
ServerName: nilIfEmpty(serverName),
80-
Namespace: nilIfEmpty(namespace),
81-
ServerNamespace: nilIfEmpty(serverNamespace),
82-
Topics: []*cloudclient.KafkaConfigInput{},
83-
Resources: []*cloudclient.HTTPConfigInput{},
80+
ClientName: nilIfEmpty(clientName),
81+
ServerName: nilIfEmpty(serverName),
82+
Namespace: nilIfEmpty(namespace),
83+
ServerNamespace: nilIfEmpty(serverNamespace),
84+
Topics: []*cloudclient.KafkaConfigInput{},
85+
Resources: []*cloudclient.HTTPConfigInput{},
86+
ResolutionData: lo.ToPtr("handleInternalTrafficTCPResult"),
87+
ConnectionsCount: lo.ToPtr(cloudclient.ConnectionsCount{Current: lo.ToPtr(1), Added: lo.ToPtr(1), Removed: lo.ToPtr(0)}),
8488
}
8589
}
8690

@@ -151,7 +155,7 @@ func (s *CloudUploaderTestSuite) TestUploadIntentsWithOperations() {
151155
},
152156
}
153157

154-
s.intentsHolder.AddIntent(testTimestamp, discoveredProduce)
158+
s.intentsHolder.AddIntent(testTimestamp, discoveredProduce, make([]int64, 0))
155159

156160
discoveredConsume := model.Intent{
157161
Client: &model.OtterizeServiceIdentity{Name: "client1", Namespace: s.testNamespace},
@@ -166,7 +170,7 @@ func (s *CloudUploaderTestSuite) TestUploadIntentsWithOperations() {
166170
HTTPResources: []model.HTTPResource{},
167171
}
168172

169-
s.intentsHolder.AddIntent(testTimestamp, discoveredConsume)
173+
s.intentsHolder.AddIntent(testTimestamp, discoveredConsume, make([]int64, 0))
170174
cloudIntent := []cloudclient.IntentInput{
171175
{
172176
ClientName: lo.ToPtr("client1"),
@@ -191,7 +195,7 @@ func (s *CloudUploaderTestSuite) TestUploadIntentsWithOperations() {
191195
s.cloudUploader.NotifyIntents(context.Background(), s.intentsHolder.GetNewIntentsSinceLastGet())
192196

193197
newTimestamp := testTimestamp.Add(time.Hour)
194-
s.intentsHolder.AddIntent(newTimestamp, discoveredProduce)
198+
s.intentsHolder.AddIntent(newTimestamp, discoveredProduce, make([]int64, 0))
195199

196200
produceOnly := []cloudclient.IntentInput{
197201
{
@@ -250,6 +254,8 @@ func (s *CloudUploaderTestSuite) TestUploadSameIntentOnce() {
250254

251255
s.cloudUploader.NotifyIntents(context.Background(), s.intentsHolder.GetNewIntentsSinceLastGet())
252256

257+
// We will upload the same intent twice, so we expect the add count to be 0
258+
intents[0].ConnectionsCount.Added = lo.ToPtr(0)
253259
s.clientMock.EXPECT().ReportDiscoveredIntents(gomock.Any(), GetMatcher(intents)).Return(nil).Times(1)
254260
s.addIntent("client", s.testNamespace, "server", s.testNamespace)
255261
s.cloudUploader.NotifyIntents(context.Background(), s.intentsHolder.GetNewIntentsSinceLastGet())

src/mapper/pkg/graph/generated/generated.go

Lines changed: 50 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/mapper/pkg/graph/model/models_gen.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)