Skip to content

Commit

Permalink
Fix the formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
schmidtw committed Sep 27, 2017
1 parent 6854180 commit dd4b7b2
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 56 deletions.
23 changes: 11 additions & 12 deletions src/caduceus/caduceus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand All @@ -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").
Expand Down
4 changes: 2 additions & 2 deletions src/caduceus/caduceusProfiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
20 changes: 9 additions & 11 deletions src/caduceus/caduceus_test.go
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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)

Expand All @@ -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")

Expand Down Expand Up @@ -101,4 +99,4 @@ func TestMuxServerConfig(t *testing.T) {

assert.Equal(http.StatusNotFound, resp.StatusCode)
})
}
}
4 changes: 2 additions & 2 deletions src/caduceus/caduceus_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
}
Expand Down
14 changes: 7 additions & 7 deletions src/caduceus/canduceus_type_test.go
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -103,4 +103,4 @@ func TestCaduceusHandler(t *testing.T) {
fakeSenderWrapper.AssertExpectations(t)
fakeProfiler.AssertExpectations(t)
})
}
}
4 changes: 2 additions & 2 deletions src/caduceus/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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(),
Expand Down
13 changes: 6 additions & 7 deletions src/caduceus/http_test.go
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -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

Expand Down
16 changes: 8 additions & 8 deletions src/caduceus/outboundSender.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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)
)
Expand All @@ -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 {
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/caduceus/outboundSender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
2 changes: 1 addition & 1 deletion src/caduceus/senderWrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/caduceus/senderWrapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -10,7 +11,6 @@ import (
"sync/atomic"
"testing"
"time"
"github.com/Comcast/webpa-common/logging"
)

type result struct {
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit dd4b7b2

Please sign in to comment.