Skip to content

Commit

Permalink
Merge pull request #295 from openconfig/cache-empty-path
Browse files Browse the repository at this point in the history
do not write updates with empty paths to the cache
  • Loading branch information
karimra authored Nov 13, 2023
2 parents 9f82f0f + 6ffcd1a commit 908837c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
9 changes: 2 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
12 changes: 12 additions & 0 deletions pkg/cache/oc_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 908837c

Please sign in to comment.