Skip to content
This repository has been archived by the owner on Feb 18, 2021. It is now read-only.

Commit

Permalink
Fix lint (#167)
Browse files Browse the repository at this point in the history
I fixed all lints and make the lint check to include all files. It takes just a few seconds to lint all files instead of recent commits, so it is not really that bad.
  • Loading branch information
thuningxu authored Apr 22, 2017
1 parent 56214c2 commit 6442730
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 30 deletions.
12 changes: 3 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ ALL_SRC := $(shell find . -name "*.go" | grep -v -e Godeps -e vendor \
-e ".*/_.*" \
-e ".*/mocks.*")

TOUCHED_SRC := $(shell git diff --name-only master | grep "\.go$$" | grep -v -e Godeps -e vendor \
-e ".*/\//*" \
-e ".*/_.*" \
-e ".*/mocks.*")

# all directories with *_test.go files in them
ALL_TEST_DIRS := $(sort $(dir $(filter %_test.go,$(ALL_SRC))))
# all tests other than integration test fall into the pkg_test category
Expand Down Expand Up @@ -130,20 +125,19 @@ clean:
rm -Rf $(BUILD)

lint:
@lintFail=0; for file in $(TOUCHED_SRC); do \
@lintFail=0; for file in $(ALL_SRC); do \
golint -set_exit_status "$$file"; \
if [ $$? -eq 1 ]; then lintFail=1; fi; \
done; \
if [ $$lintFail -eq 1 ]; then exit 1; fi;
@echo gofmt -l $(ALL_SRC)
@OUTPUT=`gofmt -l $(ALL_SRC) 2>&1`; \
if [ "$$OUTPUT" ]; then \
echo "Run 'make fmt'. gofmt must be run on the following files:"; \
echo "$$OUTPUT"; \
exit 1; \
fi
go tool vet -all -printfuncs=Info,Infof,Debug,Debugf,Warn,Warnf,Panic,Panicf $(ALL_TEST_DIRS)
@go tool vet -all -printfuncs=Info,Infof,Debug,Debugf,Warn,Warnf,Panic,Panicf $(ALL_TEST_DIRS)

fmt:
gofmt -w $(ALL_SRC)
@gofmt -w $(ALL_SRC)

2 changes: 1 addition & 1 deletion clients/outputhost/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (s *OutClientImpl) ListLoadedConsumerGroups() (*admin.ListConsumerGroupsRes
return s.client.ListLoadedConsumerGroups(ctx)
}

// ReadCgState
// ReadCgState returns consumer group state inside output host
func (s *OutClientImpl) ReadCgState(req *admin.ReadConsumerGroupStateRequest) (*admin.ReadConsumerGroupStateResult_, error) {
ctx, cancel := tcthrift.NewContext(15 * time.Second)
defer cancel()
Expand Down
2 changes: 1 addition & 1 deletion common/loadreporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ func (s *LoadReporterSuite) TestControllerClientFailure() {
})

mockTokenBucket.On("TryConsume", mock.Anything).Return(true, time.Millisecond)
mockClientFactory.On("GetControllerClient").Return(nil, errors.New("Error getting client."))
mockClientFactory.On("GetControllerClient").Return(nil, errors.New("error getting client"))

factory := NewLoadReporterDaemonFactory("test", controller.SKU_Machine1, controller.Role_IN, mockClientFactory,
newMockTickerFactory(mockTicker), newMockTokenBucketFactory(mockTokenBucket), bark.NewLoggerFromLogrus(log.New()))
Expand Down
10 changes: 5 additions & 5 deletions common/metrics/testreporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ type (
}
)

type HandlerFn func(metricName string, baseTags, tags map[string]string, value int64)
type handlerFn func(metricName string, baseTags, tags map[string]string, value int64)

var handlers = make(map[string]map[string]HandlerFn) // Key1 - metricName; Key2 - "filterTag:filterVal"
var handlers = make(map[string]map[string]handlerFn) // Key1 - metricName; Key2 - "filterTag:filterVal"
var handlerMutex sync.RWMutex

// NewTestReporter create an instance of Reporter which can be used for driver to emit metric to console
Expand Down Expand Up @@ -124,7 +124,7 @@ func (r *TestReporter) executeHandler(name string, tags map[string]string, value
handlerMutex.RUnlock()
}

