Skip to content

Commit

Permalink
Merge pull request #2333 from yarpc/antonio.alors/release
Browse files Browse the repository at this point in the history
Preparing release v1.75.3
  • Loading branch information
bananacocodrilo authored Dec 4, 2024
2 parents b202bb9 + dd6a222 commit bc0cd15
Show file tree
Hide file tree
Showing 4 changed files with 219 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

=======
## [1.75.3] - 2024-12-04
### Added
- Noop resolver to use in clients with custom load balancing.


## [1.75.2] - 2024-11-19
### Added
- HTTP2 server support for the HTTP inbound.
Expand Down Expand Up @@ -1535,6 +1540,7 @@ This release requires regeneration of ThriftRW code.
## 0.1.0 - 2016-08-31
- Initial release.
[1.75.3]: https://github.com/yarpc/yarpc-go/compare/v1.75.2...1.75.3
[1.75.2]: https://github.com/yarpc/yarpc-go/compare/v1.75.1...1.75.2
[1.75.1]: https://github.com/yarpc/yarpc-go/compare/v1.75.0...1.75.1
[1.75.0]: https://github.com/yarpc/yarpc-go/compare/v1.73.2...1.75.0
Expand Down
61 changes: 61 additions & 0 deletions pkg/noopresolver/noopresolver.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright (c) 2024 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package noopresolver

import (
"errors"

"google.golang.org/grpc/resolver"
)

// Scheme is the scheme for the noop resolver.
const Scheme = "noop"

var errInvalidTarget = errors.New("noop resolver doesn't accept a target")

type noopBuilder struct{}

// NewBuilder creates a new noop resolver builder. This resolver won't resolve any address, so it expects the target to be empty.
// It is intended to be used by clients with custom resolution logic.
func NewBuilder() resolver.Builder {
return &noopBuilder{}
}

func (*noopBuilder) Build(target resolver.Target, _ resolver.ClientConn, opts resolver.BuildOptions) (resolver.Resolver, error) {
if target.Endpoint() != "" || opts.Dialer != nil {
return nil, errInvalidTarget
}
return &noopResolver{}, nil
}

func (*noopBuilder) Scheme() string {
return Scheme
}

type noopResolver struct{}

func (*noopResolver) ResolveNow(_ resolver.ResolveNowOptions) {}

func (*noopResolver) Close() {}

func init() {
resolver.Register(&noopBuilder{})
}
151 changes: 151 additions & 0 deletions pkg/noopresolver/noopresolver_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
// Copyright (c) 2024 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package noopresolver

import (
"context"
"errors"
"net"
"net/url"
"sync"
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/reflection"
"google.golang.org/grpc/resolver"
"google.golang.org/grpc/serviceconfig"
)

var _ resolver.ClientConn = (*testClientConn)(nil)

func TestBuild(t *testing.T) {
tests := []struct {
msg string
target resolver.Target
watAddress []resolver.Address
wantErr string
}{
{
msg: "Non empty target",
target: resolver.Target{URL: url.URL{Path: "/[2001:db8::1]:http"}},
wantErr: errInvalidTarget.Error(),
},
{
msg: "Empty target",
target: resolver.Target{URL: url.URL{Path: ""}},
},
}

builder := &noopBuilder{}
for _, tt := range tests {
t.Run(tt.msg, func(t *testing.T) {

cc := &testClientConn{target: tt.target.URL.Host}
gotResolver, gotError := builder.Build(tt.target, cc, resolver.BuildOptions{})
if tt.wantErr != "" {
assert.EqualError(t, gotError, tt.wantErr)
} else {
assert.ElementsMatch(t, cc.State.Addresses, tt.watAddress)
gotResolver.Close()
}
})
}
}

func TestClientConnectionIntegration(t *testing.T) {
dest := "127.0.0.1:3456"
wantAddr := []resolver.Address{}

b := NewBuilder()

cc := &testClientConn{}
_, err := b.Build(resolver.Target{}, cc, resolver.BuildOptions{})
assert.ElementsMatch(t, cc.State.Addresses, wantAddr, "Client connection received the wrong list of addresses")
require.NoError(t, err, "unexpected error building the resolver")

cc.failUpdate = true
_, err = b.Build(resolver.Target{URL: url.URL{Path: dest}}, cc, resolver.BuildOptions{})
require.Error(t, err)

}

func TestGRPCIntegration(t *testing.T) {
ln, err := net.Listen("tcp", "127.0.0.1:0")
require.NoError(t, err)

s := grpc.NewServer()
reflection.Register(s)
t.Cleanup(s.GracefulStop)

go func() {
err := s.Serve(ln)
require.NoError(t, err)
}()

b := NewBuilder()
ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
defer cancel()

_, err = grpc.DialContext(ctx, b.Scheme()+":///"+ln.Addr().String(), grpc.WithBlock(), grpc.WithTransportCredentials(insecure.NewCredentials()))
require.Error(t, err)

_, err = grpc.DialContext(ctx, b.Scheme()+":///", grpc.WithBlock(), grpc.WithTransportCredentials(insecure.NewCredentials()))
require.Error(t, err, "expected to fail with deadline exceeded")
}

type testClientConn struct {
target string
failUpdate bool
State resolver.State
mu sync.Mutex
addrs []resolver.Address // protected by mu
t *testing.T
}

func (t *testClientConn) ParseServiceConfig(string) *serviceconfig.ParseResult {
return nil
}

func (t *testClientConn) ReportError(error) {
}

func (t *testClientConn) UpdateState(state resolver.State) error {
t.State = state
if t.failUpdate {
return errors.New("failed to update state")
}
return nil
}

func (t *testClientConn) NewAddress(addrs []resolver.Address) {
t.mu.Lock()
defer t.mu.Unlock()
t.addrs = addrs
}

// This shouldn't be called by our code since we don't support this.
func (t *testClientConn) NewServiceConfig(serviceConfig string) {
assert.Fail(t.t, "unexpected call to NewServiceConfig")
}
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
package yarpc // import "go.uber.org/yarpc"

// Version is the current version of YARPC.
const Version = "1.75.2"
const Version = "1.75.3"

0 comments on commit bc0cd15

Please sign in to comment.