Skip to content

Commit 8f0c820

Browse files
authored
Fix issue where invalid traffic reports were reported to Otterize Cloud (#280)
1 parent e4dc29c commit 8f0c820

File tree

3 files changed

+35
-19
lines changed

3 files changed

+35
-19
lines changed

src/mapper/pkg/clouduploader/cloud_upload.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -311,10 +311,10 @@ func (c *CloudUploader) NotifyTrafficLevels(ctx context.Context, trafficLevels t
311311
var inputs []cloudclient.TrafficLevelInput
312312
for trafficPair, trafficData := range trafficLevels {
313313
inputs = append(inputs, cloudclient.TrafficLevelInput{
314-
ClientName: trafficPair.Source.Name,
315-
ClientNamespace: trafficPair.Source.Namespace,
316-
ServerName: trafficPair.Destination.Name,
317-
ServerNamespace: trafficPair.Destination.Namespace,
314+
ClientName: trafficPair.SourceName,
315+
ClientNamespace: trafficPair.SourceNamespace,
316+
ServerName: trafficPair.DestinationName,
317+
ServerNamespace: trafficPair.DestinationNamespace,
318318
DataBytesPerSecond: trafficData.Bytes,
319319
FlowsCountPerSecond: trafficData.Flows,
320320
})

src/mapper/pkg/collectors/traffic/collector.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ import (
77
)
88

99
type TrafficLevelKey struct {
10-
Source serviceidentity.ServiceIdentity
11-
Destination serviceidentity.ServiceIdentity
10+
SourceName string
11+
SourceNamespace string
12+
DestinationName string
13+
DestinationNamespace string
1214
}
1315

1416
type TrafficLevelData struct {
@@ -34,8 +36,10 @@ func NewCollector() *Collector {
3436

3537
func (c *Collector) Add(source, destination serviceidentity.ServiceIdentity, bytes, flows int) {
3638
trafficKey := TrafficLevelKey{
37-
Source: source,
38-
Destination: destination,
39+
SourceName: source.Name,
40+
SourceNamespace: source.Namespace,
41+
DestinationName: destination.Name,
42+
DestinationNamespace: destination.Namespace,
3943
}
4044

4145
c.trafficLevels[trafficKey] = append(c.trafficLevels[trafficKey], TrafficLevelData{

src/mapper/pkg/resolvers/schema.helpers.resolvers.go

+23-11
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ func (r *Resolver) handleTrafficLevelReport(ctx context.Context, results model.T
382382
logrus.
383383
WithField("ip", report.SrcIP).
384384
WithError(err).
385-
Error("Could not resolve source IP to identity")
385+
Debug("could not resolve source IP to identity")
386386
continue
387387
}
388388

@@ -392,7 +392,19 @@ func (r *Resolver) handleTrafficLevelReport(ctx context.Context, results model.T
392392
logrus.
393393
WithField("ip", report.DstIP).
394394
WithError(err).
395-
Error("Could not resolve destination IP to identity")
395+
Debug("could not resolve destination IP to identity")
396+
continue
397+
}
398+
399+
if sourceIdentity.Name == "" || destinationIdentity.Name == "" || sourceIdentity.Namespace == "" || destinationIdentity.Namespace == "" {
400+
// catches a bug where the source or destination identity is not set, without any other errors
401+
logrus.
402+
WithContext(ctx).
403+
WithField("sourceIP", report.SrcIP).
404+
WithField("destinationIP", report.DstIP).
405+
WithField("sourceIdentity", sourceIdentity.String()).
406+
WithField("destinationIdentity", destinationIdentity.String()).
407+
Error("invalid traffic level report")
396408
continue
397409
}
398410

@@ -885,38 +897,38 @@ func (r *Resolver) resolveIPToIdentity(ctx context.Context, ip string) (servicei
885897
isPod, err := r.kubeFinder.IsPodIp(ctx, ip)
886898

887899
if err != nil {
888-
logrus.WithField("ip", ip).WithError(err).Error("could not determine if IP is a pod")
889900
return serviceidentity.ServiceIdentity{}, errors.Wrap(err)
890901
}
891902

892903
if isPod {
893904
sourcePod, err := r.kubeFinder.ResolveIPToPod(ctx, ip)
894905

895906
if err != nil {
896-
logrus.WithField("ip", ip).WithError(err).Error("could not resolve source pod")
897907
return serviceidentity.ServiceIdentity{}, errors.Wrap(err)
898908
}
899909

900910
identity, err = r.serviceIdResolver.ResolvePodToServiceIdentity(ctx, sourcePod)
901911

902912
if err != nil {
903-
logrus.WithField("ip", ip).WithError(err).Error("could not resolve source identity")
904913
return serviceidentity.ServiceIdentity{}, errors.Wrap(err)
905914
}
906915
} else {
907916
sourceService, ok, err := r.kubeFinder.ResolveIPToService(ctx, ip)
908-
909-
if !ok || err != nil {
910-
logrus.WithField("ip", ip).WithError(err).Error("could not resolve source service")
917+
if !ok {
918+
err = errors.New("no mapping between IP and service")
919+
}
920+
if err != nil {
911921
return serviceidentity.ServiceIdentity{}, errors.Wrap(err)
912922
}
913923

914924
otrSourceIdentity, ok, err := r.kubeFinder.ResolveOtterizeIdentityForService(ctx, sourceService, time.Now())
915-
916-
if !ok || err != nil {
917-
logrus.WithField("ip", ip).WithError(err).Error("could not resolve source identity")
925+
if !ok {
926+
err = errors.New("no mapping between service and otterize identity")
927+
}
928+
if err != nil {
918929
return serviceidentity.ServiceIdentity{}, errors.Wrap(err)
919930
}
931+
920932
identity = serviceidentity.ServiceIdentity{
921933
Name: otrSourceIdentity.Name,
922934
Namespace: otrSourceIdentity.Namespace,

0 commit comments

Comments
 (0)