Skip to content

Commit

Permalink
Merge pull request #638 from karimra/caches
Browse files Browse the repository at this point in the history
add other cache implementations
  • Loading branch information
karimra authored Sep 26, 2022
2 parents 41b5a10 + cdbb057 commit 30e2dbc
Show file tree
Hide file tree
Showing 61 changed files with 3,418 additions and 656 deletions.
7 changes: 2 additions & 5 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@ import (
"github.com/gorilla/mux"
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
"github.com/jhump/protoreflect/desc"
"github.com/karimra/gnmic/cache"
"github.com/karimra/gnmic/config"
"github.com/karimra/gnmic/formatters"
"github.com/karimra/gnmic/inputs"
"github.com/karimra/gnmic/lockers"
"github.com/karimra/gnmic/outputs"
"github.com/karimra/gnmic/target"
"github.com/karimra/gnmic/types"
"github.com/openconfig/gnmi/cache"
"github.com/openconfig/gnmi/match"
"github.com/openconfig/gnmi/proto/gnmi"
"github.com/openconfig/goyang/pkg/yang"
"github.com/openconfig/grpctunnel/tunnel"
Expand Down Expand Up @@ -89,8 +88,7 @@ type App struct {
// gRPC server where the gNMI service will be registered
grpcSrv *grpc.Server
// gNMI cache
c *cache.Cache
match *match.Match
c cache.Cache
subscribeRPCsem *semaphore.Weighted
unaryRPCsem *semaphore.Weighted
// tunnel server
Expand Down Expand Up @@ -132,7 +130,6 @@ func New() *App {

wg: new(sync.WaitGroup),
printLock: new(sync.Mutex),
c: cache.New(nil),
// tunnel server
ttm: new(sync.RWMutex),
tunTargets: make(map[tunnel.Target]struct{}),
Expand Down
17 changes: 5 additions & 12 deletions app/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func (a *App) Export(ctx context.Context, rsp *gnmi.SubscribeResponse, m outputs
if rsp == nil {
return
}
go a.updateCache(rsp, m)
go a.updateCache(ctx, rsp, m)
wg := new(sync.WaitGroup)
// target has no outputs explicitly defined
if len(outs) == 0 {
Expand Down Expand Up @@ -168,7 +168,7 @@ func (a *App) Export(ctx context.Context, rsp *gnmi.SubscribeResponse, m outputs
wg.Wait()
}

func (a *App) updateCache(rsp *gnmi.SubscribeResponse, m outputs.Meta) {
func (a *App) updateCache(ctx context.Context, rsp *gnmi.SubscribeResponse, m outputs.Meta) {
if a.c == nil {
return
}
Expand All @@ -186,18 +186,11 @@ func (a *App) updateCache(rsp *gnmi.SubscribeResponse, m outputs.Meta) {
a.Logger.Printf("response missing target")
return
}
if !a.c.HasTarget(target) {
a.c.Add(target)
a.Logger.Printf("target %q added to the local cache", target)
}
if a.Config.Debug {
a.Logger.Printf("updating target %q local cache", target)
}
err := a.c.GnmiUpdate(r.Update)
if err != nil {
a.Logger.Printf("failed to update gNMI cache: %v", err)
return
a.Logger.Printf("updating target %q cache", target)
}
sub := m["subscription-name"]
a.c.Write(ctx, sub, &gnmi.SubscribeResponse{Response: &gnmi.SubscribeResponse_Update{Update: r.Update}})
}
}

Expand Down
2 changes: 1 addition & 1 deletion app/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ func resolveGlobs(globs []string) ([]string, error) {
func walkDir(path, ext string) ([]string, error) {
fs := make([]string, 0)
err := filepath.Walk(path,
func(path string, info os.FileInfo, err error) error {
func(path string, _ os.FileInfo, err error) error {
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit 30e2dbc

Please sign in to comment.