Skip to content

Commit c1b4525

Browse files
Googlermarcushines
authored andcommitted
Project import generated by Copybara.
FolderOrigin-RevId: /usr/local/google/home/hines/copybara/temp/folder-destination7086375037878102507/.
1 parent 480bf53 commit c1b4525

File tree

17 files changed

+472
-555
lines changed

17 files changed

+472
-555
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: "bazel build"
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
schedule:
9+
- cron: "0 0 * * *"
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
env:
15+
BAZEL: bazelisk-linux-amd64
16+
steps:
17+
- uses: actions/checkout@v2
18+
with:
19+
submodules: recursive
20+
- name: Mount bazel cache
21+
uses: actions/cache@v2
22+
with:
23+
# See https://docs.bazel.build/versions/master/output_directories.html
24+
path: "~/.cache/bazel"
25+
# Create a new cache entry whenever Bazel files change.
26+
# See https://docs.github.com/en/actions/guides/caching-dependencies-to-speed-up-workflows
27+
key: bazel-${{ runner.os }}-build-${{ hashFiles('**/*.bzl', '**/*.bazel') }}
28+
restore-keys: |
29+
bazel-${{ runner.os }}-build-
30+
- name: Install bazelisk
31+
run: |
32+
curl -LO "https://github.com/bazelbuild/bazelisk/releases/download/v1.8.1/$BAZEL"
33+
chmod +x $BAZEL
34+
sudo mv $BAZEL /usr/local/bin/bazel
35+
- name: Build
36+
run: bazel build //...
37+

cache/cache.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func New(targets []string, opts ...Option) *Cache {
125125
opt(&c.opts)
126126
}
127127
}
128-
latency.RegisterMetadata(c.opts.latencyWindows)
128+
metadata.RegisterLatencyMetadata(c.opts.latencyWindows)
129129

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

