Skip to content

Commit

Permalink
Project import generated by Copybara.
Browse files Browse the repository at this point in the history
FolderOrigin-RevId: /usr/local/google/home/hines/copybara/temp/folder-destination7086375037878102507/.
  • Loading branch information
Googler authored and marcushines committed Jan 26, 2023
1 parent 480bf53 commit c1b4525
Show file tree
Hide file tree
Showing 17 changed files with 472 additions and 555 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/ci-cpp-build-gnmi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: "bazel build"

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
schedule:
- cron: "0 0 * * *"

jobs:
build:
runs-on: ubuntu-latest
env:
BAZEL: bazelisk-linux-amd64
steps:
- uses: actions/checkout@v2
with:
submodules: recursive
- name: Mount bazel cache
uses: actions/cache@v2
with:
# See https://docs.bazel.build/versions/master/output_directories.html
path: "~/.cache/bazel"
# Create a new cache entry whenever Bazel files change.
# See https://docs.github.com/en/actions/guides/caching-dependencies-to-speed-up-workflows
key: bazel-${{ runner.os }}-build-${{ hashFiles('**/*.bzl', '**/*.bazel') }}
restore-keys: |
bazel-${{ runner.os }}-build-
- name: Install bazelisk
run: |
curl -LO "https://github.com/bazelbuild/bazelisk/releases/download/v1.8.1/$BAZEL"
chmod +x $BAZEL
sudo mv $BAZEL /usr/local/bin/bazel
- name: Build
run: bazel build //...

17 changes: 15 additions & 2 deletions cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func New(targets []string, opts ...Option) *Cache {
opt(&c.opts)
}
}
latency.RegisterMetadata(c.opts.latencyWindows)
metadata.RegisterLatencyMetadata(c.opts.latencyWindows)

