Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync fork with upstream master. #2

Merged
merged 34 commits into from
May 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
4abb362
tls: append h2 to tlsconfig.NextProtos (#2744)
menghanl Apr 8, 2019
981ad1f
doc: fixing broken link in rpc-error doc (#2753)
war-turtle Apr 9, 2019
bc316a5
doc: fixing link in keepalive docs (#2755)
war-turtle Apr 9, 2019
e330511
Change version to 1.21.0-dev (#2759)
dfawley Apr 9, 2019
289eb50
internal: clean up README (#2764)
dfawley Apr 11, 2019
3f98697
grpclb: handle service config and switch to pickfirst (#2719)
menghanl Apr 11, 2019
ee9f7f0
interop: add test case for "pick_first" (#2762)
menghanl Apr 11, 2019
597a4aa
grpc: remove excess new line from the log statement (#2766)
Apr 11, 2019
e1d95c3
credentials/alts: Support UDS addresses in ALTS interop test server (…
cesarghali Apr 11, 2019
a9de79b
Use 'go vet' and not 'go tool vet'. (#2768)
easwars Apr 12, 2019
776edd3
interceptor: new APIs for chaining client interceptors. (#2696)
WeiranFang Apr 15, 2019
9d8d97a
docs: add note about retrying UNAVAILABLE (#2774)
jeanbza Apr 15, 2019
3fc7430
transport: fix a race that could lead to memory leaks (#2765)
Apr 15, 2019
5b26317
xds: make local proto generated files (#2750)
lyuxuan Apr 16, 2019
d7af56a
internal: tweak ClientTransport.GracefulClose documentation (#2772)
jeanbza Apr 16, 2019
8260df7
grpc: implementation of PreparedMsg API
prannayk Apr 19, 2019
4dfb34b
Mark PreparedMsg as EXPERIMENTAL (#2783)
Apr 22, 2019
a8b5bd3
xds: wrr with random (#2745)
menghanl Apr 23, 2019
1e6ab1e
server: define ServerOption as interfaces (#2784)
menghanl Apr 26, 2019
b78962e
xds: save category in dropper (#2780)
menghanl Apr 26, 2019
a90198c
internal: seed random for wrr tests (#2791)
menghanl Apr 26, 2019
47e1ebe
client: return helpful error message when wait-for-ready RPCs fail wi…
yuqitao Apr 29, 2019
d5973a9
xds: support BalancerV2 API (#2781)
lyuxuan Apr 29, 2019
5ed5cba
dns: rate limit DNS resolution requests (#2760)
easwars May 2, 2019
a940832
internal: remove err from ClientTransport.GracefulClose (#2771)
jeanbza May 2, 2019
42baa8b
channelz: wait for clean up before next test (#2797)
lyuxuan May 2, 2019
028242f
xds: fix flaky test due to balancerV2 API update (#2799)
lyuxuan May 2, 2019
4b60e3b
credentials/alts: Panic Bug Fix (#2800)
cesarghali May 3, 2019
9949ee0
xds: lrs load store (#2779)
menghanl May 7, 2019
39ed87f
xds: report loads to traffic director (#2789)
menghanl May 7, 2019
4748a04
balancer: provide parsed target through BuildOptions (#2803)
lyuxuan May 9, 2019
a0be99a
xds: use BuildOptions.Target.endpoint string instead of deprecated cc…
lyuxuan May 10, 2019
ab90977
Fix using grpc.WithBalancerName("grpclb") explicitly (#2778) (#2802)
wjywbs May 10, 2019
4a199db
xds: split proto imports for message and service (#2812)
menghanl May 14, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/ISSUE_TEMPLATE/bug.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ labels: 'Type: Bug'

---

Please answer these questions before submitting your issue.
Please see the FAQ in our main README.md, then answer the questions below before
submitting your issue.

### What version of gRPC are you using?

Expand Down
2 changes: 2 additions & 0 deletions .github/ISSUE_TEMPLATE/feature.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ labels: 'Type: Feature'

---

Please see the FAQ in our main README.md before submitting your issue.

### Use case(s) - what problem will this feature solve?

### Proposed Solution
Expand Down
2 changes: 2 additions & 0 deletions .github/ISSUE_TEMPLATE/question.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ about: Ask a question about gRPC-Go
labels: 'Type: Question'

---

Please see the FAQ in our main README.md before submitting your issue.
57 changes: 40 additions & 17 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,50 @@ In order to protect both you and ourselves, you will need to sign the

## Guidelines for Pull Requests
How to get your contributions merged smoothly and quickly.

- Create **small PRs** that are narrowly focused on **addressing a single concern**. We often times receive PRs that are trying to fix several things at a time, but only one fix is considered acceptable, nothing gets merged and both author's & review's time is wasted. Create more PRs to address different concerns and everyone will be happy.

- For speculative changes, consider opening an issue and discussing it first. If you are suggesting a behavioral or API change, consider starting with a [gRFC proposal](https://github.com/grpc/proposal).

- Provide a good **PR description** as a record of **what** change is being made and **why** it was made. Link to a github issue if it exists.

- Don't fix code style and formatting unless you are already changing that line to address an issue. PRs with irrelevant changes won't be merged. If you do want to fix formatting or style, do that in a separate PR.

- Unless your PR is trivial, you should expect there will be reviewer comments that you'll need to address before merging. We expect you to be reasonably responsive to those comments, otherwise the PR will be closed after 2-3 weeks of inactivity.

- Maintain **clean commit history** and use **meaningful commit messages**. PRs with messy commit history are difficult to review and won't be merged. Use `rebase -i upstream/master` to curate your commit history and/or to bring in latest changes from master (but avoid rebasing in the middle of a code review).

- Keep your PR up to date with upstream/master (if there are merge conflicts, we can't really merge your change).

- **All tests need to be passing** before your change can be merged. We recommend you **run tests locally** before creating your PR to catch breakages early on.

- Create **small PRs** that are narrowly focused on **addressing a single
concern**. We often times receive PRs that are trying to fix several things at
a time, but only one fix is considered acceptable, nothing gets merged and
both author's & review's time is wasted. Create more PRs to address different
concerns and everyone will be happy.

- The grpc package should only depend on standard Go packages and a small number
of exceptions. If your contribution introduces new dependencies which are NOT
in the [list](https://godoc.org/google.golang.org/grpc?imports), you need a
discussion with gRPC-Go authors and consultants.

- For speculative changes, consider opening an issue and discussing it first. If
you are suggesting a behavioral or API change, consider starting with a [gRFC
proposal](https://github.com/grpc/proposal).

- Provide a good **PR description** as a record of **what** change is being made
and **why** it was made. Link to a github issue if it exists.

- Don't fix code style and formatting unless you are already changing that line
to address an issue. PRs with irrelevant changes won't be merged. If you do
want to fix formatting or style, do that in a separate PR.

- Unless your PR is trivial, you should expect there will be reviewer comments
that you'll need to address before merging. We expect you to be reasonably
responsive to those comments, otherwise the PR will be closed after 2-3 weeks
of inactivity.

- Maintain **clean commit history** and use **meaningful commit messages**. PRs
with messy commit history are difficult to review and won't be merged. Use
`rebase -i upstream/master` to curate your commit history and/or to bring in
latest changes from master (but avoid rebasing in the middle of a code
review).

- Keep your PR up to date with upstream/master (if there are merge conflicts, we
can't really merge your change).

- **All tests need to be passing** before your change can be merged. We
recommend you **run tests locally** before creating your PR to catch breakages
early on.
- `make all` to test everything, OR
- `make vet` to catch vet errors
- `make test` to run the tests
- `make testrace` to run tests in race mode
- optional `make testappengine` to run tests with appengine

- Exceptions to the rules can be made if there's a compelling reason for doing so.

2 changes: 1 addition & 1 deletion Documentation/keepalive.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ for details.
### Enforcement policy

[Enforcement
policy](https://godoc.org/google.golang.org/grpc/keepalive#ServerParameters) is
policy](https://godoc.org/google.golang.org/grpc/keepalive#EnforcementPolicy) is
a special setting on server side to protect server from malicious or misbehaving
clients.

Expand Down
2 changes: 1 addition & 1 deletion Documentation/rpc-errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ exit status 1
[details]: https://godoc.org/google.golang.org/grpc/status#Status.Details
[status-err]: https://godoc.org/google.golang.org/grpc/status#Status.Err
[status-error]: https://godoc.org/google.golang.org/grpc/status#Error
[example]: https://github.com/grpc/grpc-go/blob/master/examples/rpc_errors
[example]: https://github.com/grpc/grpc-go/tree/master/examples/features/errors
76 changes: 65 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,42 +1,96 @@
# gRPC-Go

[![Build Status](https://travis-ci.org/grpc/grpc-go.svg)](https://travis-ci.org/grpc/grpc-go) [![GoDoc](https://godoc.org/google.golang.org/grpc?status.svg)](https://godoc.org/google.golang.org/grpc) [![GoReportCard](https://goreportcard.com/badge/grpc/grpc-go)](https://goreportcard.com/report/github.com/grpc/grpc-go)
[![Build Status](https://travis-ci.org/grpc/grpc-go.svg)](https://travis-ci.org/grpc/grpc-go)
[![GoDoc](https://godoc.org/google.golang.org/grpc?status.svg)](https://godoc.org/google.golang.org/grpc)
[![GoReportCard](https://goreportcard.com/badge/grpc/grpc-go)](https://goreportcard.com/report/github.com/grpc/grpc-go)

The Go implementation of [gRPC](https://grpc.io/): A high performance, open source, general RPC framework that puts mobile and HTTP/2 first. For more information see the [gRPC Quick Start: Go](https://grpc.io/docs/quickstart/go.html) guide.
The Go implementation of [gRPC](https://grpc.io/): A high performance, open
source, general RPC framework that puts mobile and HTTP/2 first. For more
information see the [gRPC Quick Start:
Go](https://grpc.io/docs/quickstart/go.html) guide.

Installation
------------

To install this package, you need to install Go and setup your Go workspace on your computer. The simplest way to install the library is to run:
To install this package, you need to install Go and setup your Go workspace on
your computer. The simplest way to install the library is to run:

```
$ go get -u google.golang.org/grpc
```

With Go module support (Go 1.11+), simply `import "google.golang.org/grpc"` in
your source code and `go [build|run|test]` will automatically download the
necessary dependencies ([Go modules
ref](https://github.com/golang/go/wiki/Modules)).

If you are trying to access grpc-go from within China, please see the
[FAQ](#FAQ) below.

Prerequisites
-------------

gRPC-Go requires Go 1.9 or later.

Constraints
-----------
The grpc package should only depend on standard Go packages and a small number of exceptions. If your contribution introduces new dependencies which are NOT in the [list](https://godoc.org/google.golang.org/grpc?imports), you need a discussion with gRPC-Go authors and consultants.

Documentation
-------------
See [API documentation](https://godoc.org/google.golang.org/grpc) for package and API descriptions and find examples in the [examples directory](examples/).
- See [godoc](https://godoc.org/google.golang.org/grpc) for package and API
descriptions.
- Documentation on specific topics can be found in the [Documentation
directory](Documentation/).
- Examples can be found in the [examples directory](examples/).

Performance
-----------
See the current benchmarks for some of the languages supported in [this dashboard](https://performance-dot-grpc-testing.appspot.com/explore?dashboard=5652536396611584&widget=490377658&container=1286539696).
Performance benchmark data for grpc-go and other languages is maintained in
[this
dashboard](https://performance-dot-grpc-testing.appspot.com/explore?dashboard=5652536396611584&widget=490377658&container=1286539696).

Status
------
General Availability [Google Cloud Platform Launch Stages](https://cloud.google.com/terms/launch-stages).
General Availability [Google Cloud Platform Launch
Stages](https://cloud.google.com/terms/launch-stages).

FAQ
---

#### I/O Timeout Errors

The `golang.org` domain may be blocked from some countries. `go get` usually
produces an error like the following when this happens:

```
$ go get -u google.golang.org/grpc
package google.golang.org/grpc: unrecognized import path "google.golang.org/grpc" (https fetch: Get https://google.golang.org/grpc?go-get=1: dial tcp 216.239.37.1:443: i/o timeout)
```

To build Go code, there are several options:

- Set up a VPN and access google.golang.org through that.

- Without Go module support: `git clone` the repo manually:

```
git clone https://github.com/grpc/grpc-go.git $GOPATH/src/google.golang.org/grpc
```

You will need to do the same for all of grpc's dependencies in `golang.org`,
e.g. `golang.org/x/net`.

- With Go module support: it is possible to use the `replace` feature of `go
mod` to create aliases for golang.org packages. In your project's directory:

```
go mod edit -replace=google.golang.org/grpc=github.com/grpc/grpc-go@latest
go mod tidy
go mod vendor
go build -mod=vendor
```

Again, this will need to be done for all transitive dependencies hosted on
golang.org as well. Please refer to [this
issue](https://github.com/golang/go/issues/28652) in the golang repo regarding
this concern.

#### Compiling error, undefined: grpc.SupportPackageIsVersion

Please update proto package, gRPC package and rebuild the proto files:
Expand Down
6 changes: 6 additions & 0 deletions balancer/balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ type ClientConn interface {
ResolveNow(resolver.ResolveNowOption)

// Target returns the dial target for this ClientConn.
//
// Deprecated: Use the Target field in the BuildOptions instead.
Target() string
}

Expand All @@ -155,6 +157,10 @@ type BuildOptions struct {
Dialer func(context.Context, string) (net.Conn, error)
// ChannelzParentID is the entity parent's channelz unique identification number.
ChannelzParentID int64
// Target contains the parsed address info of the dial target. It is the same resolver.Target as
// passed to the resolver.
// See the documentation for the resolver.Target type for details about what it contains.
Target resolver.Target
}

// Builder creates a balancer.
Expand Down
64 changes: 36 additions & 28 deletions balancer/grpclb/grpclb.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"context"
"errors"
"strconv"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -129,19 +128,8 @@ func newLBBuilderWithFallbackTimeout(fallbackTimeout time.Duration) balancer.Bui
}
}

// newLBBuilderWithPickFirst creates a grpclb builder with pick-first.
func newLBBuilderWithPickFirst() balancer.Builder {
return &lbBuilder{
usePickFirst: true,
}
}

type lbBuilder struct {
fallbackTimeout time.Duration

// TODO: delete this when balancer can handle service config. This should be
// updated by service config.
usePickFirst bool // Use roundrobin or pickfirst for backends.
}

func (b *lbBuilder) Name() string {
Expand All @@ -155,19 +143,10 @@ func (b *lbBuilder) Build(cc balancer.ClientConn, opt balancer.BuildOptions) bal
scheme := "grpclb_internal_" + strconv.FormatInt(time.Now().UnixNano(), 36)
r := &lbManualResolver{scheme: scheme, ccb: cc}

var target string
targetSplitted := strings.Split(cc.Target(), ":///")
if len(targetSplitted) < 2 {
target = cc.Target()
} else {
target = targetSplitted[1]
}

lb := &lbBalancer{
cc: newLBCacheClientConn(cc),
target: target,
target: opt.Target.Endpoint,
opt: opt,
usePickFirst: b.usePickFirst,
fallbackTimeout: b.fallbackTimeout,
doneCh: make(chan struct{}),

Expand Down Expand Up @@ -231,11 +210,14 @@ type lbBalancer struct {
// serverList contains anything new. Each generate picker will also have
// reference to this list to do the first layer pick.
fullServerList []*lbpb.Server
// Backend addresses. It's kept so the addresses are available when
// switching between round_robin and pickfirst.
backendAddrs []resolver.Address
// All backends addresses, with metadata set to nil. This list contains all
// backend addresses in the same order and with the same duplicates as in
// serverlist. When generating picker, a SubConn slice with the same order
// but with only READY SCs will be gerenated.
backendAddrs []resolver.Address
backendAddrsWithoutMetadata []resolver.Address
// Roundrobin functionalities.
state connectivity.State
subConns map[resolver.Address]balancer.SubConn // Used to new/remove SubConn.
Expand Down Expand Up @@ -275,7 +257,7 @@ func (lb *lbBalancer) regeneratePicker(resetDrop bool) {
break
}
} else {
for _, a := range lb.backendAddrs {
for _, a := range lb.backendAddrsWithoutMetadata {
if sc, ok := lb.subConns[a]; ok {
if st, ok := lb.scStates[sc]; ok && st == connectivity.Ready {
readySCs = append(readySCs, sc)
Expand Down Expand Up @@ -339,6 +321,11 @@ func (lb *lbBalancer) aggregateSubConnStates() connectivity.State {
}

func (lb *lbBalancer) HandleSubConnStateChange(sc balancer.SubConn, s connectivity.State) {
panic("not used")
}

func (lb *lbBalancer) UpdateSubConnState(sc balancer.SubConn, scs balancer.SubConnState) {
s := scs.ConnectivityState
if grpclog.V(2) {
grpclog.Infof("lbBalancer: handle SubConn state change: %p, %v", sc, s)
}
Expand Down Expand Up @@ -371,7 +358,7 @@ func (lb *lbBalancer) HandleSubConnStateChange(sc balancer.SubConn, s connectivi
if lb.state != connectivity.Ready {
if !lb.inFallback && !lb.remoteBalancerConnected {
// Enter fallback.
lb.refreshSubConns(lb.resolvedBackendAddrs, false)
lb.refreshSubConns(lb.resolvedBackendAddrs, true, lb.usePickFirst)
}
}
}
Expand Down Expand Up @@ -410,17 +397,38 @@ func (lb *lbBalancer) fallbackToBackendsAfter(fallbackTimeout time.Duration) {
return
}
// Enter fallback.
lb.refreshSubConns(lb.resolvedBackendAddrs, false)
lb.refreshSubConns(lb.resolvedBackendAddrs, true, lb.usePickFirst)
lb.mu.Unlock()
}

// HandleResolvedAddrs sends the updated remoteLB addresses to remoteLB
// clientConn. The remoteLB clientConn will handle creating/removing remoteLB
// connections.
func (lb *lbBalancer) HandleResolvedAddrs(addrs []resolver.Address, err error) {
panic("not used")
}

func (lb *lbBalancer) handleServiceConfig(sc string) {
lb.mu.Lock()
defer lb.mu.Unlock()

newUsePickFirst := childIsPickFirst(sc)
if lb.usePickFirst == newUsePickFirst {
return
}
if grpclog.V(2) {
grpclog.Infof("lbBalancer: switching mode, new usePickFirst: %+v", newUsePickFirst)
}
lb.refreshSubConns(lb.backendAddrs, lb.inFallback, newUsePickFirst)
}

func (lb *lbBalancer) UpdateResolverState(rs resolver.State) {
if grpclog.V(2) {
grpclog.Infof("lbBalancer: handleResolvedResult: %+v", addrs)
grpclog.Infof("lbBalancer: UpdateResolverState: %+v", rs)
}
lb.handleServiceConfig(rs.ServiceConfig)

addrs := rs.Addresses
if len(addrs) <= 0 {
return
}
Expand Down Expand Up @@ -457,7 +465,7 @@ func (lb *lbBalancer) HandleResolvedAddrs(addrs []resolver.Address, err error) {
// This means we received a new list of resolved backends, and we are
// still in fallback mode. Need to update the list of backends we are
// using to the new list of backends.
lb.refreshSubConns(lb.resolvedBackendAddrs, false)
lb.refreshSubConns(lb.resolvedBackendAddrs, true, lb.usePickFirst)
}
lb.mu.Unlock()
}
Expand Down
Loading