From dd4b7b2633bb42884b6178842e0aaf522abe5922 Mon Sep 17 00:00:00 2001 From: Weston Schmidt Date: Wed, 27 Sep 2017 10:00:05 -0700 Subject: [PATCH] Fix the formatting. --- src/caduceus/caduceus.go | 23 +++++++++++------------ src/caduceus/caduceusProfiler.go | 4 ++-- src/caduceus/caduceus_test.go | 20 +++++++++----------- src/caduceus/caduceus_type.go | 4 ++-- src/caduceus/canduceus_type_test.go | 14 +++++++------- src/caduceus/http.go | 4 ++-- src/caduceus/http_test.go | 13 ++++++------- src/caduceus/outboundSender.go | 16 ++++++++-------- src/caduceus/outboundSender_test.go | 4 ++-- src/caduceus/senderWrapper.go | 2 +- src/caduceus/senderWrapper_test.go | 4 ++-- 11 files changed, 52 insertions(+), 56 deletions(-) diff --git a/src/caduceus/caduceus.go b/src/caduceus/caduceus.go index 32734ddd..f54317fb 100644 --- a/src/caduceus/caduceus.go +++ b/src/caduceus/caduceus.go @@ -11,12 +11,12 @@ import ( "time" "github.com/Comcast/webpa-common/concurrent" + "github.com/Comcast/webpa-common/logging" "github.com/Comcast/webpa-common/secure" "github.com/Comcast/webpa-common/secure/handler" "github.com/Comcast/webpa-common/secure/key" "github.com/Comcast/webpa-common/server" "github.com/Comcast/webpa-common/webhook" - "github.com/Comcast/webpa-common/logging" "github.com/SermoDigital/jose/jwt" "github.com/gorilla/mux" "github.com/justinas/alice" @@ -224,31 +224,31 @@ func caduceus(arguments []string) int { fmt.Fprintf(os.Stderr, "Unable to start device manager: %s\n", err) return 1 } - + var messageKey = logging.MessageKey() - debugLog.Log(messageKey,"Calling webhookFactory.PrepareAndStart") + debugLog.Log(messageKey, "Calling webhookFactory.PrepareAndStart") beginPrepStart := time.Now() webhookFactory.PrepareAndStart() - debugLog.Log(messageKey,"WebhookFactory.PrepareAndStart done.", "elapsedTime", time.Since(beginPrepStart)) + debugLog.Log(messageKey, "WebhookFactory.PrepareAndStart done.", "elapsedTime", time.Since(beginPrepStart)) // Attempt to obtain the current listener list from current system without having to wait for listener reregistration. - debugLog.Log(messageKey,"Attempting to obtain current listener list from source", "source", + debugLog.Log(messageKey, "Attempting to obtain current listener list from source", "source", v.GetString("start.apiPath")) beginObtainList := time.Now() startChan := make(chan webhook.Result, 1) webhookFactory.Start.GetCurrentSystemsHooks(startChan) var webhookStartResults webhook.Result = <-startChan if webhookStartResults.Error != nil { - errorLog.Log(logging.ErrorKey(),webhookStartResults.Error) + errorLog.Log(logging.ErrorKey(), webhookStartResults.Error) } else { // todo: add message webhookFactory.SetList(webhook.NewList(webhookStartResults.Hooks)) caduceusSenderWrapper.Update(webhookStartResults.Hooks) } - debugLog.Log(messageKey,"Current listener retrieval.", "elapsedTime", time.Since(beginObtainList)) + debugLog.Log(messageKey, "Current listener retrieval.", "elapsedTime", time.Since(beginObtainList)) - infoLog.Log(messageKey,"Caduceus is up and running!","elapsedTime", time.Since(beginCaduceus)) + infoLog.Log(messageKey, "Caduceus is up and running!", "elapsedTime", time.Since(beginCaduceus)) var ( signals = make(chan os.Signal, 1) @@ -265,10 +265,9 @@ func caduceus(arguments []string) int { return 0 } - -func configServerRouter(router *mux.Router, caduceusHandler alice.Chain, serverWrapper *ServerHandler)(*mux.Router){ - var singleContentType = func (r *http.Request, _ *mux.RouteMatch) bool { - return len(r.Header["Content-Type"]) == 1 //require single specification for Content-Type Header +func configServerRouter(router *mux.Router, caduceusHandler alice.Chain, serverWrapper *ServerHandler) *mux.Router { + var singleContentType = func(r *http.Request, _ *mux.RouteMatch) bool { + return len(r.Header["Content-Type"]) == 1 //require single specification for Content-Type Header } router.Handle("/api/v3/notify", caduceusHandler.Then(serverWrapper)).Methods("POST"). diff --git a/src/caduceus/caduceusProfiler.go b/src/caduceus/caduceusProfiler.go index ee2cd2c4..62d6f138 100644 --- a/src/caduceus/caduceusProfiler.go +++ b/src/caduceus/caduceusProfiler.go @@ -3,12 +3,12 @@ package main import ( "encoding/json" "errors" + "github.com/Comcast/webpa-common/logging" + "github.com/go-kit/kit/log" "math" "sort" "sync" "time" - "github.com/go-kit/kit/log" - "github.com/Comcast/webpa-common/logging" ) type ServerProfilerFactory struct { diff --git a/src/caduceus/caduceus_test.go b/src/caduceus/caduceus_test.go index e6e8505b..025cd6be 100644 --- a/src/caduceus/caduceus_test.go +++ b/src/caduceus/caduceus_test.go @@ -1,27 +1,26 @@ package main import ( - "os" - "testing" + "errors" "github.com/Comcast/webpa-common/logging" "github.com/Comcast/webpa-common/secure/handler" - "github.com/stretchr/testify/mock" - "net/http/httptest" "github.com/gorilla/mux" "github.com/justinas/alice" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" "net/http" - "errors" + "net/http/httptest" + "os" + "testing" ) func TestMain(m *testing.M) { os.Exit(m.Run()) } - /* -Simply tests that no bad requests make it to the caduceus listener. - */ +Simply tests that no bad requests make it to the caduceus listener. +*/ func TestMuxServerConfig(t *testing.T) { assert := assert.New(t) @@ -45,7 +44,7 @@ func TestMuxServerConfig(t *testing.T) { doJob: forceTimeOut, } - authHandler := handler.AuthorizationHandler{Validator:nil} + authHandler := handler.AuthorizationHandler{Validator: nil} caduceusHandler := alice.New(authHandler.Decorate) router := configServerRouter(mux.NewRouter(), caduceusHandler, serverWrapper) @@ -71,7 +70,6 @@ func TestMuxServerConfig(t *testing.T) { assert.Equal(http.StatusRequestTimeout, resp.StatusCode) }) - t.Run("TestMuxResponseManyHeaders", func(t *testing.T) { req.Header.Add("Content-Type", "too/many/headers") @@ -101,4 +99,4 @@ func TestMuxServerConfig(t *testing.T) { assert.Equal(http.StatusNotFound, resp.StatusCode) }) -} \ No newline at end of file +} diff --git a/src/caduceus/caduceus_type.go b/src/caduceus/caduceus_type.go index 4d11661b..8bcad12c 100644 --- a/src/caduceus/caduceus_type.go +++ b/src/caduceus/caduceus_type.go @@ -4,10 +4,10 @@ import ( "errors" "github.com/Comcast/webpa-common/health" "github.com/Comcast/webpa-common/logging" - "github.com/go-kit/kit/log" "github.com/Comcast/webpa-common/secure" "github.com/Comcast/webpa-common/secure/key" "github.com/Comcast/webpa-common/wrp" + "github.com/go-kit/kit/log" "time" ) @@ -101,7 +101,7 @@ type CaduceusHandler struct { func (ch *CaduceusHandler) HandleRequest(workerID int, inRequest CaduceusRequest) { inRequest.Telemetry.TimeSentToOutbound = time.Now() - logging.Info(ch).Log("workerID", workerID, logging.MessageKey(), "Worker received a request, now passing" + + logging.Info(ch).Log("workerID", workerID, logging.MessageKey(), "Worker received a request, now passing"+ " to sender") ch.senderWrapper.Queue(inRequest) } diff --git a/src/caduceus/canduceus_type_test.go b/src/caduceus/canduceus_type_test.go index d3c95cbc..f1d8eef2 100644 --- a/src/caduceus/canduceus_type_test.go +++ b/src/caduceus/canduceus_type_test.go @@ -1,14 +1,14 @@ package main import ( - "testing" - "sync" - "github.com/stretchr/testify/require" - "math" - "github.com/stretchr/testify/mock" + "github.com/Comcast/webpa-common/health" "github.com/Comcast/webpa-common/logging" "github.com/stretchr/testify/assert" - "github.com/Comcast/webpa-common/health" + "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" + "math" + "sync" + "testing" ) func TestWorkerPool(t *testing.T) { @@ -103,4 +103,4 @@ func TestCaduceusHandler(t *testing.T) { fakeSenderWrapper.AssertExpectations(t) fakeProfiler.AssertExpectations(t) }) -} \ No newline at end of file +} diff --git a/src/caduceus/http.go b/src/caduceus/http.go index 880ddafb..8359a5cf 100644 --- a/src/caduceus/http.go +++ b/src/caduceus/http.go @@ -2,8 +2,8 @@ package main import ( "encoding/json" - "github.com/go-kit/kit/log" "github.com/Comcast/webpa-common/logging" + "github.com/go-kit/kit/log" "io/ioutil" "net/http" "time" @@ -26,7 +26,7 @@ func (sh *ServerHandler) ServeHTTP(response http.ResponseWriter, request *http.R messageKey := logging.MessageKey() errorKey := logging.ErrorKey() - infoLog.Log(messageKey,"Receiving incoming request...") + infoLog.Log(messageKey, "Receiving incoming request...") stats := CaduceusTelemetry{ TimeReceived: time.Now(), diff --git a/src/caduceus/http_test.go b/src/caduceus/http_test.go index 7fd2510f..02fc1c39 100644 --- a/src/caduceus/http_test.go +++ b/src/caduceus/http_test.go @@ -1,16 +1,16 @@ package main import ( - "testing" - "net/http/httptest" - "strings" - "errors" "encoding/json" + "errors" "github.com/Comcast/webpa-common/logging" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" - "net/http" "io/ioutil" + "net/http" + "net/http/httptest" + "strings" + "testing" ) func TestServerHandler(t *testing.T) { @@ -101,8 +101,7 @@ func TestProfilerHandler(t *testing.T) { fakeProfiler.AssertExpectations(t) }) - - t.Run("TestServeHTTPSadPath", func(t *testing.T){ + t.Run("TestServeHTTPSadPath", func(t *testing.T) { innocentList := make([]interface{}, 1) innocentList[0] = make(chan int) //channels cannot be marshaled diff --git a/src/caduceus/outboundSender.go b/src/caduceus/outboundSender.go index 86feb36f..a21556ce 100644 --- a/src/caduceus/outboundSender.go +++ b/src/caduceus/outboundSender.go @@ -9,8 +9,8 @@ import ( "errors" "fmt" "github.com/Comcast/webpa-common/logging" - "github.com/go-kit/kit/log" "github.com/Comcast/webpa-common/webhook" + "github.com/go-kit/kit/log" "hash" "io" "io/ioutil" @@ -275,7 +275,7 @@ func (obs *CaduceusOutboundSender) QueueJSON(req CaduceusRequest, contentType: "application/json", } outboundReq.req.Telemetry.TimeOutboundAccepted = time.Now() - logging.Debug(obs.logger).Log(logging.MessageKey(),"JSON Sent to obs queue", "url", + logging.Debug(obs.logger).Log(logging.MessageKey(), "JSON Sent to obs queue", "url", obs.listener.Config.URL) obs.queue <- outboundReq } else { @@ -373,7 +373,7 @@ func (obs *CaduceusOutboundSender) QueueWrp(req CaduceusRequest) { } } } else { - debugLog.Log(logging.MessageKey(),"Outside delivery window") + debugLog.Log(logging.MessageKey(), "Outside delivery window") debugLog.Log("now", now, "before", deliverUntil, "after", dropUntil) } } @@ -460,7 +460,7 @@ func (obs *CaduceusOutboundSender) queueOverflow() { obs.dropUntil = time.Now().Add(obs.cutOffPeriod) obs.mutex.Unlock() - var( + var ( debugLog = logging.Debug(obs.logger) errorLog = logging.Error(obs.logger) ) @@ -469,10 +469,10 @@ func (obs *CaduceusOutboundSender) queueOverflow() { msg, err := json.Marshal(obs.failureMsg) if nil != err { - errorLog.Log(logging.MessageKey(),"Cut-off notification json.Marshall failed", "failureMessage", obs.failureMsg, + errorLog.Log(logging.MessageKey(), "Cut-off notification json.Marshall failed", "failureMessage", obs.failureMsg, "for", obs.listener.Config.URL, logging.ErrorKey(), err) } else { - errorLog.Log(logging.MessageKey(),"Cut-off notification", "failureMessage", msg, "for", obs.listener.Config.URL) + errorLog.Log(logging.MessageKey(), "Cut-off notification", "failureMessage", msg, "for", obs.listener.Config.URL) // Send a "you've been cut off" warning message if "" != obs.listener.FailureURL { @@ -491,12 +491,12 @@ func (obs *CaduceusOutboundSender) queueOverflow() { resp, err := obs.client.Do(req) if nil != err { // Failure - errorLog.Log(logging.MessageKey(),"Unable to send cut-off notification", "notification", + errorLog.Log(logging.MessageKey(), "Unable to send cut-off notification", "notification", obs.listener.FailureURL, "for", obs.listener.Config.URL, logging.ErrorKey(), err) } else { if nil == resp { // Failure - errorLog.Log(logging.MessageKey(),"Unable to send cut-off notification, nil response", + errorLog.Log(logging.MessageKey(), "Unable to send cut-off notification, nil response", "notification", obs.listener.FailureURL) } else { // Success diff --git a/src/caduceus/outboundSender_test.go b/src/caduceus/outboundSender_test.go index 7d89cd07..bd9cfea9 100644 --- a/src/caduceus/outboundSender_test.go +++ b/src/caduceus/outboundSender_test.go @@ -5,14 +5,14 @@ import ( "fmt" "github.com/Comcast/webpa-common/webhook" "github.com/Comcast/webpa-common/wrp" + "github.com/go-kit/kit/log" "github.com/stretchr/testify/assert" + "io" "io/ioutil" "net/http" "sync/atomic" "testing" "time" - "github.com/go-kit/kit/log" - "io" ) var ( diff --git a/src/caduceus/senderWrapper.go b/src/caduceus/senderWrapper.go index 83b95e44..b24bc9f2 100644 --- a/src/caduceus/senderWrapper.go +++ b/src/caduceus/senderWrapper.go @@ -4,12 +4,12 @@ import ( "errors" "github.com/Comcast/webpa-common/webhook" "github.com/Comcast/webpa-common/wrp" + "github.com/go-kit/kit/log" "net/http" "net/url" "strings" "sync" "time" - "github.com/go-kit/kit/log" ) // SenderWrapperFactory configures the CaduceusSenderWrapper for creation diff --git a/src/caduceus/senderWrapper_test.go b/src/caduceus/senderWrapper_test.go index ab7cbb67..19fba2c5 100644 --- a/src/caduceus/senderWrapper_test.go +++ b/src/caduceus/senderWrapper_test.go @@ -2,6 +2,7 @@ package main import ( "bytes" + "github.com/Comcast/webpa-common/logging" "github.com/Comcast/webpa-common/webhook" "github.com/Comcast/webpa-common/wrp" "github.com/stretchr/testify/assert" @@ -10,7 +11,6 @@ import ( "sync/atomic" "testing" "time" - "github.com/Comcast/webpa-common/logging" ) type result struct { @@ -50,7 +50,7 @@ func TestInvalidLinger(t *testing.T) { NumWorkersPerSender: 10, QueueSizePerSender: 10, CutOffPeriod: 30 * time.Second, - Logger: logging.DefaultLogger(), + Logger: logging.DefaultLogger(), Linger: 0 * time.Second, ProfilerFactory: ServerProfilerFactory{ Frequency: 10,