for _, t := range targets {
c.Add(t)
Expand Down Expand Up @@ -331,7 +331,12 @@ func (c *Cache) GnmiUpdate(n *pb.Notification) error {
// each individual Update/Delete is sent to cache as
// a separate gnmi.Notification.
func (t *Target) GnmiUpdate(n *pb.Notification) error {
t.checkTimestamp(T(n.GetTimestamp()))
if u := n.GetUpdate(); len(u) > 0 {
if p := u[0].GetPath().GetElem(); len(p) > 0 && p[0].GetName() != metadata.Root {
// Record latest timestamp from the device, excluding all 'meta' paths.
t.checkTimestamp(T(n.GetTimestamp()))
}
}
switch {
// Store atomic notifications as a single leaf in the tree.
case n.Atomic:
Expand Down Expand Up @@ -424,6 +429,12 @@ func (t *Target) checkTimestamp(ts time.Time) {
}
}

func (t *Target) resetTimestamp() {
defer t.tsmu.Unlock()
t.tsmu.Lock()
t.ts = time.Time{}
}

func (t *Target) gnmiUpdate(n *pb.Notification) (*ctree.Leaf, error) {
realData := true
suffix := n.Update[0].Path
Expand Down Expand Up @@ -647,6 +658,8 @@ func (t *Target) updateMeta(clients func(*ctree.Leaf)) {
// Reset clears the Target of stale data upon a reconnection and notifies
// cache client of the removal.
func (t *Target) Reset() {
// Clear latest timestamp received from device.
t.resetTimestamp()
// Reset metadata to zero values (e.g. connected = false) and notify clients.
t.meta.Clear()
t.updateMeta(t.client)
Expand Down
12 changes: 6 additions & 6 deletions cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,9 @@ func TestMetadataLatency(t *testing.T) {
opt, _ := WithLatencyWindows([]string{"2s"}, 2*time.Second)
c := New([]string{"dev1"}, opt)
for _, path := range [][]string{
latency.Path(window, latency.Avg),
latency.Path(window, latency.Max),
latency.Path(window, latency.Min),
metadata.LatencyPath(window, latency.Avg),
metadata.LatencyPath(window, latency.Max),
metadata.LatencyPath(window, latency.Min),
} {
c.Query("dev1", path, func(_ []string, _ *ctree.Leaf, v interface{}) error {
t.Errorf("%s exists when device not in sync", strings.Join(path, "/"))
Expand All @@ -235,9 +235,9 @@ func TestMetadataLatency(t *testing.T) {
c.GnmiUpdate(gnmiNotification("dev1", nil, []string{"a", "1"}, timestamp, "b", false))
c.GetTarget("dev1").updateMeta(nil)
for _, path := range [][]string{
latency.Path(window, latency.Avg),
latency.Path(window, latency.Max),
latency.Path(window, latency.Min),
metadata.LatencyPath(window, latency.Avg),
metadata.LatencyPath(window, latency.Max),
metadata.LatencyPath(window, latency.Min),
} {
c.Query("dev1", path, func(_ []string, _ *ctree.Leaf, v interface{}) error {
l := v.(*pb.Notification).Update[0].Val.GetIntVal()
Expand Down
4 changes: 2 additions & 2 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,8 @@ func displayStreamingResults(ctx context.Context, query client.Query, cfg *Confi
return
}
b := make(pathmap)
if cfg.Timestamp != "" {
b.add(append(path, "timestamp"), ts)
if t := formatTime(ts, cfg); t != nil {
b.add(append(path, "timestamp"), t)
b.add(append(path, "value"), val)
} else {
b.add(path, val)
Expand Down
45 changes: 45 additions & 0 deletions cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,51 @@ update: {
}
}
}
`,
}, {
desc: "single target multiple paths with timestamp format (streaming)",
updates: []*fpb.Value{
{Path: []string{"a", "b"}, Value: &fpb.Value_IntValue{IntValue: &fpb.IntValue{Value: 5}}, Repeat: 1, Timestamp: &fpb.Timestamp{Timestamp: 100}},
{Value: &fpb.Value_Sync{Sync: 1}, Repeat: 1, Timestamp: &fpb.Timestamp{Timestamp: 300}},
{Path: []string{"a", "b"}, Value: &fpb.Value_IntValue{IntValue: &fpb.IntValue{Value: 6}}, Repeat: 1, Timestamp: &fpb.Timestamp{Timestamp: 400}},
},
query: client.Query{
Target: "dev1",
Queries: []client.Path{{"a"}},
Type: client.Stream,
TLS: &tls.Config{InsecureSkipVerify: true},
},
cfg: Config{
Display: display,
DisplayPrefix: "",
DisplayIndent: " ",
DisplayType: "group",
// StreamingDuration will expire before Count updates are received because
// no updates are being streamed in the test.
Count: 3,
StreamingDuration: 100 * time.Millisecond,
Timestamp: "raw",
},
want: `{
"dev1": {
"a": {
"b": {
"timestamp": 100,
"value": 5
}
}
}
}
{
"dev1": {
"a": {
"b": {
"timestamp": 400,
"value": 6
}
}
}
}
`,
}, {
desc: "single target multiple paths (single line)",
Expand Down
12 changes: 0 additions & 12 deletions client/gnmi/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import (
"google.golang.org/protobuf/proto"
"github.com/openconfig/ygot/ygot"
"github.com/openconfig/gnmi/client"
"github.com/openconfig/gnmi/client/grpcutil"
"github.com/openconfig/gnmi/path"
"github.com/openconfig/gnmi/value"

Expand Down Expand Up @@ -112,17 +111,6 @@ func New(ctx context.Context, d client.Destination) (client.Impl, error) {

// NewFromConn creates and returns the client based on the provided transport.
func NewFromConn(ctx context.Context, conn *grpc.ClientConn, d client.Destination) (*Client, error) {
ok, err := grpcutil.Lookup(ctx, conn, "gnmi.gNMI")
if err != nil {
log.V(1).Infof("gRPC reflection lookup on %q for service gnmi.gNMI failed: %v", d.Addrs, err)
// This check is disabled for now. Reflection will become part of gNMI
// specification in the near future, so we can't enforce it yet.
}
if !ok {
// This check is disabled for now. Reflection will become part of gNMI
// specification in the near future, so we can't enforce it yet.
}

cl := gpb.NewGNMIClient(conn)
return &Client{
conn: conn,
Expand Down
59 changes: 0 additions & 59 deletions client/grpcutil/lookup.go

This file was deleted.

70 changes: 0 additions & 70 deletions client/grpcutil/lookup_test.go

This file was deleted.

Loading

0 comments on commit c1b4525

Please sign in to comment.