Repository: incubator-htrace Updated Branches: refs/heads/master 26518585d -> 2df858aef
run "go fmt" on go code Project: http://git-wip-us.apache.org/repos/asf/incubator-htrace/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-htrace/commit/2df858ae Tree: http://git-wip-us.apache.org/repos/asf/incubator-htrace/tree/2df858ae Diff: http://git-wip-us.apache.org/repos/asf/incubator-htrace/diff/2df858ae Branch: refs/heads/master Commit: 2df858aef5d847fb7e0ce57c549b9736bf04cc73 Parents: 2651858 Author: Colin P. Mccabe <[email protected]> Authored: Sat Nov 21 13:32:19 2015 -0800 Committer: Colin P. Mccabe <[email protected]> Committed: Sat Nov 21 13:32:19 2015 -0800 ---------------------------------------------------------------------- .../go/src/org/apache/htrace/client/hclient.go | 6 +- .../go/src/org/apache/htrace/common/log.go | 6 +- .../go/src/org/apache/htrace/common/process.go | 4 +- .../go/src/org/apache/htrace/common/rpc.go | 6 +- .../src/org/apache/htrace/common/semaphore.go | 14 ++-- .../go/src/org/apache/htrace/conf/config.go | 2 +- .../src/org/apache/htrace/conf/config_keys.go | 26 ++++---- .../org/apache/htrace/htraced/client_test.go | 40 ++++++------ .../src/org/apache/htrace/htraced/datastore.go | 68 ++++++++++---------- .../org/apache/htrace/htraced/datastore_test.go | 8 +-- .../go/src/org/apache/htrace/htraced/hrpc.go | 40 ++++++------ .../go/src/org/apache/htrace/htraced/metrics.go | 24 +++---- .../org/apache/htrace/htraced/metrics_test.go | 10 +-- .../org/apache/htrace/htraced/reaper_test.go | 4 +- .../go/src/org/apache/htrace/htraced/rest.go | 8 +-- .../org/apache/htrace/htracedTool/queries.go | 2 +- .../org/apache/htrace/htracedTool/query_test.go | 60 ++++++++--------- 17 files changed, 164 insertions(+), 164 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/2df858ae/htrace-htraced/go/src/org/apache/htrace/client/hclient.go ---------------------------------------------------------------------- diff --git a/htrace-htraced/go/src/org/apache/htrace/client/hclient.go b/htrace-htraced/go/src/org/apache/htrace/client/hclient.go index ef79deb..2fcd9a0 100644 --- a/htrace-htraced/go/src/org/apache/htrace/client/hclient.go +++ b/htrace-htraced/go/src/org/apache/htrace/client/hclient.go @@ -36,8 +36,8 @@ type hClient struct { } type HrpcClientCodec struct { - rwc io.ReadWriteCloser - length uint32 + rwc io.ReadWriteCloser + length uint32 testHooks *TestHooks } @@ -148,7 +148,7 @@ func newHClient(hrpcAddr string, testHooks *TestHooks) (*hClient, error) { "at %s: %s", hrpcAddr, err.Error())) } hcr.rpcClient = rpc.NewClientWithCodec(&HrpcClientCodec{ - rwc: conn, + rwc: conn, testHooks: testHooks, }) return &hcr, nil http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/2df858ae/htrace-htraced/go/src/org/apache/htrace/common/log.go ---------------------------------------------------------------------- diff --git a/htrace-htraced/go/src/org/apache/htrace/common/log.go b/htrace-htraced/go/src/org/apache/htrace/common/log.go index 8a26507..5697d18 100644 --- a/htrace-htraced/go/src/org/apache/htrace/common/log.go +++ b/htrace-htraced/go/src/org/apache/htrace/common/log.go @@ -314,13 +314,13 @@ func (lg *Logger) Close() { // to log things that come out of the go HTTP server and other standard library // systems. type WrappedLogger struct { - lg *Logger + lg *Logger level Level } func (lg *Logger) Wrap(prefix string, level Level) *log.Logger { - wlg := &WrappedLogger { - lg: lg, + wlg := &WrappedLogger{ + lg: lg, level: level, } return log.New(wlg, prefix, 0) http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/2df858ae/htrace-htraced/go/src/org/apache/htrace/common/process.go ---------------------------------------------------------------------- diff --git a/htrace-htraced/go/src/org/apache/htrace/common/process.go b/htrace-htraced/go/src/org/apache/htrace/common/process.go index dbe9b93..ce32067 100644 --- a/htrace-htraced/go/src/org/apache/htrace/common/process.go +++ b/htrace-htraced/go/src/org/apache/htrace/common/process.go @@ -56,7 +56,7 @@ func InstallSignalHandlers(cnf *conf.Config) { sigQuitChan := make(chan os.Signal, 1) signal.Notify(sigQuitChan, syscall.SIGQUIT) go func() { - stackTraceBuf := make([]byte, 1 << 20) + stackTraceBuf := make([]byte, 1<<20) for { <-sigQuitChan GetStackTraces(&stackTraceBuf) @@ -74,7 +74,7 @@ func InstallSignalHandlers(cnf *conf.Config) { func GetStackTraces(buf *[]byte) { *buf = (*buf)[0:cap(*buf)] neededBytes := runtime.Stack(*buf, true) - for ;neededBytes > len(*buf); { + for neededBytes > len(*buf) { *buf = make([]byte, neededBytes) runtime.Stack(*buf, true) } http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/2df858ae/htrace-htraced/go/src/org/apache/htrace/common/rpc.go ---------------------------------------------------------------------- diff --git a/htrace-htraced/go/src/org/apache/htrace/common/rpc.go b/htrace-htraced/go/src/org/apache/htrace/common/rpc.go index 8028cc6..2ec5fe9 100644 --- a/htrace-htraced/go/src/org/apache/htrace/common/rpc.go +++ b/htrace-htraced/go/src/org/apache/htrace/common/rpc.go @@ -38,9 +38,9 @@ const MAX_HRPC_BODY_LENGTH = 64 * 1024 * 1024 // A request to write spans to htraced. type WriteSpansReq struct { - Addr string `json:",omitempty"` // This gets filled in by the RPC layer. - DefaultTrid string `json:",omitempty"` - Spans []*Span + Addr string `json:",omitempty"` // This gets filled in by the RPC layer. + DefaultTrid string `json:",omitempty"` + Spans []*Span } // Info returned by /server/version http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/2df858ae/htrace-htraced/go/src/org/apache/htrace/common/semaphore.go ---------------------------------------------------------------------- diff --git a/htrace-htraced/go/src/org/apache/htrace/common/semaphore.go b/htrace-htraced/go/src/org/apache/htrace/common/semaphore.go index 1d56ae9..1acde76 100644 --- a/htrace-htraced/go/src/org/apache/htrace/common/semaphore.go +++ b/htrace-htraced/go/src/org/apache/htrace/common/semaphore.go @@ -25,16 +25,16 @@ import ( // A simple lock-and-condition-variable based semaphore implementation. type Semaphore struct { - lock sync.Mutex - cond *sync.Cond + lock sync.Mutex + cond *sync.Cond count int64 } func NewSemaphore(count int64) *Semaphore { - sem := &Semaphore { - count:int64(count), + sem := &Semaphore{ + count: int64(count), } - sem.cond = &sync.Cond { + sem.cond = &sync.Cond{ L: &sem.lock, } return sem @@ -51,7 +51,7 @@ func (sem *Semaphore) Post() { func (sem *Semaphore) Posts(amt int64) { sem.lock.Lock() - sem.count+=amt + sem.count += amt if sem.count > 0 { sem.cond.Broadcast() } @@ -72,7 +72,7 @@ func (sem *Semaphore) Wait() { func (sem *Semaphore) Waits(amt int64) { var i int64 - for i=0; i<amt; i++ { + for i = 0; i < amt; i++ { sem.Wait() } } http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/2df858ae/htrace-htraced/go/src/org/apache/htrace/conf/config.go ---------------------------------------------------------------------- diff --git a/htrace-htraced/go/src/org/apache/htrace/conf/config.go b/htrace-htraced/go/src/org/apache/htrace/conf/config.go index 0ce69a8..cb1d8b4 100644 --- a/htrace-htraced/go/src/org/apache/htrace/conf/config.go +++ b/htrace-htraced/go/src/org/apache/htrace/conf/config.go @@ -199,7 +199,7 @@ func (bld *Builder) Build() (*Config, error) { func (bld *Builder) removeApplicationPrefixes(in map[string]string) map[string]string { out := make(map[string]string) - for k, v := range(in) { + for k, v := range in { if strings.HasPrefix(k, bld.AppPrefix) { out[k[len(bld.AppPrefix):]] = v } else { http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/2df858ae/htrace-htraced/go/src/org/apache/htrace/conf/config_keys.go ---------------------------------------------------------------------- diff --git a/htrace-htraced/go/src/org/apache/htrace/conf/config_keys.go b/htrace-htraced/go/src/org/apache/htrace/conf/config_keys.go index 573ce21..10204cd 100644 --- a/htrace-htraced/go/src/org/apache/htrace/conf/config_keys.go +++ b/htrace-htraced/go/src/org/apache/htrace/conf/config_keys.go @@ -102,24 +102,24 @@ var DEFAULTS = map[string]string{ HTRACE_HRPC_ADDRESS: fmt.Sprintf("0.0.0.0:%d", HTRACE_HRPC_ADDRESS_DEFAULT_PORT), HTRACE_DATA_STORE_DIRECTORIES: PATH_SEP + "tmp" + PATH_SEP + "htrace1" + PATH_LIST_SEP + PATH_SEP + "tmp" + PATH_SEP + "htrace2", - HTRACE_DATA_STORE_CLEAR: "false", - HTRACE_DATA_STORE_SPAN_BUFFER_SIZE: "100", - HTRACE_LOG_PATH: "", - HTRACE_LOG_LEVEL: "INFO", + HTRACE_DATA_STORE_CLEAR: "false", + HTRACE_DATA_STORE_SPAN_BUFFER_SIZE: "100", + HTRACE_LOG_PATH: "", + HTRACE_LOG_LEVEL: "INFO", HTRACE_DATASTORE_HEARTBEAT_PERIOD_MS: fmt.Sprintf("%d", 45*1000), - HTRACE_METRICS_MAX_ADDR_ENTRIES: "100000", - HTRACE_SPAN_EXPIRY_MS: "0", - HTRACE_REAPER_HEARTBEAT_PERIOD_MS: fmt.Sprintf("%d", 90*1000), - HTRACE_NUM_HRPC_HANDLERS: "20", - HTRACE_HRPC_IO_TIMEOUT_MS: "60000", + HTRACE_METRICS_MAX_ADDR_ENTRIES: "100000", + HTRACE_SPAN_EXPIRY_MS: "0", + HTRACE_REAPER_HEARTBEAT_PERIOD_MS: fmt.Sprintf("%d", 90*1000), + HTRACE_NUM_HRPC_HANDLERS: "20", + HTRACE_HRPC_IO_TIMEOUT_MS: "60000", } // Values to be used when creating test configurations func TEST_VALUES() map[string]string { return map[string]string{ - HTRACE_HRPC_ADDRESS: ":0", // use a random port for the HRPC server - HTRACE_LOG_LEVEL: "TRACE", // show all log messages in tests - HTRACE_WEB_ADDRESS: ":0", // use a random port for the REST server - HTRACE_SPAN_EXPIRY_MS:"0", // never time out spans (unless testing the reaper) + HTRACE_HRPC_ADDRESS: ":0", // use a random port for the HRPC server + HTRACE_LOG_LEVEL: "TRACE", // show all log messages in tests + HTRACE_WEB_ADDRESS: ":0", // use a random port for the REST server + HTRACE_SPAN_EXPIRY_MS: "0", // never time out spans (unless testing the reaper) } } http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/2df858ae/htrace-htraced/go/src/org/apache/htrace/htraced/client_test.go ---------------------------------------------------------------------- diff --git a/htrace-htraced/go/src/org/apache/htrace/htraced/client_test.go b/htrace-htraced/go/src/org/apache/htrace/htraced/client_test.go index 36e8369..3a877f6 100644 --- a/htrace-htraced/go/src/org/apache/htrace/htraced/client_test.go +++ b/htrace-htraced/go/src/org/apache/htrace/htraced/client_test.go @@ -24,15 +24,15 @@ import ( "github.com/ugorji/go/codec" "math" "math/rand" + htrace "org/apache/htrace/client" "org/apache/htrace/common" "org/apache/htrace/conf" "org/apache/htrace/test" "sort" - "testing" - "time" "sync" "sync/atomic" - htrace "org/apache/htrace/client" + "testing" + "time" ) func TestClientGetServerVersion(t *testing.T) { @@ -94,7 +94,7 @@ func createRandomTestSpans(amount int) common.SpanSlice { func TestClientOperations(t *testing.T) { htraceBld := &MiniHTracedBuilder{Name: "TestClientOperations", - DataDirs: make([]string, 2), + DataDirs: make([]string, 2), WrittenSpans: common.NewSemaphore(0), } ht, err := htraceBld.Build() @@ -121,7 +121,7 @@ func TestClientOperations(t *testing.T) { t.Fatalf("WriteSpans(0:%d) failed: %s\n", NUM_TEST_SPANS/2, err.Error()) } - ht.Store.WrittenSpans.Waits(int64(NUM_TEST_SPANS/2)) + ht.Store.WrittenSpans.Waits(int64(NUM_TEST_SPANS / 2)) // Look up the first half of the spans. They should be found. var span *common.Span @@ -188,7 +188,7 @@ func TestClientOperations(t *testing.T) { func TestDumpAll(t *testing.T) { htraceBld := &MiniHTracedBuilder{Name: "TestDumpAll", - DataDirs: make([]string, 2), + DataDirs: make([]string, 2), WrittenSpans: common.NewSemaphore(0), Cnf: map[string]string{ conf.HTRACE_LOG_LEVEL: "INFO", @@ -287,19 +287,19 @@ func TestHrpcAdmissionsControl(t *testing.T) { var wg sync.WaitGroup wg.Add(TEST_NUM_WRITESPANS) var numConcurrentHrpcCalls int32 - testHooks := &hrpcTestHooks { + testHooks := &hrpcTestHooks{ HandleAdmission: func() { defer wg.Done() n := atomic.AddInt32(&numConcurrentHrpcCalls, 1) if n > TEST_NUM_HRPC_HANDLERS { - t.Fatalf("The number of concurrent HRPC calls went above " + + t.Fatalf("The number of concurrent HRPC calls went above "+ "%d: it's at %d\n", TEST_NUM_HRPC_HANDLERS, n) } time.Sleep(1 * time.Millisecond) n = atomic.AddInt32(&numConcurrentHrpcCalls, -1) if n >= TEST_NUM_HRPC_HANDLERS { - t.Fatalf("The number of concurrent HRPC calls went above " + - "%d: it was at %d\n", TEST_NUM_HRPC_HANDLERS, n + 1) + t.Fatalf("The number of concurrent HRPC calls went above "+ + "%d: it was at %d\n", TEST_NUM_HRPC_HANDLERS, n+1) } }, } @@ -308,7 +308,7 @@ func TestHrpcAdmissionsControl(t *testing.T) { Cnf: map[string]string{ conf.HTRACE_NUM_HRPC_HANDLERS: fmt.Sprintf("%d", TEST_NUM_HRPC_HANDLERS), }, - WrittenSpans: common.NewSemaphore(0), + WrittenSpans: common.NewSemaphore(0), HrpcTestHooks: testHooks, } ht, err := htraceBld.Build() @@ -326,7 +326,7 @@ func TestHrpcAdmissionsControl(t *testing.T) { for iter := 0; iter < TEST_NUM_WRITESPANS; iter++ { go func(i int) { err = hcl.WriteSpans(&common.WriteSpansReq{ - Spans: allSpans[i:i+1], + Spans: allSpans[i : i+1], }) if err != nil { t.Fatalf("WriteSpans failed: %s\n", err.Error()) @@ -342,7 +342,7 @@ func TestHrpcIoTimeout(t *testing.T) { htraceBld := &MiniHTracedBuilder{Name: "TestHrpcIoTimeout", DataDirs: make([]string, 2), Cnf: map[string]string{ - conf.HTRACE_NUM_HRPC_HANDLERS: fmt.Sprintf("%d", TEST_NUM_HRPC_HANDLERS), + conf.HTRACE_NUM_HRPC_HANDLERS: fmt.Sprintf("%d", TEST_NUM_HRPC_HANDLERS), conf.HTRACE_HRPC_IO_TIMEOUT_MS: "1", }, } @@ -354,11 +354,11 @@ func TestHrpcIoTimeout(t *testing.T) { var hcl *htrace.Client finishClient := make(chan interface{}) defer func() { - // Close the finishClient channel, if it hasn't already been closed. - defer func() {recover()}() + // Close the finishClient channel, if it hasn't already been closed. + defer func() { recover() }() close(finishClient) }() - testHooks := &htrace.TestHooks { + testHooks := &htrace.TestHooks{ HandleWriteRequestBody: func() { <-finishClient }, @@ -380,7 +380,7 @@ func TestHrpcIoTimeout(t *testing.T) { // TEST_NUM_WRITESPANS I/O errors in the HRPC server-- after that, // we let requests through so that the test can exit cleanly. hcl.WriteSpans(&common.WriteSpansReq{ - Spans: allSpans[i:i+1], + Spans: allSpans[i : i+1], }) }(iter) } @@ -399,7 +399,7 @@ func doWriteSpans(name string, N int, maxSpansPerRpc uint32, b *testing.B) { Cnf: map[string]string{ conf.HTRACE_LOG_LEVEL: "INFO", }, - WrittenSpans: common.NewSemaphore(int64(1-N)), + WrittenSpans: common.NewSemaphore(int64(1 - N)), } ht, err := htraceBld.Build() if err != nil { @@ -428,7 +428,7 @@ func doWriteSpans(name string, N int, maxSpansPerRpc uint32, b *testing.B) { for n := 0; n < N; n++ { span := allSpans[n] if (curReqSpans >= maxSpansPerRpc) || - (curReqLen >= bodyLen) { + (curReqLen >= bodyLen) { reqs = append(reqs, &common.WriteSpansReq{}) curReqLen = 0 curReq++ @@ -464,7 +464,7 @@ func doWriteSpans(name string, N int, maxSpansPerRpc uint32, b *testing.B) { } // Write many random spans. - for reqIdx := range(reqs) { + for reqIdx := range reqs { go func() { err = hcl.WriteSpans(reqs[reqIdx]) if err != nil { http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/2df858ae/htrace-htraced/go/src/org/apache/htrace/htraced/datastore.go ---------------------------------------------------------------------- diff --git a/htrace-htraced/go/src/org/apache/htrace/htraced/datastore.go b/htrace-htraced/go/src/org/apache/htrace/htraced/datastore.go index 1dab5c8..816123a 100644 --- a/htrace-htraced/go/src/org/apache/htrace/htraced/datastore.go +++ b/htrace-htraced/go/src/org/apache/htrace/htraced/datastore.go @@ -131,7 +131,7 @@ func (shd *shard) processIncoming() { } totalWritten := 0 totalDropped := 0 - for spanIdx := range(spans) { + for spanIdx := range spans { err := shd.writeSpan(spans[spanIdx]) if err != nil { lg.Errorf("Shard processor for %s got fatal error %s.\n", @@ -675,59 +675,59 @@ const WRITESPANS_BATCH_SIZE = 128 // encoder setup for each span, and also generates less garbage. type SpanIngestor struct { // The logger to use. - lg *common.Logger + lg *common.Logger // The dataStore we are ingesting spans into. - store *dataStore + store *dataStore // The remote address these spans are coming from. - addr string + addr string // Default TracerId - defaultTrid string + defaultTrid string // The msgpack handle to use to serialize the spans. - mh codec.MsgpackHandle + mh codec.MsgpackHandle // The msgpack encoder to use to serialize the spans. - // Caching this avoids generating a lot of garbage and burning CPUs + // Caching this avoids generating a lot of garbage and burning CPUs // creating new encoder objects for each span. - enc *codec.Encoder + enc *codec.Encoder - // The buffer which codec.Encoder is currently serializing to. + // The buffer which codec.Encoder is currently serializing to. // We have to create a new buffer for each span because once we hand it off to the shard, the // shard manages the buffer lifecycle. - spanDataBytes []byte + spanDataBytes []byte // An array mapping shard index to span batch. - batches []*SpanIngestorBatch + batches []*SpanIngestorBatch - // The total number of spans ingested. Includes dropped spans. - totalIngested int + // The total number of spans ingested. Includes dropped spans. + totalIngested int // The total number of spans the ingestor dropped because of a server-side error. - serverDropped int + serverDropped int } // A batch of spans destined for a particular shard. type SpanIngestorBatch struct { - incoming []*IncomingSpan + incoming []*IncomingSpan } func (store *dataStore) NewSpanIngestor(lg *common.Logger, - addr string, defaultTrid string) *SpanIngestor { - ing := &SpanIngestor { - lg: lg, - store: store, - addr: addr, - defaultTrid: defaultTrid, + addr string, defaultTrid string) *SpanIngestor { + ing := &SpanIngestor{ + lg: lg, + store: store, + addr: addr, + defaultTrid: defaultTrid, spanDataBytes: make([]byte, 0, 1024), - batches: make([]*SpanIngestorBatch, len(store.shards)), + batches: make([]*SpanIngestorBatch, len(store.shards)), } ing.mh.WriteExt = true ing.enc = codec.NewEncoderBytes(&ing.spanDataBytes, &ing.mh) - for batchIdx := range(ing.batches) { - ing.batches[batchIdx] = &SpanIngestorBatch { + for batchIdx := range ing.batches { + ing.batches[batchIdx] = &SpanIngestorBatch{ incoming: make([]*IncomingSpan, 0, WRITESPANS_BATCH_SIZE), } } @@ -770,41 +770,41 @@ func (ing *SpanIngestor) IngestSpan(span *common.Span) { batch := ing.batches[shardIdx] incomingLen := len(batch.incoming) if ing.lg.TraceEnabled() { - ing.lg.Tracef("SpanIngestor#IngestSpan: spanId=%s, shardIdx=%d, " + + ing.lg.Tracef("SpanIngestor#IngestSpan: spanId=%s, shardIdx=%d, "+ "incomingLen=%d, cap(batch.incoming)=%d\n", span.Id.String(), shardIdx, incomingLen, cap(batch.incoming)) } - if incomingLen + 1 == cap(batch.incoming) { + if incomingLen+1 == cap(batch.incoming) { if ing.lg.TraceEnabled() { - ing.lg.Tracef("SpanIngestor#IngestSpan: flushing %d spans for " + + ing.lg.Tracef("SpanIngestor#IngestSpan: flushing %d spans for "+ "shard %d\n", len(batch.incoming), shardIdx) } ing.store.WriteSpans(shardIdx, batch.incoming) batch.incoming = make([]*IncomingSpan, 1, WRITESPANS_BATCH_SIZE) incomingLen = 0 } else { - batch.incoming = batch.incoming[0:incomingLen+1] + batch.incoming = batch.incoming[0 : incomingLen+1] } - batch.incoming[incomingLen] = &IncomingSpan { - Addr: ing.addr, - Span: span, + batch.incoming[incomingLen] = &IncomingSpan{ + Addr: ing.addr, + Span: span, SpanDataBytes: spanDataBytes, } } func (ing *SpanIngestor) Close(startTime time.Time) { - for shardIdx := range(ing.batches) { + for shardIdx := range ing.batches { batch := ing.batches[shardIdx] if len(batch.incoming) > 0 { if ing.lg.TraceEnabled() { - ing.lg.Tracef("SpanIngestor#Close: flushing %d span(s) for " + + ing.lg.Tracef("SpanIngestor#Close: flushing %d span(s) for "+ "shard %d\n", len(batch.incoming), shardIdx) } ing.store.WriteSpans(shardIdx, batch.incoming) } batch.incoming = nil } - ing.lg.Debugf("Closed span ingestor for %s. Ingested %d span(s); dropped " + + ing.lg.Debugf("Closed span ingestor for %s. Ingested %d span(s); dropped "+ "%d span(s).\n", ing.addr, ing.totalIngested, ing.serverDropped) endTime := time.Now() http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/2df858ae/htrace-htraced/go/src/org/apache/htrace/htraced/datastore_test.go ---------------------------------------------------------------------- diff --git a/htrace-htraced/go/src/org/apache/htrace/htraced/datastore_test.go b/htrace-htraced/go/src/org/apache/htrace/htraced/datastore_test.go index d38c1b0..b13112b 100644 --- a/htrace-htraced/go/src/org/apache/htrace/htraced/datastore_test.go +++ b/htrace-htraced/go/src/org/apache/htrace/htraced/datastore_test.go @@ -334,7 +334,7 @@ func BenchmarkDatastoreWrites(b *testing.B) { htraceBld := &MiniHTracedBuilder{Name: "BenchmarkDatastoreWrites", Cnf: map[string]string{ conf.HTRACE_DATASTORE_HEARTBEAT_PERIOD_MS: "30000", - conf.HTRACE_LOG_LEVEL: "INFO", + conf.HTRACE_LOG_LEVEL: "INFO", }, WrittenSpans: common.NewSemaphore(0), } @@ -351,7 +351,7 @@ func BenchmarkDatastoreWrites(b *testing.B) { }() rnd := rand.New(rand.NewSource(time.Now().UnixNano())) allSpans := make([]*common.Span, b.N) - for n := range(allSpans) { + for n := range allSpans { allSpans[n] = test.NewRandomSpan(rnd, allSpans[0:n]) } @@ -375,9 +375,9 @@ func TestReloadDataStore(t *testing.T) { Cnf: map[string]string{ conf.HTRACE_DATASTORE_HEARTBEAT_PERIOD_MS: "30000", }, - DataDirs: make([]string, 2), + DataDirs: make([]string, 2), KeepDataDirsOnClose: true, - WrittenSpans: common.NewSemaphore(0), + WrittenSpans: common.NewSemaphore(0), } ht, err := htraceBld.Build() if err != nil { http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/2df858ae/htrace-htraced/go/src/org/apache/htrace/htraced/hrpc.go ---------------------------------------------------------------------- diff --git a/htrace-htraced/go/src/org/apache/htrace/htraced/hrpc.go b/htrace-htraced/go/src/org/apache/htrace/htraced/hrpc.go index 0d569a0..a6f6751 100644 --- a/htrace-htraced/go/src/org/apache/htrace/htraced/hrpc.go +++ b/htrace-htraced/go/src/org/apache/htrace/htraced/hrpc.go @@ -49,31 +49,31 @@ type HrpcHandler struct { // The HRPC server type HrpcServer struct { *rpc.Server - hand *HrpcHandler + hand *HrpcHandler // The listener we are using to accept new connections. listener net.Listener // A WaitGroup used to block until the HRPC server has exited. - exited sync.WaitGroup + exited sync.WaitGroup // A channel containing server codecs to use. This channel is fully // buffered. The number of entries it initially contains determines how // many concurrent codecs we will have running at once. - cdcs chan *HrpcServerCodec + cdcs chan *HrpcServerCodec // Used to shut down shutdown chan interface{} // The I/O timeout to use when reading requests or sending responses. This // timeout does not apply to the time we spend processing the message. - ioTimeo time.Duration + ioTimeo time.Duration // A count of all I/O errors that we have encountered since the server // started. This counts errors like improperly formatted message frames, // but not errors like properly formatted but invalid messages. // This count is updated from multiple goroutines via sync/atomic. - ioErrorCount uint64 + ioErrorCount uint64 // The test hooks to use, or nil during normal operation. testHooks *hrpcTestHooks @@ -88,13 +88,13 @@ type hrpcTestHooks struct { // A codec which encodes HRPC data via JSON. This structure holds the context // for a particular client connection. type HrpcServerCodec struct { - lg *common.Logger + lg *common.Logger // The current connection. - conn net.Conn + conn net.Conn // The HrpcServer which this connection is part of. - hsv *HrpcServer + hsv *HrpcServer // The message length we read from the header. length uint32 @@ -117,7 +117,7 @@ func newIoErrorWarn(cdc *HrpcServerCodec, val string) error { func newIoError(cdc *HrpcServerCodec, val string, level common.Level) error { if cdc.lg.LevelEnabled(level) { - cdc.lg.Write(level, cdc.conn.RemoteAddr().String() + ": " + val + "\n") + cdc.lg.Write(level, cdc.conn.RemoteAddr().String()+": "+val+"\n") } if level >= common.INFO { atomic.AddUint64(&cdc.hsv.ioErrorCount, 1) @@ -134,7 +134,7 @@ func (cdc *HrpcServerCodec) ReadRequestHeader(req *rpc.Request) error { err := binary.Read(cdc.conn, binary.LittleEndian, &hdr) if err != nil { if err == io.EOF && cdc.numHandled > 0 { - return newIoError(cdc, fmt.Sprintf("Remote closed connection " + + return newIoError(cdc, fmt.Sprintf("Remote closed connection "+ "after writing %d message(s)", cdc.numHandled), common.DEBUG) } return newIoError(cdc, @@ -173,7 +173,7 @@ func (cdc *HrpcServerCodec) ReadRequestBody(body interface{}) error { dec := codec.NewDecoder(io.LimitReader(cdc.conn, int64(cdc.length)), mh) err := dec.Decode(body) if err != nil { - return newIoErrorWarn(cdc, fmt.Sprintf("Failed to read %d-byte " + + return newIoErrorWarn(cdc, fmt.Sprintf("Failed to read %d-byte "+ "request body: %s", cdc.length, err.Error())) } if cdc.lg.TraceEnabled() { @@ -257,13 +257,13 @@ func (cdc *HrpcServerCodec) Close() error { } func (hand *HrpcHandler) WriteSpans(req *common.WriteSpansReq, - resp *common.WriteSpansResp) (err error) { + resp *common.WriteSpansResp) (err error) { startTime := time.Now() hand.lg.Debugf("hrpc writeSpansHandler: received %d span(s). "+ "defaultTrid = %s\n", len(req.Spans), req.DefaultTrid) client, _, err := net.SplitHostPort(req.Addr) if err != nil { - return errors.New(fmt.Sprintf("Failed to split host and port " + + return errors.New(fmt.Sprintf("Failed to split host and port "+ "for %s: %s\n", req.Addr, err.Error())) } ing := hand.store.NewSpanIngestor(hand.lg, client, req.DefaultTrid) @@ -275,7 +275,7 @@ func (hand *HrpcHandler) WriteSpans(req *common.WriteSpansReq, } func CreateHrpcServer(cnf *conf.Config, store *dataStore, - testHooks *hrpcTestHooks) (*HrpcServer, error) { + testHooks *hrpcTestHooks) (*HrpcServer, error) { lg := common.NewLogger("hrpc", cnf) numHandlers := cnf.GetInt(conf.HTRACE_NUM_HRPC_HANDLERS) if numHandlers < 1 { @@ -293,7 +293,7 @@ func CreateHrpcServer(cnf *conf.Config, store *dataStore, lg: lg, store: store, }, - cdcs: make(chan *HrpcServerCodec, numHandlers), + cdcs: make(chan *HrpcServerCodec, numHandlers), shutdown: make(chan interface{}), ioTimeo: time.Millisecond * time.Duration(cnf.GetInt64(conf.HTRACE_HRPC_IO_TIMEOUT_MS)), @@ -301,8 +301,8 @@ func CreateHrpcServer(cnf *conf.Config, store *dataStore, } for i := 0; i < numHandlers; i++ { hsv.cdcs <- &HrpcServerCodec{ - lg: lg, - hsv: hsv, + lg: lg, + hsv: hsv, } } var err error @@ -313,7 +313,7 @@ func CreateHrpcServer(cnf *conf.Config, store *dataStore, hsv.Server.Register(hsv.hand) hsv.exited.Add(1) go hsv.run() - lg.Infof("Started HRPC server on %s with %d handler routines. " + + lg.Infof("Started HRPC server on %s with %d handler routines. "+ "ioTimeo=%s.\n", hsv.listener.Addr().String(), numHandlers, hsv.ioTimeo.String()) return hsv, nil @@ -328,11 +328,11 @@ func (hsv *HrpcServer) run() { }() for { select { - case cdc:=<-hsv.cdcs: + case cdc := <-hsv.cdcs: conn, err := hsv.listener.Accept() if err != nil { lg.Errorf("HrpcServer on %s got accept error: %s\n", srvAddr, err.Error()) - hsv.cdcs<-cdc // never blocks; there is always sufficient buffer space + hsv.cdcs <- cdc // never blocks; there is always sufficient buffer space continue } if lg.TraceEnabled() { http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/2df858ae/htrace-htraced/go/src/org/apache/htrace/htraced/metrics.go ---------------------------------------------------------------------- diff --git a/htrace-htraced/go/src/org/apache/htrace/htraced/metrics.go b/htrace-htraced/go/src/org/apache/htrace/htraced/metrics.go index 7bf42fd..9176de0 100644 --- a/htrace-htraced/go/src/org/apache/htrace/htraced/metrics.go +++ b/htrace-htraced/go/src/org/apache/htrace/htraced/metrics.go @@ -66,18 +66,18 @@ type MetricsSink struct { } func NewMetricsSink(cnf *conf.Config) *MetricsSink { - return &MetricsSink { + return &MetricsSink{ lg: common.NewLogger("metrics", cnf), maxMtx: cnf.GetInt(conf.HTRACE_METRICS_MAX_ADDR_ENTRIES), - HostSpanMetrics: make(common.SpanMetricsMap), + HostSpanMetrics: make(common.SpanMetricsMap), wsLatencyCircBuf: NewCircBufU32(LATENCY_CIRC_BUF_SIZE), } } // Update the total number of spans which were ingested, as well as other -// metrics that get updated during span ingest. +// metrics that get updated during span ingest. func (msink *MetricsSink) UpdateIngested(addr string, totalIngested int, - serverDropped int, wsLatency time.Duration) { + serverDropped int, wsLatency time.Duration) { msink.lock.Lock() defer msink.lock.Unlock() msink.IngestedSpans += uint64(totalIngested) @@ -95,7 +95,7 @@ func (msink *MetricsSink) UpdateIngested(addr string, totalIngested int, // Update the per-host span metrics. Must be called with the lock held. func (msink *MetricsSink) updateSpanMetrics(addr string, numWritten int, - serverDropped int) { + serverDropped int) { mtx, found := msink.HostSpanMetrics[addr] if !found { // Ensure that the per-host span metrics map doesn't grow too large. @@ -108,7 +108,7 @@ func (msink *MetricsSink) updateSpanMetrics(addr string, numWritten int, break } } - mtx = &common.SpanMetrics { } + mtx = &common.SpanMetrics{} msink.HostSpanMetrics[addr] = mtx } mtx.Written += uint64(numWritten) @@ -117,7 +117,7 @@ func (msink *MetricsSink) updateSpanMetrics(addr string, numWritten int, // Update the total number of spans which were persisted to disk. func (msink *MetricsSink) UpdatePersisted(addr string, totalWritten int, - serverDropped int) { + serverDropped int) { msink.lock.Lock() defer msink.lock.Unlock() msink.WrittenSpans += uint64(totalWritten) @@ -135,9 +135,9 @@ func (msink *MetricsSink) PopulateServerStats(stats *common.ServerStats) { stats.MaxWriteSpansLatencyMs = msink.wsLatencyCircBuf.Max() stats.AverageWriteSpansLatencyMs = msink.wsLatencyCircBuf.Average() stats.HostSpanMetrics = make(common.SpanMetricsMap) - for k, v := range(msink.HostSpanMetrics) { - stats.HostSpanMetrics[k] = &common.SpanMetrics { - Written: v.Written, + for k, v := range msink.HostSpanMetrics { + stats.HostSpanMetrics[k] = &common.SpanMetrics{ + Written: v.Written, ServerDropped: v.ServerDropped, } } @@ -158,9 +158,9 @@ type CircBufU32 struct { } func NewCircBufU32(size int) *CircBufU32 { - return &CircBufU32 { + return &CircBufU32{ slotsUsed: -1, - buf: make([]uint32, size), + buf: make([]uint32, size), } } http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/2df858ae/htrace-htraced/go/src/org/apache/htrace/htraced/metrics_test.go ---------------------------------------------------------------------- diff --git a/htrace-htraced/go/src/org/apache/htrace/htraced/metrics_test.go b/htrace-htraced/go/src/org/apache/htrace/htraced/metrics_test.go index e1dba1f..bad7889 100644 --- a/htrace-htraced/go/src/org/apache/htrace/htraced/metrics_test.go +++ b/htrace-htraced/go/src/org/apache/htrace/htraced/metrics_test.go @@ -48,7 +48,7 @@ type Fatalfer interface { } func assertNumWrittenEquals(t Fatalfer, msink *MetricsSink, - expectedNumWritten int) { + expectedNumWritten int) { var sstats common.ServerStats msink.PopulateServerStats(&sstats) if sstats.WrittenSpans != uint64(expectedNumWritten) { @@ -59,8 +59,8 @@ func assertNumWrittenEquals(t Fatalfer, msink *MetricsSink, t.Fatalf("no entry for sstats.HostSpanMetrics[127.0.0.1] found.") } if sstats.HostSpanMetrics["127.0.0.1"].Written != - uint64(expectedNumWritten) { - t.Fatalf("sstats.HostSpanMetrics[127.0.0.1].Written = %d, but " + + uint64(expectedNumWritten) { + t.Fatalf("sstats.HostSpanMetrics[127.0.0.1].Written = %d, but "+ "expected %d\n", sstats.HostSpanMetrics["127.0.0.1"].Written, len(SIMPLE_TEST_SPANS)) } @@ -83,7 +83,7 @@ func TestMetricsSinkPerHostEviction(t *testing.T) { msink.lock.Lock() defer msink.lock.Unlock() if len(msink.HostSpanMetrics) != 2 { - for k, v := range(msink.HostSpanMetrics) { + for k, v := range msink.HostSpanMetrics { fmt.Printf("WATERMELON: [%s] = [%s]\n", k, v) } t.Fatalf("Expected len(msink.HostSpanMetrics) to be 2, but got %d\n", @@ -109,7 +109,7 @@ func testIngestedSpansMetricsImpl(t *testing.T, usePacked bool) { } defer ht.Close() var hcl *htrace.Client - hcl, err = htrace.NewClient(ht.ClientConf(), &htrace.TestHooks { + hcl, err = htrace.NewClient(ht.ClientConf(), &htrace.TestHooks{ HrpcDisabled: !usePacked, }) if err != nil { http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/2df858ae/htrace-htraced/go/src/org/apache/htrace/htraced/reaper_test.go ---------------------------------------------------------------------- diff --git a/htrace-htraced/go/src/org/apache/htrace/htraced/reaper_test.go b/htrace-htraced/go/src/org/apache/htrace/htraced/reaper_test.go index b354a2c..2d6a76f 100644 --- a/htrace-htraced/go/src/org/apache/htrace/htraced/reaper_test.go +++ b/htrace-htraced/go/src/org/apache/htrace/htraced/reaper_test.go @@ -41,8 +41,8 @@ func TestReapingOldSpans(t *testing.T) { } htraceBld := &MiniHTracedBuilder{Name: "TestReapingOldSpans", Cnf: map[string]string{ - conf.HTRACE_SPAN_EXPIRY_MS: fmt.Sprintf("%d", 60*60*1000), - conf.HTRACE_REAPER_HEARTBEAT_PERIOD_MS: "1", + conf.HTRACE_SPAN_EXPIRY_MS: fmt.Sprintf("%d", 60*60*1000), + conf.HTRACE_REAPER_HEARTBEAT_PERIOD_MS: "1", conf.HTRACE_DATASTORE_HEARTBEAT_PERIOD_MS: "1", }, WrittenSpans: common.NewSemaphore(0), http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/2df858ae/htrace-htraced/go/src/org/apache/htrace/htraced/rest.go ---------------------------------------------------------------------- diff --git a/htrace-htraced/go/src/org/apache/htrace/htraced/rest.go b/htrace-htraced/go/src/org/apache/htrace/htraced/rest.go index c327cdd..da82912 100644 --- a/htrace-htraced/go/src/org/apache/htrace/htraced/rest.go +++ b/htrace-htraced/go/src/org/apache/htrace/htraced/rest.go @@ -77,11 +77,11 @@ type serverDebugInfoHandler struct { func (hand *serverDebugInfoHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { setResponseHeaders(w.Header()) - buf := make([]byte, 1 << 20) + buf := make([]byte, 1<<20) common.GetStackTraces(&buf) resp := common.ServerDebugInfo{ StackTraces: string(buf), - GCStats: common.GetGCStats(), + GCStats: common.GetGCStats(), } buf, err := json.Marshal(&resp) if err != nil { @@ -315,7 +315,7 @@ type RestServer struct { } func CreateRestServer(cnf *conf.Config, store *dataStore, - listener net.Listener) (*RestServer, error) { + listener net.Listener) (*RestServer, error) { var err error rsv := &RestServer{} rsv.lg = common.NewLogger("rest", cnf) @@ -357,7 +357,7 @@ func CreateRestServer(cnf *conf.Config, store *dataStore, } } - rsv.lg.Infof(`Serving static files from "%s"` + "\n", webdir) + rsv.lg.Infof(`Serving static files from "%s"`+"\n", webdir) r.PathPrefix("/").Handler(http.FileServer(http.Dir(webdir))).Methods("GET") // Log an error message for unknown non-GET requests. http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/2df858ae/htrace-htraced/go/src/org/apache/htrace/htracedTool/queries.go ---------------------------------------------------------------------- diff --git a/htrace-htraced/go/src/org/apache/htrace/htracedTool/queries.go b/htrace-htraced/go/src/org/apache/htrace/htracedTool/queries.go index 442df4f..1e6f51f 100644 --- a/htrace-htraced/go/src/org/apache/htrace/htracedTool/queries.go +++ b/htrace-htraced/go/src/org/apache/htrace/htracedTool/queries.go @@ -104,7 +104,7 @@ func parseQueryString(str string) ([]common.Predicate, error) { if verbose { fmt.Printf("Running query [ ") prefix := "" - for tokenIdx := range(ps.tokens) { + for tokenIdx := range ps.tokens { fmt.Printf("%s'%s'", prefix, ps.tokens[tokenIdx]) prefix = ", " } http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/2df858ae/htrace-htraced/go/src/org/apache/htrace/htracedTool/query_test.go ---------------------------------------------------------------------- diff --git a/htrace-htraced/go/src/org/apache/htrace/htracedTool/query_test.go b/htrace-htraced/go/src/org/apache/htrace/htracedTool/query_test.go index cab1e92..755d0b0 100644 --- a/htrace-htraced/go/src/org/apache/htrace/htracedTool/query_test.go +++ b/htrace-htraced/go/src/org/apache/htrace/htracedTool/query_test.go @@ -40,49 +40,49 @@ func checkParseQueryString(t *testing.T, str string, epreds []common.Predicate) t.Fatalf("got unexpected parseQueryString error: %s\n", err.Error()) } if !reflect.DeepEqual(preds, epreds) { - t.Fatalf("Unexpected result from parseQueryString. " + + t.Fatalf("Unexpected result from parseQueryString. "+ "Expected: %s, got: %s\n", predsToStr(epreds), predsToStr(preds)) } } func TestParseQueryString(t *testing.T) { verbose = testing.Verbose() - checkParseQueryString(t, "description eq ls", []common.Predicate { - common.Predicate { - Op: common.EQUALS, + checkParseQueryString(t, "description eq ls", []common.Predicate{ + common.Predicate{ + Op: common.EQUALS, Field: common.DESCRIPTION, - Val: "ls", + Val: "ls", }, }) - checkParseQueryString(t, "begin gt 123 and end le 456", []common.Predicate { - common.Predicate { - Op: common.GREATER_THAN, + checkParseQueryString(t, "begin gt 123 and end le 456", []common.Predicate{ + common.Predicate{ + Op: common.GREATER_THAN, Field: common.BEGIN_TIME, - Val: "123", + Val: "123", }, - common.Predicate { - Op: common.LESS_THAN_OR_EQUALS, + common.Predicate{ + Op: common.LESS_THAN_OR_EQUALS, Field: common.END_TIME, - Val: "456", + Val: "456", }, }) - checkParseQueryString(t, `DESCRIPTION cn "Foo Bar" and ` + + checkParseQueryString(t, `DESCRIPTION cn "Foo Bar" and `+ `BEGIN ge "999" and SPANID eq "4565d8abc4f70ac1216a3f1834c6860b"`, - []common.Predicate { - common.Predicate { - Op: common.CONTAINS, - Field: common.DESCRIPTION, - Val: "Foo Bar", - }, - common.Predicate { - Op: common.GREATER_THAN_OR_EQUALS, - Field: common.BEGIN_TIME, - Val: "999", - }, - common.Predicate { - Op: common.EQUALS, - Field: common.SPAN_ID, - Val: "4565d8abc4f70ac1216a3f1834c6860b", - }, - }) + []common.Predicate{ + common.Predicate{ + Op: common.CONTAINS, + Field: common.DESCRIPTION, + Val: "Foo Bar", + }, + common.Predicate{ + Op: common.GREATER_THAN_OR_EQUALS, + Field: common.BEGIN_TIME, + Val: "999", + }, + common.Predicate{ + Op: common.EQUALS, + Field: common.SPAN_ID, + Val: "4565d8abc4f70ac1216a3f1834c6860b", + }, + }) }
