From 6699366e113262c162d2bf86ef9839b4d2e01c59 Mon Sep 17 00:00:00 2001 From: Ori Shoshan Date: Thu, 19 Sep 2024 13:12:05 +0300 Subject: [PATCH] Revert "Allow the network mapper to track previously resolved DNS addresses based on ongoing TCP traffic" This reverts commit 6c1314d911c66a088cb4bd367c7ba76a5580daea. --- src/mapper/pkg/dnscache/dns_cache.go | 26 ++----------------- src/mapper/pkg/resolvers/resolver.go | 14 +++++----- .../pkg/resolvers/schema.helpers.resolvers.go | 15 ++--------- 3 files changed, 11 insertions(+), 44 deletions(-) diff --git a/src/mapper/pkg/dnscache/dns_cache.go b/src/mapper/pkg/dnscache/dns_cache.go index 7dc41ae8..db0d9e19 100644 --- a/src/mapper/pkg/dnscache/dns_cache.go +++ b/src/mapper/pkg/dnscache/dns_cache.go @@ -10,19 +10,15 @@ import ( ) type DNSCache struct { - cache *ttlcache.Cache[string, string] - ipToNameCache *ttlcache.Cache[string, string] + cache *ttlcache.Cache[string, string] } func NewDNSCache() *DNSCache { capacity := viper.GetInt(config.DNSCacheItemsMaxCapacityKey) dnsRecordCache := ttlcache.New[string, string](ttlcache.WithCapacity[string, string](uint64(capacity))) go dnsRecordCache.Start() - ipToNameCache := ttlcache.New[string, string](ttlcache.WithCapacity[string, string](uint64(capacity))) - go ipToNameCache.Start() lastCapacityReachedErrorPrint := time.Time{} - ipToNameLastCapacityReachedErrorPrint := time.Time{} dnsRecordCache.OnEviction(func(ctx context.Context, reason ttlcache.EvictionReason, item *ttlcache.Item[string, string]) { if reason == ttlcache.EvictionReasonCapacityReached && time.Since(lastCapacityReachedErrorPrint) > time.Minute { logrus.Warningf("DNS cache capacity reached entries are being dropped, consider increasing config '%s'", @@ -31,23 +27,13 @@ func NewDNSCache() *DNSCache { } }) - ipToNameCache.OnEviction(func(ctx context.Context, reason ttlcache.EvictionReason, item *ttlcache.Item[string, string]) { - if reason == ttlcache.EvictionReasonCapacityReached && time.Since(ipToNameLastCapacityReachedErrorPrint) > time.Minute { - logrus.Warningf("DNS cache capacity reached entries are being dropped, consider increasing config '%s'", - config.DNSCacheItemsMaxCapacityKey) - ipToNameLastCapacityReachedErrorPrint = time.Now() - } - }) - return &DNSCache{ - cache: dnsRecordCache, - ipToNameCache: ipToNameCache, + cache: dnsRecordCache, } } func (d *DNSCache) AddOrUpdateDNSData(dnsName string, ip string, ttl time.Duration) { d.cache.Set(dnsName, ip, ttl) - d.ipToNameCache.Set(ip, dnsName, ttl) } func (d *DNSCache) GetResolvedIP(dnsName string) (string, bool) { @@ -57,11 +43,3 @@ func (d *DNSCache) GetResolvedIP(dnsName string) (string, bool) { } return entry.Value(), true } - -func (d *DNSCache) GetResolvedDNSName(ip string) (string, bool) { - entry := d.ipToNameCache.Get(ip) - if entry == nil { - return "", false - } - return entry.Value(), true -} diff --git a/src/mapper/pkg/resolvers/resolver.go b/src/mapper/pkg/resolvers/resolver.go index 70ffc75c..143d7aba 100644 --- a/src/mapper/pkg/resolvers/resolver.go +++ b/src/mapper/pkg/resolvers/resolver.go @@ -3,10 +3,10 @@ package resolvers import ( "context" "github.com/99designs/gqlgen/graphql/handler" + "github.com/bugsnag/bugsnag-go/v2" "github.com/labstack/echo/v4" "github.com/otterize/intents-operator/src/shared/errors" "github.com/otterize/intents-operator/src/shared/serviceidresolver" - "github.com/otterize/intents-operator/src/shared/telemetries/errorreporter" "github.com/otterize/network-mapper/src/mapper/pkg/awsintentsholder" "github.com/otterize/network-mapper/src/mapper/pkg/dnscache" "github.com/otterize/network-mapper/src/mapper/pkg/externaltrafficholder" @@ -84,27 +84,27 @@ func (r *Resolver) Register(e *echo.Echo) { func (r *Resolver) RunForever(ctx context.Context) error { errgrp, errGrpCtx := errgroup.WithContext(ctx) errgrp.Go(func() error { - defer errorreporter.AutoNotify() + defer bugsnag.AutoNotify(errGrpCtx) return runHandleLoop(errGrpCtx, r.dnsCaptureResults, r.handleReportCaptureResults) }) errgrp.Go(func() error { - defer errorreporter.AutoNotify() + defer bugsnag.AutoNotify(errGrpCtx) return runHandleLoop(errGrpCtx, r.tcpCaptureResults, r.handleReportTCPCaptureResults) }) errgrp.Go(func() error { - defer errorreporter.AutoNotify() + defer bugsnag.AutoNotify(errGrpCtx) return runHandleLoop(errGrpCtx, r.socketScanResults, r.handleReportSocketScanResults) }) errgrp.Go(func() error { - defer errorreporter.AutoNotify() + defer bugsnag.AutoNotify(errGrpCtx) return runHandleLoop(errGrpCtx, r.kafkaMapperResults, r.handleReportKafkaMapperResults) }) errgrp.Go(func() error { - defer errorreporter.AutoNotify() + defer bugsnag.AutoNotify(errGrpCtx) return runHandleLoop(errGrpCtx, r.istioConnectionResults, r.handleReportIstioConnectionResults) }) errgrp.Go(func() error { - defer errorreporter.AutoNotify() + defer bugsnag.AutoNotify(errGrpCtx) return runHandleLoop(errGrpCtx, r.awsOperations, r.handleAWSOperationReport) }) err := errgrp.Wait() diff --git a/src/mapper/pkg/resolvers/schema.helpers.resolvers.go b/src/mapper/pkg/resolvers/schema.helpers.resolvers.go index 3c9678d5..a28ccd3d 100644 --- a/src/mapper/pkg/resolvers/schema.helpers.resolvers.go +++ b/src/mapper/pkg/resolvers/schema.helpers.resolvers.go @@ -397,7 +397,7 @@ func (r *Resolver) handleReportTCPCaptureResults(ctx context.Context, results mo } for _, dest := range captureItem.Destinations { - r.handleIncomingTCPResult(ctx, srcSvcIdentity, dest) + r.handleExternalIncomingTrafficTCPResult(ctx, srcSvcIdentity, dest) } } telemetrysender.SendNetworkMapper(telemetriesgql.EventTypeIntentsDiscoveredCapture, len(results.Results)) @@ -427,7 +427,7 @@ func (r *Resolver) reportIncomingInternetTraffic(ctx context.Context, srcIP stri return nil } -func (r *Resolver) handleIncomingTCPResult(ctx context.Context, srcIdentity model.OtterizeServiceIdentity, dest model.Destination) { +func (r *Resolver) handleExternalIncomingTrafficTCPResult(ctx context.Context, srcIdentity model.OtterizeServiceIdentity, dest model.Destination) { lastSeen := dest.LastSeen destIdentity, ok, err := r.resolveDestIdentity(ctx, dest, lastSeen) if err != nil { @@ -435,17 +435,6 @@ func (r *Resolver) handleIncomingTCPResult(ctx context.Context, srcIdentity mode return } if !ok { - // If the destination is not in cluster, check if it's traffic that goes to an IP address that we previously resolved by DNS. - dnsName, found := r.dnsCache.GetResolvedDNSName(dest.Destination) - if found && dest.DestinationIP != nil { - intent := externaltrafficholder.ExternalTrafficIntent{ - Client: srcIdentity, - LastSeen: dest.LastSeen, - DNSName: dnsName, - IPs: map[externaltrafficholder.IP]struct{}{externaltrafficholder.IP(*dest.DestinationIP): {}}, - } - r.externalTrafficIntentsHolder.AddIntent(intent) - } return }