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-destination12665513920209546645/.
  • Loading branch information
Googler authored and marcushines committed Sep 20, 2022
1 parent 41246b1 commit 480bf53
Show file tree
Hide file tree
Showing 26 changed files with 1,324 additions and 1,643 deletions.
38 changes: 0 additions & 38 deletions .github/workflows/ci-cpp-build-gnmi.yml

This file was deleted.

15 changes: 10 additions & 5 deletions cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,14 @@ import (
// int64 (nanoseconds since epoch).
func T(n int64) time.Time { return time.Unix(0, n) }

// Now is a function that can be overridden in tests to alter the timestamps
// applied to deletes and metadata updates.
var Now = time.Now
var (
// Now is a function that can be overridden in tests to alter the timestamps
// applied to deletes and metadata updates.
Now = time.Now

// ErrStale is the error returned if an update is stale.
ErrStale = errors.New("update is stale")
)

// A Target hosts an indexed cache of state for a single target.
type Target struct {
Expand Down Expand Up @@ -465,7 +470,7 @@ func (t *Target) gnmiUpdate(n *pb.Notification) (*ctree.Leaf, error) {
case n.GetTimestamp() < old.GetTimestamp():
// Update rejected. Timestamp < previous recorded timestamp.
t.meta.AddInt(metadata.StaleCount, 1)
return nil, errors.New("update is stale")
return nil, ErrStale
case n.GetTimestamp() == old.GetTimestamp():
if !proto.Equal(old, n) {
if log.V(1) {
Expand All @@ -474,7 +479,7 @@ func (t *Target) gnmiUpdate(n *pb.Notification) (*ctree.Leaf, error) {
// Allow to continue to update the cache taking the last supplied value for this timestamp.
} else {
t.meta.AddInt(metadata.StaleCount, 1)
return nil, errors.New("update is stale")
return nil, ErrStale
}
}
oldval.Update(n)
Expand Down
9 changes: 6 additions & 3 deletions cmd/gnmi_collector/gnmi_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
log "github.com/golang/glog"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc"
"github.com/openconfig/grpctunnel/dialer"
"github.com/openconfig/grpctunnel/tunnel"
"google.golang.org/protobuf/encoding/prototext"
"github.com/openconfig/gnmi/cache"
Expand All @@ -40,7 +41,6 @@ import (
"github.com/openconfig/gnmi/manager"
"github.com/openconfig/gnmi/subscribe"
"github.com/openconfig/gnmi/target"
"github.com/openconfig/gnmi/tunnel/dialer"

tunnelpb "github.com/openconfig/grpctunnel/proto/tunnel"
cpb "github.com/openconfig/gnmi/proto/collector"
Expand Down Expand Up @@ -156,16 +156,19 @@ func runCollector(ctx context.Context) error {
if c.tServer, err = tunnel.NewServer(tunnel.ServerConfig{AddTargetHandler: c.addTargetHandler, DeleteTargetHandler: c.deleteTargetHandler}); err != nil {
log.Fatalf("failed to setup tunnel server: %v", err)
}
tDialer, err := dialer.NewDialer(c.tServer)
tDialer, err := dialer.FromServer(c.tServer)
if err != nil {
log.Fatalf("failed to setup tunnel dialer: %v", err)
}

dialerContext := func(ctx context.Context, target string, opts ...grpc.DialOption) (conn *grpc.ClientConn, err error) {
return tDialer.DialContext(ctx, target, tunnelpb.TargetType_GNMI_GNOI.String(), opts...)
}
// Create connection manager with default dialer. Target specific dialer will be added later.
c.cm, err = connection.NewManagerCustom(
map[string]connection.Dial{
connection.DEFAULT: grpc.DialContext,
"tunnel": tDialer.DialContext},
"tunnel": dialerContext},
defaultDialOpts...)
if err != nil {
return fmt.Errorf("error creating connection.Manager: %v", err)
Expand Down
10 changes: 8 additions & 2 deletions coalesce/coalesce.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,16 @@ func (q *Queue) next() (interface{}, uint32, bool) {
if len(q.queue) == 0 {
return nil, 0, false
}
var i interface{}
i, q.queue = q.queue[0], q.queue[1:]
i := q.queue[0]
// Remove reference from underlying array to allow garbage collection.
q.queue[0] = nil
q.queue = q.queue[1:]
coalesced := q.coalesced[i]
delete(q.coalesced, i)
if len(q.queue) == 0 {
q.queue = nil
q.coalesced = make(map[interface{}]uint32)
}
return i, coalesced, true
}

Expand Down
17 changes: 11 additions & 6 deletions compile_protos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,17 @@
set -euo pipefail

# Go
proto_imports_go="${GOPATH}/src"
protoc -I=$proto_imports_go --go_out=$proto_imports_go --go_opt=paths=source_relative --go-grpc_out=$proto_imports_go --go-grpc_opt=paths=source_relative,require_unimplemented_servers=false github.com/openconfig/gnmi/testing/fake/proto/fake.proto
protoc -I=$proto_imports_go --go_out=$proto_imports_go --go_opt=paths=source_relative --go-grpc_out=$proto_imports_go --go-grpc_opt=paths=source_relative,require_unimplemented_servers=false github.com/openconfig/gnmi/proto/gnmi/gnmi.proto
protoc -I=$proto_imports_go --go_out=$proto_imports_go --go_opt=paths=source_relative --go-grpc_out=$proto_imports_go --go-grpc_opt=paths=source_relative,require_unimplemented_servers=false github.com/openconfig/gnmi/proto/collector/collector.proto
protoc -I=$proto_imports_go --go_out=$proto_imports_go --go_opt=paths=source_relative github.com/openconfig/gnmi/proto/gnmi_ext/gnmi_ext.proto
protoc -I=$proto_imports_go --go_out=$proto_imports_go --go_opt=paths=source_relative github.com/openconfig/gnmi/proto/target/target.proto
if ! which protoc-gen-go-grpc; then
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
fi
protobufsrc=${GOPATH}/src/github.com/google/protobuf/src
googleapis=${GOPATH}/src/github.com/googleapis/googleapis
proto_imports_go=".:${protobufsrc}:${googleapis}:${GOPATH}/src"
protoc -I=$proto_imports_go --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative,require_unimplemented_servers=false testing/fake/proto/fake.proto
protoc -I=$proto_imports_go --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative,require_unimplemented_servers=false proto/gnmi/gnmi.proto
protoc -I=$proto_imports_go --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative,require_unimplemented_servers=false proto/collector/collector.proto
protoc -I=$proto_imports_go --go_out=. --go_opt=paths=source_relative proto/gnmi_ext/gnmi_ext.proto
protoc -I=$proto_imports_go --go_out=. --go_opt=paths=source_relative proto/target/target.proto

# Python
proto_imports_python=".:${GOPATH}/src"
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
github.com/google/go-cmp v0.5.7
github.com/kylelemons/godebug v1.1.0
github.com/openconfig/grpctunnel v0.0.0-20220524190229-125331eabdde
github.com/openconfig/grpctunnel v0.0.0-20220819142823-6f5422b8ca70
github.com/openconfig/ygot v0.6.0
github.com/protocolbuffers/txtpbfmt v0.0.0-20220608084003-fc78c767cd6a
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQ
github.com/mitchellh/go-wordwrap v1.0.1/go.mod h1:R62XHJLzvMFRBbcrT7m7WgmE1eOyTSsCt+hzestvNj0=
github.com/openconfig/goyang v0.0.0-20200115183954-d0a48929f0ea h1:5MyIz4bN4vpH6aHDN339bkWXAjTkhg1ZKMhR4aIi5Rk=
github.com/openconfig/goyang v0.0.0-20200115183954-d0a48929f0ea/go.mod h1:dhXaV0JgHJzdrHi2l+w0fZrwArtXL7jEFoiqLEdmkvU=
github.com/openconfig/grpctunnel v0.0.0-20220524190229-125331eabdde h1:tSMKTQlWcHhdxQhn6P9myhLcoI+SzxF9e6hHWstCagU=
github.com/openconfig/grpctunnel v0.0.0-20220524190229-125331eabdde/go.mod h1:OmTWe7RyZj2CIzIgy4ovEBzCLBJzRvWSZmn7u02U9gU=
github.com/openconfig/grpctunnel v0.0.0-20220819142823-6f5422b8ca70 h1:t6SvvdfWCMlw0XPlsdxO8EgO+q/fXnTevDjdYREKFwU=
github.com/openconfig/grpctunnel v0.0.0-20220819142823-6f5422b8ca70/go.mod h1:OmTWe7RyZj2CIzIgy4ovEBzCLBJzRvWSZmn7u02U9gU=
github.com/openconfig/ygot v0.6.0 h1:kJJFPBrczC6TDnz/HMlFTJEdW2CuyUftV13XveIukg0=
github.com/openconfig/ygot v0.6.0/go.mod h1:o30svNf7O0xK+R35tlx95odkDmZWS9JyWWQSmIhqwAs=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down
16 changes: 16 additions & 0 deletions latency/latency_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
Copyright 2022 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package latency

import (
Expand Down
91 changes: 45 additions & 46 deletions proto/collector/collector.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion proto/collector/collector_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 480bf53

Please sign in to comment.