// Register a handler (closure) that receives updates for a particular guage or counter based on the metric name and
// RegisterHandler registers a handler (closure) that receives updates for a particular guage or counter based on the metric name and
// the name/value of one of the metric's tags. If the filterTag/Val are both empty, all updates to that metric will
// trigger the handler. If metricName is empty, all metrics matching the tag filter will pass through your function.
// A nil handler unregisters the handler for the given filter parameters
Expand All @@ -134,11 +134,11 @@ func (r *TestReporter) executeHandler(name string, tags map[string]string, value
// * Your handler can be called concurrently. Capture your own sync.Mutex if you must serialize
// * Counters report the delta; you must maintain the cumulative value of your counter if it is important
// * Your handler executes synchronously with the metrics code; DO NOT BLOCK
func RegisterHandler(metricName, filterTag, filterTagVal string, handler HandlerFn) {
func RegisterHandler(metricName, filterTag, filterTagVal string, handler handlerFn) {
defer handlerMutex.Unlock()
handlerMutex.Lock()
if _, ok := handlers[metricName]; !ok {
handlers[metricName] = make(map[string]HandlerFn)
handlers[metricName] = make(map[string]handlerFn)
}

key2 := filterTag + `:` + filterTagVal
Expand Down
8 changes: 4 additions & 4 deletions services/inputhost/load/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ const (
DstMetricMsgsIn
// DstMetricBytesIn represents count of incoming bytes per dst
DstMetricBytesIn
// DstMetricsNumAcks represents count of number of acked messages per dst
// DstMetricNumAcks represents count of number of acked messages per dst
DstMetricNumAcks
// DstMetricsNumNacks represents count of number of nacked messages per dst
// DstMetricNumNacks represents count of number of nacked messages per dst
DstMetricNumNacks
// DstMetricsNumThrottled represents count of number of throttled messages per dst
// DstMetricNumThrottled represents count of number of throttled messages per dst
DstMetricNumThrottled
// DstMetricsNumFailed represents count of number of failed messages per dst
// DstMetricNumFailed represents count of number of failed messages per dst
DstMetricNumFailed
// DstMetricOverallNumMsgs represents count of the overall number of messages per dst
// Note: this is different than the MsgsIn above since that maintains the per second msgs
Expand Down
2 changes: 1 addition & 1 deletion services/outputhost/cgcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ func (cgCache *consumerGroupCache) loadExtentCache(ctx thrift.Context, destType
&extCache.kafkaClient,
)
} else {
committer = NewCheramiCommitter(
committer = newCheramiCommitter(
cgCache.metaClient,
cgCache.outputHostUUID,
cgCache.cachedCGDesc.GetConsumerGroupUUID(),
Expand Down
9 changes: 4 additions & 5 deletions services/outputhost/cheramiCommitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
package outputhost

import (
"errors"
"fmt"
"sync"
"time"
Expand Down Expand Up @@ -127,8 +126,8 @@ func (c *cheramiCommitter) GetCommitLevel() (l CommitterLevel) {
* Setup & Utility
*/

// NewCheramiCommitter instantiates a cheramiCommitter
func NewCheramiCommitter(metaclient metadata.TChanMetadataService,
// newCheramiCommitter instantiates a cheramiCommitter
func newCheramiCommitter(metaclient metadata.TChanMetadataService,
outputHostUUID string,
cgUUID string,
extUUID string,
Expand All @@ -152,7 +151,7 @@ func (c *cheramiCommitter) SetAckOffsetInRemote(setAckLevelRequest *shared.SetAc
// send to local replicator to fan out
localReplicator, err := c.tClients.GetReplicatorClient()
if err != nil {
return errors.New(fmt.Sprintf("SetAckOffsetInRemote: GetReplicatorClient failed: %#v", err))
return fmt.Errorf("SetAckOffsetInRemote: GetReplicatorClient failed: %#v", err)
}

// empty the output host and store uuid as these apply to local zone only
Expand All @@ -163,7 +162,7 @@ func (c *cheramiCommitter) SetAckOffsetInRemote(setAckLevelRequest *shared.SetAc
defer cancel()
err = localReplicator.SetAckOffsetInRemote(ctx, setAckLevelRequest)
if err != nil {
return errors.New(fmt.Sprintf("SetAckOffsetInRemote: SetAckOffsetInRemote failed from replicator: %#v", err))
return fmt.Errorf("SetAckOffsetInRemote: SetAckOffsetInRemote failed from replicator: %#v", err)
}
return nil
}
2 changes: 2 additions & 0 deletions services/replicator/replicator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,7 @@ func (r *Replicator) createCgExtentRemoteCall(zone string, logger bark.Logger, c
return nil
}

// SetAckOffset updates ack offsets in local zone
func (r *Replicator) SetAckOffset(ctx thrift.Context, request *shared.SetAckOffsetRequest) error {
lcllg := r.logger.WithFields(bark.Fields{
common.TagCnsm: common.FmtDst(request.GetConsumerGroupUUID()),
Expand All @@ -1067,6 +1068,7 @@ func (r *Replicator) SetAckOffset(ctx thrift.Context, request *shared.SetAckOffs
return nil
}

// SetAckOffsetInRemote updates ack offsets in remote zone
func (r *Replicator) SetAckOffsetInRemote(ctx thrift.Context, request *shared.SetAckOffsetRequest) error {
r.m3Client.IncCounter(metrics.ReplicatorSetAckOffsetInRemoteScope, metrics.ReplicatorRequests)

Expand Down
2 changes: 1 addition & 1 deletion services/storehost/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ func (t *outputhostStreamMock) Write(msg *store.ReadMessageContent) error {
for i := range data {
if data[i] != byte(r.Intn(256)) {
t.Lock()
t.err = fmt.Errorf("corrupt (seqNum: %x): data[%d]\n", appMsg.GetSequenceNumber(), i)
t.err = fmt.Errorf("corrupt (seqNum: %x): data[%d]", appMsg.GetSequenceNumber(), i)
fmt.Printf("message corrupt (addr: %x seq: %x): data[%d]\n", msg.GetMessage().GetAddress(), appMsg.GetSequenceNumber(), i)
t.Unlock()
break
Expand Down
3 changes: 3 additions & 0 deletions services/storehost/extMgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
)

type (
// ExtentCallbacks is an interface for any objects want to subscribe to extent events
ExtentCallbacks interface {

// ExtentInit defines the callback function called when a new extent context
Expand Down Expand Up @@ -523,12 +524,14 @@ func (xMgr *ExtentManager) IsExtentOpenedForReplication(extentID string) bool {
return false
}

// RegisterCallbacks registers a subscriber
func (xMgr *ExtentManager) RegisterCallbacks(callbacks ExtentCallbacks) {

// add to list of callback objects
xMgr.callbacks = append(xMgr.callbacks, callbacks)
}

// CallbackDone decrement callback ref count
func (xMgr *ExtentManager) CallbackDone(ext *extentContext) {

// decrement callback-ref; if that drops to zero, call in
Expand Down
6 changes: 5 additions & 1 deletion services/storehost/extStats.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const (
)

type (
// ExtStatsReporter reports extent stats to metadata
ExtStatsReporter struct {
hostID string
xMgr *ExtentManager
Expand Down Expand Up @@ -79,7 +80,7 @@ type (
// the following globals and their methods are
var (
reportInterval atomic.Value
extStatsReporterPaused int32 = 0
extStatsReporterPaused int32
)

func init() {
Expand Down Expand Up @@ -112,6 +113,7 @@ func (t *report) String() string {
t.extentID, t.firstSeqNum, t.firstAddress, t.firstTimestamp, t.lastSeqNum, t.lastAddress, t.lastTimestamp)
}

// NewExtStatsReporter is the constructor for ExtStatsReporter
func NewExtStatsReporter(hostID string, xMgr *ExtentManager, mClient metadata.TChanMetadataService, logger bark.Logger) *ExtStatsReporter {

return &ExtStatsReporter{
Expand All @@ -130,6 +132,7 @@ func NewExtStatsReporter(hostID string, xMgr *ExtentManager, mClient metadata.TC
}
}

// Start registers callbacks, and kicks off reporter pump and scheduler pump
func (t *ExtStatsReporter) Start() {

t.logger.Info("extStatsReporter: started")
Expand All @@ -144,6 +147,7 @@ func (t *ExtStatsReporter) Start() {
go t.schedulerPump()
}

// Stop stops periodic pumps for ExtStatsReporter
func (t *ExtStatsReporter) Stop() {

close(t.stopC)
Expand Down
7 changes: 5 additions & 2 deletions services/storehost/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@ import (
)

const (
SeqnumInvalid = int64(math.MaxInt64)
// SeqnumInvalid designates an invalid or unknown sequence number
SeqnumInvalid = int64(math.MaxInt64)
// TimestampInvalid designates an invalid or unknown timestamp
TimestampInvalid = int64(math.MaxInt64)
AddressInvalid = int64(math.MaxInt64)
// AddressInvalid designates an invalid or unknown address
AddressInvalid = int64(math.MaxInt64)
)

// -- wrappers to create various error blobs -- //
Expand Down

0 comments on commit 6442730

Please sign in to comment.