From 6ffcd1ab80d526867174583586711c9f25ff1114 Mon Sep 17 00:00:00 2001 From: Karim Radhouani Date: Mon, 13 Nov 2023 09:49:36 -0800 Subject: [PATCH] do not write updates with empty paths to the cache --- go.mod | 9 ++------- go.sum | 4 ++++ pkg/cache/oc_cache.go | 12 ++++++++++++ 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index 4a2867df..6b42a789 100644 --- a/go.mod +++ b/go.mod @@ -2,11 +2,6 @@ module github.com/openconfig/gnmic go 1.21.1 -replace ( - github.com/openconfig/gnmic/pkg/api => ./pkg/api - github.com/openconfig/gnmic/pkg/cache => ./pkg/cache -) - require ( github.com/Shopify/sarama v1.38.1 github.com/adrg/xdg v0.4.0 @@ -43,8 +38,8 @@ require ( github.com/nsf/termbox-go v1.1.1 github.com/olekukonko/tablewriter v0.0.5 github.com/openconfig/gnmi v0.10.0 - github.com/openconfig/gnmic/pkg/api v0.34.0 - github.com/openconfig/gnmic/pkg/cache v0.34.0 + github.com/openconfig/gnmic/pkg/api v0.1.1 + github.com/openconfig/gnmic/pkg/cache v0.1.1 github.com/openconfig/gnmic/pkg/path v0.1.1 github.com/openconfig/gnmic/pkg/target v0.1.1 github.com/openconfig/gnmic/pkg/testutils v0.1.0 diff --git a/go.sum b/go.sum index 55cfb04b..7ee59b43 100644 --- a/go.sum +++ b/go.sum @@ -954,6 +954,10 @@ github.com/openconfig/gnmi v0.0.0-20200414194230-1597cc0f2600/go.mod h1:M/EcuapN github.com/openconfig/gnmi v0.0.0-20200508230933-d19cebf5e7be/go.mod h1:M/EcuapNQgvzxo1DDXHK4tx3QpYM/uG4l591v33jG2A= github.com/openconfig/gnmi v0.10.0 h1:kQEZ/9ek3Vp2Y5IVuV2L/ba8/77TgjdXg505QXvYmg8= github.com/openconfig/gnmi v0.10.0/go.mod h1:Y9os75GmSkhHw2wX8sMsxfI7qRGAEcDh8NTa5a8vj6E= +github.com/openconfig/gnmic/pkg/api v0.1.1 h1:9d7mhVdoz9k+73h9qoWvwcTpmWvLhjavHg1jyuRGq6Y= +github.com/openconfig/gnmic/pkg/api v0.1.1/go.mod h1:kX1bJnTRTuYyvceHLcs8JDkLL3QzTpaeYVfQGphYWE4= +github.com/openconfig/gnmic/pkg/cache v0.1.1 h1:cT3swYn6NOmBFELFMJeK3GsWEviRgo9+mft7CKVh3sE= +github.com/openconfig/gnmic/pkg/cache v0.1.1/go.mod h1:EQpcUMnkiUUvsSpAux8Jul8Tfkz6XT/wJvXbgohCyr4= github.com/openconfig/gnmic/pkg/path v0.1.1 h1:C6vZTC0NsMOGyre7ueXRS8vmYvCW9sdHKQ5cqWYiNPw= github.com/openconfig/gnmic/pkg/path v0.1.1/go.mod h1:Z2Ejm3UIO7WDxlXsnJmzE7/lnWe/0neCuXW6QDwmYHQ= github.com/openconfig/gnmic/pkg/target v0.1.1 h1:/XA3cFs3FTb2Bli4TdvLYf0b/ifMX1gDOMY+f8LcTr0= diff --git a/pkg/cache/oc_cache.go b/pkg/cache/oc_cache.go index 3e24ea57..4baa7e7b 100644 --- a/pkg/cache/oc_cache.go +++ b/pkg/cache/oc_cache.go @@ -105,6 +105,18 @@ func (gc *gnmiCache) Write(ctx context.Context, measName string, m proto.Message gc.logger.Printf("subscription=%q: response missing target: %v", measName, rsp) return } + + // if the update does not have a prefix path, + // check that each update has a path. + if len(rsp.Update.GetPrefix().GetElem()) == 0 { + for _, upd := range rsp.Update.GetUpdate() { + if len(upd.GetPath().GetElem()) == 0 { + gc.logger.Printf("write fail: received an update with en empty path: %v", upd) + return + } + } + } + gc.m.Lock() sCache, ok := gc.caches[measName] if !ok {