Skip to content

Commit

Permalink
Vendor apache thrift due to build incompatibility >= 0.10.0 (uber-go#104
Browse files Browse the repository at this point in the history
)

* Vendor apache thrift due to build incompatibilities between 0.11.0 and 0.12.0
* Vendor 0.10.0 without dependencies on context
* Fix lint
* Rename vendored files to thirdparty
  • Loading branch information
robskillington authored and mway committed Jun 17, 2019
1 parent 24c699f commit f266f90
Show file tree
Hide file tree
Showing 74 changed files with 10,758 additions and 31 deletions.
11 changes: 6 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ export GO15VENDOREXPERIMENT=1
BENCH_FLAGS ?= -cpuprofile=cpu.pprof -memprofile=mem.pprof -benchmem
PKGS ?= $(shell glide novendor)
PKG_FILES ?= *.go example/*.go m3
LINT_IGNORE = m3/thrift
LINT_IGNORE = m3/thrift\|thirdparty
LICENSE_IGNORE = thirdparty

.PHONY: all
all: lint test
Expand All @@ -23,15 +24,15 @@ dependencies:
lint:
@rm -rf lint.log
@echo "Checking formatting..."
@gofmt -d -s $(PKG_FILES) 2>&1 | grep -v $(LINT_IGNORE) | tee lint.log
@gofmt -d -s $(PKG_FILES) 2>&1 | grep -v '$(LINT_IGNORE)' | tee lint.log
@echo "Installing test dependencies for vet..."
@go test -i $(PKGS)
@echo "Checking lint..."
@$(foreach dir,$(PKGS),golint $(dir) 2>&1 | grep -v $(LINT_IGNORE) | tee -a lint.log;)
@$(foreach dir,$(PKGS),golint $(dir) 2>&1 | grep -v '$(LINT_IGNORE)' | tee -a lint.log;)
@echo "Checking for unresolved FIXMEs..."
@git grep -i fixme | grep -v -e vendor -e Makefile | grep -v $(LINT_IGNORE) | tee -a lint.log
@git grep -i fixme | grep -v -e vendor -e Makefile | grep -v '$(LINT_IGNORE)' | tee -a lint.log
@echo "Checking for license headers..."
@./check_license.sh | tee -a lint.log
@./check_license.sh | grep -v '$(LICENSE_IGNORE)' | tee -a lint.log
@[ ! -s lint.log ]

.PHONY: test
Expand Down
4 changes: 0 additions & 4 deletions glide.lock

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

4 changes: 0 additions & 4 deletions glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ import:
version: ^0.1.0
- package: github.com/m3db/prometheus_procfs
version: ^0.8.1
- package: github.com/apache/thrift
version: '>=0.9.3, <0.11.0'
subpackages:
- lib/go/thrift
- package: go.uber.org/atomic
version: ^1
testImport:
Expand Down
2 changes: 1 addition & 1 deletion m3/customtransports/buffered_read_transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ package customtransport
import (
"bytes"

"github.com/apache/thrift/lib/go/thrift"
"github.com/uber-go/tally/thirdparty/github.com/apache/thrift/lib/go/thrift"
)

// TBufferedReadTransport is a thrift.TTransport that reads from a buffer
Expand Down
3 changes: 1 addition & 2 deletions m3/example/local_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ import (
"github.com/uber-go/tally/m3"
customtransport "github.com/uber-go/tally/m3/customtransports"
m3thrift "github.com/uber-go/tally/m3/thrift"

"github.com/apache/thrift/lib/go/thrift"
"github.com/uber-go/tally/thirdparty/github.com/apache/thrift/lib/go/thrift"
)

type batchCallback func(batch *m3thrift.MetricBatch)
Expand Down
5 changes: 2 additions & 3 deletions m3/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@ import (
"time"

"github.com/uber-go/tally"
"github.com/uber-go/tally/m3/customtransports"
customtransport "github.com/uber-go/tally/m3/customtransports"
m3thrift "github.com/uber-go/tally/m3/thrift"
"github.com/uber-go/tally/m3/thriftudp"

"github.com/apache/thrift/lib/go/thrift"
"github.com/uber-go/tally/thirdparty/github.com/apache/thrift/lib/go/thrift"
)

// Protocol describes a M3 thrift transport protocol.
Expand Down
4 changes: 2 additions & 2 deletions m3/reporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ import (
"time"

"github.com/uber-go/tally"
"github.com/uber-go/tally/m3/customtransports"
customtransport "github.com/uber-go/tally/m3/customtransports"
m3thrift "github.com/uber-go/tally/m3/thrift"
"github.com/uber-go/tally/m3/thriftudp"
"github.com/uber-go/tally/thirdparty/github.com/apache/thrift/lib/go/thrift"

"github.com/apache/thrift/lib/go/thrift"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down
5 changes: 2 additions & 3 deletions m3/resource_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ package m3

import (
"github.com/uber-go/tally"
"github.com/uber-go/tally/m3/customtransports"
customtransport "github.com/uber-go/tally/m3/customtransports"
m3thrift "github.com/uber-go/tally/m3/thrift"

"github.com/apache/thrift/lib/go/thrift"
"github.com/uber-go/tally/thirdparty/github.com/apache/thrift/lib/go/thrift"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion m3/resource_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (
"testing"

m3thrift "github.com/uber-go/tally/m3/thrift"
"github.com/uber-go/tally/thirdparty/github.com/apache/thrift/lib/go/thrift"

"github.com/apache/thrift/lib/go/thrift"
"github.com/stretchr/testify/require"
)

Expand Down
3 changes: 2 additions & 1 deletion m3/thrift/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ package m3
import (
"bytes"
"fmt"
"github.com/apache/thrift/lib/go/thrift"

"github.com/uber-go/tally/thirdparty/github.com/apache/thrift/lib/go/thrift"
)

// (needed to ensure safety because of naive import list construction.)
Expand Down
3 changes: 2 additions & 1 deletion m3/thrift/m3.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ package m3
import (
"bytes"
"fmt"
"github.com/apache/thrift/lib/go/thrift"

"github.com/uber-go/tally/thirdparty/github.com/apache/thrift/lib/go/thrift"
)

// (needed to ensure safety because of naive import list construction.)
Expand Down
3 changes: 2 additions & 1 deletion m3/thrift/ttypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ package m3
import (
"bytes"
"fmt"
"github.com/apache/thrift/lib/go/thrift"

"github.com/uber-go/tally/thirdparty/github.com/apache/thrift/lib/go/thrift"
)

// (needed to ensure safety because of naive import list construction.)
Expand Down
2 changes: 1 addition & 1 deletion m3/thriftudp/multitransport.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ package thriftudp
import (
"fmt"

"github.com/apache/thrift/lib/go/thrift"
"github.com/uber-go/tally/thirdparty/github.com/apache/thrift/lib/go/thrift"
)

// TMultiUDPTransport does multiUDP as a thrift.TTransport
Expand Down
2 changes: 1 addition & 1 deletion m3/thriftudp/multitransport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"fmt"
"testing"

"github.com/apache/thrift/lib/go/thrift"
"github.com/uber-go/tally/thirdparty/github.com/apache/thrift/lib/go/thrift"

"github.com/stretchr/testify/assert"
)
Expand Down
3 changes: 2 additions & 1 deletion m3/thriftudp/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import (
"bytes"
"net"

"github.com/apache/thrift/lib/go/thrift"
"github.com/uber-go/tally/thirdparty/github.com/apache/thrift/lib/go/thrift"

"go.uber.org/atomic"
)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 thrift

const (
UNKNOWN_APPLICATION_EXCEPTION = 0
UNKNOWN_METHOD = 1
INVALID_MESSAGE_TYPE_EXCEPTION = 2
WRONG_METHOD_NAME = 3
BAD_SEQUENCE_ID = 4
MISSING_RESULT = 5
INTERNAL_ERROR = 6
PROTOCOL_ERROR = 7
)

// Application level Thrift exception
type TApplicationException interface {
TException
TypeId() int32
Read(iprot TProtocol) (TApplicationException, error)
Write(oprot TProtocol) error
}

type tApplicationException struct {
message string
type_ int32
}

func (e tApplicationException) Error() string {
return e.message
}

func NewTApplicationException(type_ int32, message string) TApplicationException {
return &tApplicationException{message, type_}
}

func (p *tApplicationException) TypeId() int32 {
return p.type_
}

func (p *tApplicationException) Read(iprot TProtocol) (TApplicationException, error) {
_, err := iprot.ReadStructBegin()
if err != nil {
return nil, err
}

message := ""
type_ := int32(UNKNOWN_APPLICATION_EXCEPTION)

for {
_, ttype, id, err := iprot.ReadFieldBegin()
if err != nil {
return nil, err
}
if ttype == STOP {
break
}
switch id {
case 1:
if ttype == STRING {
if message, err = iprot.ReadString(); err != nil {
return nil, err
}
} else {
if err = SkipDefaultDepth(iprot, ttype); err != nil {
return nil, err
}
}
case 2:
if ttype == I32 {
if type_, err = iprot.ReadI32(); err != nil {
return nil, err
}
} else {
if err = SkipDefaultDepth(iprot, ttype); err != nil {
return nil, err
}
}
default:
if err = SkipDefaultDepth(iprot, ttype); err != nil {
return nil, err
}
}
if err = iprot.ReadFieldEnd(); err != nil {
return nil, err
}
}
return NewTApplicationException(type_, message), iprot.ReadStructEnd()
}

func (p *tApplicationException) Write(oprot TProtocol) (err error) {
err = oprot.WriteStructBegin("TApplicationException")
if len(p.Error()) > 0 {
err = oprot.WriteFieldBegin("message", STRING, 1)
if err != nil {
return
}
err = oprot.WriteString(p.Error())
if err != nil {
return
}
err = oprot.WriteFieldEnd()
if err != nil {
return
}
}
err = oprot.WriteFieldBegin("type", I32, 2)
if err != nil {
return
}
err = oprot.WriteI32(p.type_)
if err != nil {
return
}
err = oprot.WriteFieldEnd()
if err != nil {
return
}
err = oprot.WriteFieldStop()
if err != nil {
return
}
err = oprot.WriteStructEnd()
return
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 thrift

import (
"testing"
)

func TestTApplicationException(t *testing.T) {
exc := NewTApplicationException(UNKNOWN_APPLICATION_EXCEPTION, "")
if exc.Error() != "" {
t.Fatalf("Expected empty string for exception but found '%s'", exc.Error())
}
if exc.TypeId() != UNKNOWN_APPLICATION_EXCEPTION {
t.Fatalf("Expected type UNKNOWN for exception but found '%v'", exc.TypeId())
}
exc = NewTApplicationException(WRONG_METHOD_NAME, "junk_method")
if exc.Error() != "junk_method" {
t.Fatalf("Expected 'junk_method' for exception but found '%s'", exc.Error())
}
if exc.TypeId() != WRONG_METHOD_NAME {
t.Fatalf("Expected type WRONG_METHOD_NAME for exception but found '%v'", exc.TypeId())
}
}
Loading

0 comments on commit f266f90

Please sign in to comment.