432+
func (t *Target) resetTimestamp() {
433+
defer t.tsmu.Unlock()
434+
t.tsmu.Lock()
435+
t.ts = time.Time{}
436+
}
437+
427438
func (t *Target) gnmiUpdate(n *pb.Notification) (*ctree.Leaf, error) {
428439
realData := true
429440
suffix := n.Update[0].Path
@@ -647,6 +658,8 @@ func (t *Target) updateMeta(clients func(*ctree.Leaf)) {
647658
// Reset clears the Target of stale data upon a reconnection and notifies
648659
// cache client of the removal.
649660
func (t *Target) Reset() {
661+
// Clear latest timestamp received from device.
662+
t.resetTimestamp()
650663
// Reset metadata to zero values (e.g. connected = false) and notify clients.
651664
t.meta.Clear()
652665
t.updateMeta(t.client)

cache/cache_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,9 @@ func TestMetadataLatency(t *testing.T) {
221221
opt, _ := WithLatencyWindows([]string{"2s"}, 2*time.Second)
222222
c := New([]string{"dev1"}, opt)
223223
for _, path := range [][]string{
224-
latency.Path(window, latency.Avg),
225-
latency.Path(window, latency.Max),
226-
latency.Path(window, latency.Min),
224+
metadata.LatencyPath(window, latency.Avg),
225+
metadata.LatencyPath(window, latency.Max),
226+
metadata.LatencyPath(window, latency.Min),
227227
} {
228228
c.Query("dev1", path, func(_ []string, _ *ctree.Leaf, v interface{}) error {
229229
t.Errorf("%s exists when device not in sync", strings.Join(path, "/"))
@@ -235,9 +235,9 @@ func TestMetadataLatency(t *testing.T) {
235235
c.GnmiUpdate(gnmiNotification("dev1", nil, []string{"a", "1"}, timestamp, "b", false))
236236
c.GetTarget("dev1").updateMeta(nil)
237237
for _, path := range [][]string{
238-
latency.Path(window, latency.Avg),
239-
latency.Path(window, latency.Max),
240-
latency.Path(window, latency.Min),
238+
metadata.LatencyPath(window, latency.Avg),
239+
metadata.LatencyPath(window, latency.Max),
240+
metadata.LatencyPath(window, latency.Min),
241241
} {
242242
c.Query("dev1", path, func(_ []string, _ *ctree.Leaf, v interface{}) error {
243243
l := v.(*pb.Notification).Update[0].Val.GetIntVal()

cli/cli.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,8 @@ func displayStreamingResults(ctx context.Context, query client.Query, cfg *Confi
300300
return
301301
}
302302
b := make(pathmap)
303-
if cfg.Timestamp != "" {
304-
b.add(append(path, "timestamp"), ts)
303+
if t := formatTime(ts, cfg); t != nil {
304+
b.add(append(path, "timestamp"), t)
305305
b.add(append(path, "value"), val)
306306
} else {
307307
b.add(path, val)

cli/cli_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,51 @@ update: {
568568
}
569569
}
570570
}
571+
`,
572+
}, {
573+
desc: "single target multiple paths with timestamp format (streaming)",
574+
updates: []*fpb.Value{
575+
{Path: []string{"a", "b"}, Value: &fpb.Value_IntValue{IntValue: &fpb.IntValue{Value: 5}}, Repeat: 1, Timestamp: &fpb.Timestamp{Timestamp: 100}},
576+
{Value: &fpb.Value_Sync{Sync: 1}, Repeat: 1, Timestamp: &fpb.Timestamp{Timestamp: 300}},
577+
{Path: []string{"a", "b"}, Value: &fpb.Value_IntValue{IntValue: &fpb.IntValue{Value: 6}}, Repeat: 1, Timestamp: &fpb.Timestamp{Timestamp: 400}},
578+
},
579+
query: client.Query{
580+
Target: "dev1",
581+
Queries: []client.Path{{"a"}},
582+
Type: client.Stream,
583+
TLS: &tls.Config{InsecureSkipVerify: true},
584+
},
585+
cfg: Config{
586+
Display: display,
587+
DisplayPrefix: "",
588+
DisplayIndent: " ",
589+
DisplayType: "group",
590+
// StreamingDuration will expire before Count updates are received because
591+
// no updates are being streamed in the test.
592+
Count: 3,
593+
StreamingDuration: 100 * time.Millisecond,
594+
Timestamp: "raw",
595+
},
596+
want: `{
597+
"dev1": {
598+
"a": {
599+
"b": {
600+
"timestamp": 100,
601+
"value": 5
602+
}
603+
}
604+
}
605+
}
606+
{
607+
"dev1": {
608+
"a": {
609+
"b": {
610+
"timestamp": 400,
611+
"value": 6
612+
}
613+
}
614+
}
615+
}
571616
`,
572617
}, {
573618
desc: "single target multiple paths (single line)",

client/gnmi/client.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ import (
3636
"google.golang.org/protobuf/proto"
3737
"github.com/openconfig/ygot/ygot"
3838
"github.com/openconfig/gnmi/client"
39-
"github.com/openconfig/gnmi/client/grpcutil"
4039
"github.com/openconfig/gnmi/path"
4140
"github.com/openconfig/gnmi/value"
4241

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

113112
// NewFromConn creates and returns the client based on the provided transport.
114113
func NewFromConn(ctx context.Context, conn *grpc.ClientConn, d client.Destination) (*Client, error) {
115-
ok, err := grpcutil.Lookup(ctx, conn, "gnmi.gNMI")
116-
if err != nil {
117-
log.V(1).Infof("gRPC reflection lookup on %q for service gnmi.gNMI failed: %v", d.Addrs, err)
118-
// This check is disabled for now. Reflection will become part of gNMI
119-
// specification in the near future, so we can't enforce it yet.
120-
}
121-
if !ok {
122-
// This check is disabled for now. Reflection will become part of gNMI
123-
// specification in the near future, so we can't enforce it yet.
124-
}
125-
126114
cl := gpb.NewGNMIClient(conn)
127115
return &Client{
128116
conn: conn,

client/grpcutil/lookup.go

Lines changed: 0 additions & 59 deletions
This file was deleted.

client/grpcutil/lookup_test.go

Lines changed: 0 additions & 70 deletions
This file was deleted.

0 commit comments

Comments
 (0)