Skip to content

Commit

Permalink
Merge pull request #577 from uber/dev
Browse files Browse the repository at this point in the history
Version 1.3.0
  • Loading branch information
kriskowal authored Feb 2, 2017
2 parents aeda483 + 1fc4d99 commit 7938782
Show file tree
Hide file tree
Showing 18 changed files with 67 additions and 44 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Changelog
=========

# v1.3.0

* Exposes the channel's RootPeerList with `channel.RootPeers()`.
* Support Thrift namespaces for thrift-gen.

# v1.2.3

* Improve error messages when an argument reader is closed without
Expand All @@ -9,7 +14,7 @@ Changelog
but none was found (e.g., exception is from the future). (#566)
* Fix ListenIP selecting docker interfaces over physical networks. (#565)
* Fix for error when a Thrift payload has completed decoding and attempts
to close the argument reader without waiting till EOF. (#564)
to close the argument reader without waiting until EOF. (#564)
* thrift-gen: Fix "namespace go" being ignored even though the Apache thrift
generated code was respecting it. (#559)

Expand Down
18 changes: 14 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ We'd love your help making tchannel-go great!

## Getting Started

TChannel uses [godep](https://github.com/tools/godep) to manage dependencies.
TChannel uses [glide](https://github.com/Masterminds/glide) to manage
dependencies.
To get started:

```bash
go get github.com/uber/tchannel-go
go get github.com/tools/godep
cd $GOPATH/src/github.com/uber/tchannel-go
godep restore
make install_glide
make # tests should pass
```

Expand All @@ -32,3 +31,14 @@ pull request is most likely to be accepted if it:
review comments](https://github.com/golang/go/wiki/CodeReviewComments).
* Has a [good commit
message](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html).

## Cutting a Release

* Send a pull request against dev including:
* update CHANGELOG.md (`scripts/changelog_halp.sh`)
* update version.go
* Send a pull request for dev into master
* `git tag -m v0.0.0 -a v0.0.0`
* `git push origin --tags`
* Copy CHANGELOG.md fragment into release notes on
https://github.com/uber/tchannel-go/releases
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ else
endif

install_glide:
GOPATH=$(OLD_GOPATH) go get -u github.com/Masterminds/glide
# all we want is: GOPATH=$(OLD_GOPATH) go get -u github.com/Masterminds/glide
# but have to pin to 0.12.3 due to https://github.com/Masterminds/glide/issues/745
GOPATH=$(OLD_GOPATH) go get -u github.com/Masterminds/glide && cd $(OLD_GOPATH)/src/github.com/Masterminds/glide && git checkout v0.12.3 && go install

install_ci: install_glide install_lint get_thrift install
GOPATH=$(OLD_GOPATH) go get -u github.com/mattn/goveralls
Expand Down
19 changes: 11 additions & 8 deletions channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ type ChannelOptions struct {
// The name of the process, for logging and reporting to peers
ProcessName string

// OnPeerStatusChanged
OnPeerStatusChanged func(*Peer)

// The logger to use for this channel
Logger Logger

Expand Down Expand Up @@ -363,18 +366,18 @@ func (ch *Channel) Peers() *PeerList {
return ch.peers
}

// rootPeers returns the root PeerList for the channel, which is the sole place
// RootPeers returns the root PeerList for the channel, which is the sole place
// new Peers are created. All children of the root list (including ch.Peers())
// automatically re-use peers from the root list and create new peers in the
// root list.
func (ch *Channel) rootPeers() *RootPeerList {
func (ch *Channel) RootPeers() *RootPeerList {
return ch.peers.parent
}

// BeginCall starts a new call to a remote peer, returning an OutboundCall that can
// be used to write the arguments of the call.
func (ch *Channel) BeginCall(ctx context.Context, hostPort, serviceName, methodName string, callOptions *CallOptions) (*OutboundCall, error) {
p := ch.rootPeers().GetOrAdd(hostPort)
p := ch.RootPeers().GetOrAdd(hostPort)
return p.BeginCall(ctx, serviceName, methodName, callOptions)
}

Expand Down Expand Up @@ -431,7 +434,7 @@ func (ch *Channel) serve() {

// Ping sends a ping message to the given hostPort and waits for a response.
func (ch *Channel) Ping(ctx context.Context, hostPort string) error {
peer := ch.rootPeers().GetOrAdd(hostPort)
peer := ch.RootPeers().GetOrAdd(hostPort)
conn, err := peer.GetConnection(ctx)
if err != nil {
return err
Expand Down Expand Up @@ -524,7 +527,7 @@ func (ch *Channel) exchangeUpdated(c *Connection) {
return
}

p, ok := ch.rootPeers().Get(c.remotePeerInfo.HostPort)
p, ok := ch.RootPeers().Get(c.remotePeerInfo.HostPort)
if !ok {
return
}
Expand Down Expand Up @@ -575,7 +578,7 @@ func (ch *Channel) connectionActive(c *Connection, direction connectionDirection
}

func (ch *Channel) addConnectionToPeer(hostPort string, c *Connection, direction connectionDirection) {
p := ch.rootPeers().GetOrAdd(hostPort)
p := ch.RootPeers().GetOrAdd(hostPort)
if err := p.addConnection(c, direction); err != nil {
c.log.WithFields(
LogField{"remoteHostPort", c.remotePeerInfo.HostPort},
Expand Down Expand Up @@ -620,13 +623,13 @@ func (ch *Channel) getMinConnectionState() connectionState {
// connectionCloseStateChange is called when a connection's close state changes.
func (ch *Channel) connectionCloseStateChange(c *Connection) {
ch.removeClosedConn(c)
if peer, ok := ch.rootPeers().Get(c.remotePeerInfo.HostPort); ok {
if peer, ok := ch.RootPeers().Get(c.remotePeerInfo.HostPort); ok {
peer.connectionCloseStateChange(c)
ch.updatePeer(peer)
}
if c.outboundHP != "" && c.outboundHP != c.remotePeerInfo.HostPort {
// Outbound connections may be in multiple peers.
if peer, ok := ch.rootPeers().Get(c.outboundHP); ok {
if peer, ok := ch.RootPeers().Get(c.outboundHP); ok {
peer.connectionCloseStateChange(c)
ch.updatePeer(peer)
}
Expand Down
2 changes: 1 addition & 1 deletion introspection.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func (ch *Channel) IntrospectState(opts *IntrospectionOptions) *RuntimeState {
CreatedStack: ch.createdStack,
LocalPeer: ch.PeerInfo(),
SubChannels: ch.subChannels.IntrospectState(opts),
RootPeers: ch.rootPeers().IntrospectState(opts),
RootPeers: ch.RootPeers().IntrospectState(opts),
Peers: ch.Peers().IntrospectList(opts),
NumConnections: numConns,
Connections: connIDs,
Expand Down
2 changes: 1 addition & 1 deletion relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func NewRelayer(ch *Channel, conn *Connection) *Relayer {
localHandler: ch.relayLocal,
outbound: newRelayItems(ch.Logger().WithFields(LogField{"relay", "outbound"})),
inbound: newRelayItems(ch.Logger().WithFields(LogField{"relay", "inbound"})),
peers: ch.rootPeers(),
peers: ch.RootPeers(),
conn: conn,
logger: conn.log,
}
Expand Down
4 changes: 2 additions & 2 deletions testutils/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ var (

func checkCacheSize(n int) {
// Start with a reasonably large cache.
if n < 8 {
n = 8
if n < 1024 {
n = 1024
}

randMut.RLock()
Expand Down
8 changes: 4 additions & 4 deletions thrift/thrift-gen/compile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ var (
func TestMain(m *testing.M) {
exitCode := m.Run()

// If we created a fake GOPATH, we should clean it up.
if _testGoPath != "" {
// If we created a fake GOPATH, we should clean it up on success.
if _testGoPath != "" && exitCode == 0 {
os.RemoveAll(_testGoPath)
}

Expand Down Expand Up @@ -193,7 +193,7 @@ func TestExternalTemplate(t *testing.T) {
}

// Verify the contents of the extra file.
outFile := filepath.Join(dir, packageName(templateFile)+"-service_extend.go")
outFile := filepath.Join(dir, defaultPackageName(templateFile)+"-service_extend.go")
return verifyFileContents(outFile, expected)
}
if err := runTest(t, opts, checks); err != nil {
Expand Down Expand Up @@ -301,7 +301,7 @@ func checkDirectoryFiles(dir string, n int) error {

func runBuildTest(t *testing.T, thriftFile string) error {
extraChecks := func(dir string) error {
return checkDirectoryFiles(filepath.Join(dir, packageName(thriftFile)), 4)
return checkDirectoryFiles(filepath.Join(dir, defaultPackageName(thriftFile)), 4)
}

opts := processOptions{InputFile: thriftFile}
Expand Down
1 change: 1 addition & 0 deletions thrift/thrift-gen/extends.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func setExtends(state map[string]parseState) error {
searchFor = s.Extends
} else {
include := v.global.includes[parts[0]]
s.ExtendsPrefix = include.pkg + "."
searchServices = state[include.file].services
searchFor = parts[1]
}
Expand Down
2 changes: 1 addition & 1 deletion thrift/thrift-gen/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func runThrift(inFile string, outDir string) error {
}

// Delete any existing generated code for this Thrift file.
genDir := filepath.Join(outDir, packageName(inFile))
genDir := filepath.Join(outDir, defaultPackageName(inFile))
if err := execCmd("rm", "-rf", genDir); err != nil {
return fmt.Errorf("failed to delete directory %s: %v", genDir, err)
}
Expand Down
20 changes: 9 additions & 11 deletions thrift/thrift-gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func processFile(opts processOptions) error {
}

for filename, v := range allParsed {
pkg := packageName(filename)
pkg := getNamespace(filename, v.ast)

for _, template := range allTemplates {
outputFile := filepath.Join(opts.OutputDir, pkg, template.outputFile(pkg))
Expand Down Expand Up @@ -180,14 +180,19 @@ func parseFile(inputFile string) (map[string]parseState, error) {
return allParsed, setExtends(allParsed)
}

func defaultPackageName(fullPath string) string {
filename := filepath.Base(fullPath)
file := strings.TrimSuffix(filename, filepath.Ext(filename))
return strings.ToLower(file)
}

func getNamespace(filename string, v *parser.Thrift) string {
if ns, ok := v.Namespaces["go"]; ok {
return ns
}

base := filepath.Base(filename)
base = strings.TrimSuffix(base, filepath.Ext(base))
return strings.ToLower(base)
// TODO(prashant): Remove any characters that are not valid in Go package names.
return defaultPackageName(filename)
}

func generateCode(outputFile string, template *Template, pkg string, state parseState) error {
Expand All @@ -212,13 +217,6 @@ func generateCode(outputFile string, template *Template, pkg string, state parse
return template.execute(outputFile, td)
}

func packageName(fullPath string) string {
// TODO(prashant): Remove any characters that are not valid in Go package names.
_, filename := filepath.Split(fullPath)
file := strings.TrimSuffix(filename, filepath.Ext(filename))
return strings.ToLower(file)
}

type stringSliceFlag []string

func (s *stringSliceFlag) String() string {
Expand Down
2 changes: 1 addition & 1 deletion thrift/thrift-gen/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func parseTemplateFile(file string) (*Template, error) {
return nil, fmt.Errorf("failed to parse template in file %q: %v", file, err)
}

return &Template{packageName(file), t}, nil
return &Template{defaultPackageName(file), t}, nil
}

func contextType() string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ namespace go a_shared
include "../b/shared.thrift"

typedef shared.b_string a_string

service AShared extends shared.BShared {
bool healthA()
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
namespace go b_shared

typedef string b_string

service BShared {
bool healthB()
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
include "a/shared.thrift"

service Foo {
service Foo extends shared.AShared {
void Foo(1: shared.a_string str)
}
5 changes: 3 additions & 2 deletions thrift/thrift-gen/wrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ type Service struct {
*parser.Service
state *State

// ExtendsService is not set in wrap, but in setExtends.
// ExtendsService and ExtendsPrefix are set in `setExtends`.
ExtendsService *Service
ExtendsPrefix string

// methods is a cache of all methods.
methods []*Method
Expand Down Expand Up @@ -91,7 +92,7 @@ func (s *Service) HasExtends() bool {
// ExtendsServicePrefix returns a package selector (if any) for the extended service.
func (s *Service) ExtendsServicePrefix() string {
if dotIndex := strings.Index(s.Extends, "."); dotIndex > 0 {
return s.Extends[:dotIndex+1]
return s.ExtendsPrefix
}
return ""
}
Expand Down
5 changes: 0 additions & 5 deletions utils_for_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ import (
// MexChannelBufferSize is the size of the message exchange channel buffer.
const MexChannelBufferSize = mexChannelBufferSize

// RootPeers returns the root peer list from the Channel.
func (ch *Channel) RootPeers() *RootPeerList {
return ch.rootPeers()
}

// SetOnUpdate sets onUpdate for a peer, which is called when the peer's score is
// updated in all peer lists.
func (p *Peer) SetOnUpdate(f func(*Peer)) {
Expand Down
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ package tchannel
// VersionInfo identifies the version of the TChannel library.
// Due to lack of proper package management, this version string will
// be maintained manually.
const VersionInfo = "1.2.3"
const VersionInfo = "1.3.0"

0 comments on commit 7938782

Please sign in to comment.