Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added zap logger and basculehelper package #403

Merged
merged 7 commits into from
Jun 15, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions basculeLogging.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ import (
"context"
"net/http"
"strings"
"time"

"github.com/go-kit/log"
"github.com/xmidt-org/candlelight"

// nolint:staticcheck
"github.com/xmidt-org/webpa-common/v2/logging"
"github.com/xmidt-org/sallust"
"go.uber.org/zap"
)

func sanitizeHeaders(headers http.Header) (filtered http.Header) {
Expand All @@ -24,19 +23,19 @@ func sanitizeHeaders(headers http.Header) (filtered http.Header) {
return
}

func setLogger(logger log.Logger) func(delegate http.Handler) http.Handler {
func setLogger(logger *zap.Logger) func(delegate http.Handler) http.Handler {
return func(delegate http.Handler) http.Handler {
return http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
kvs := []interface{}{"requestHeaders", sanitizeHeaders(r.Header), "requestURL", r.URL.EscapedPath(), "method", r.Method}
kvs, _ = candlelight.AppendTraceInfo(r.Context(), kvs)
ctx := r.WithContext(logging.WithLogger(r.Context(), log.With(logger, kvs...)))
ctx := r.WithContext(sallust.With(r.Context(), logger))
delegate.ServeHTTP(w, ctx)
})
}
}

func getLogger(ctx context.Context) log.Logger {
logger := log.With(logging.GetLogger(ctx), "ts", log.DefaultTimestampUTC, "caller", log.DefaultCaller)
func getLogger(ctx context.Context) *zap.Logger {
logger := sallust.Get(ctx).With(zap.Time("ts", time.Now().UTC()), zap.Any("caller", zap.WithCaller(true)))
return logger
}
}
11 changes: 3 additions & 8 deletions caduceus_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,11 @@ package main
import (
"time"

"github.com/go-kit/log"
"github.com/go-kit/log/level"
"go.uber.org/zap"

"github.com/go-kit/kit/metrics"
"github.com/xmidt-org/ancla"

// nolint:staticcheck
"github.com/xmidt-org/webpa-common/v2/logging"
"github.com/xmidt-org/wrp-go/v3"
)

Expand Down Expand Up @@ -70,12 +67,10 @@ type RequestHandler interface {

type CaduceusHandler struct {
senderWrapper SenderWrapper
log.Logger
*zap.Logger
}

func (ch *CaduceusHandler) HandleRequest(workerID int, msg *wrp.Message) {
ch.Log(level.Key(), level.InfoValue(), "workerID", workerID, logging.MessageKey(), "Worker received a request, now passing"+
" to sender")

ch.Logger.Info("Worker received a request, now passing to sender", zap.Int("workerId", workerID))
ch.senderWrapper.Queue(msg)
}
4 changes: 2 additions & 2 deletions caduceus_type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ import (

"github.com/stretchr/testify/mock"
// nolint:staticcheck
"github.com/xmidt-org/webpa-common/v2/logging"
"github.com/xmidt-org/webpa-common/v2/adapter"
"github.com/xmidt-org/wrp-go/v3"
)

func TestCaduceusHandler(t *testing.T) {
logger := logging.DefaultLogger()
logger := adapter.DefaultLogger().Logger

fakeSenderWrapper := new(mockSenderWrapper)
fakeSenderWrapper.On("Queue", mock.AnythingOfType("*wrp.Message")).Return().Once()
Expand Down
44 changes: 22 additions & 22 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,21 @@ require (
emperror.dev/emperror v0.33.0
github.com/davecgh/go-spew v1.1.1
github.com/go-kit/kit v0.12.0
github.com/go-kit/log v0.2.1
github.com/gorilla/mux v1.8.0
github.com/justinas/alice v1.2.0
github.com/prometheus/client_golang v1.15.1
github.com/satori/go.uuid v1.2.0
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.16.0
github.com/stretchr/testify v1.8.4
github.com/xmidt-org/ancla v0.3.10
github.com/xmidt-org/bascule v0.11.1
github.com/xmidt-org/ancla v0.3.11
github.com/xmidt-org/bascule v0.11.5
github.com/xmidt-org/candlelight v0.0.16
github.com/xmidt-org/clortho v0.0.4
github.com/xmidt-org/httpaux v0.3.2
github.com/xmidt-org/sallust v0.2.0
github.com/xmidt-org/sallust v0.2.2
github.com/xmidt-org/touchstone v0.1.2
github.com/xmidt-org/webpa-common/v2 v2.0.7
github.com/xmidt-org/webpa-common/v2 v2.1.2
github.com/xmidt-org/wrp-go/v3 v3.1.6
go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux v0.40.0
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.40.0
Expand All @@ -32,7 +31,7 @@ require (
emperror.dev/errors v0.8.1 // indirect
github.com/SermoDigital/jose v0.9.2-0.20161205224733-f6df55f235c2 // indirect
github.com/VividCortex/gohistogram v1.0.0 // indirect
github.com/armon/go-metrics v0.4.0 // indirect
github.com/armon/go-metrics v0.4.1 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/billhathaway/consistentHash v0.0.0-20140718022140-addea16d2229 // indirect
github.com/c9s/goprocinfo v0.0.0-20210130143923-c95fcf8c64a8 // indirect
Expand All @@ -42,20 +41,21 @@ require (
github.com/fatih/color v1.13.0 // indirect
github.com/felixge/httpsnoop v1.0.3 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-logfmt/logfmt v0.5.1 // indirect
github.com/go-kit/log v0.2.1 // indirect
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-zookeeper/zk v1.0.3 // indirect
github.com/goccy/go-json v0.9.11 // indirect
github.com/goccy/go-json v0.10.0 // indirect
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/golang/glog v1.1.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/goph/emperror v0.17.3-0.20190703203600-60a8d9faa17b // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.14.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.15.1 // indirect
github.com/hashicorp/consul/api v1.20.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-hclog v1.2.2 // indirect
github.com/hashicorp/go-hclog v1.4.0 // indirect
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
github.com/hashicorp/go-rootcerts v1.0.2 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
Expand All @@ -67,19 +67,19 @@ require (
github.com/lestrrat-go/httpcc v1.0.1 // indirect
github.com/lestrrat-go/httprc v1.0.4 // indirect
github.com/lestrrat-go/iter v1.0.2 // indirect
github.com/lestrrat-go/jwx/v2 v2.0.5 // indirect
github.com/lestrrat-go/option v1.0.0 // indirect
github.com/lestrrat-go/jwx/v2 v2.0.8 // indirect
github.com/lestrrat-go/option v1.0.1 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/openzipkin/zipkin-go v0.4.1 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/client_model v0.4.0 // indirect
github.com/prometheus/common v0.42.0 // indirect
github.com/prometheus/procfs v0.9.0 // indirect
github.com/segmentio/ksuid v1.0.4 // indirect
Expand All @@ -90,11 +90,9 @@ require (
github.com/stretchr/objx v0.5.0 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
github.com/xmidt-org/argus v0.9.1 // indirect
github.com/xmidt-org/arrange v0.3.0 // indirect
github.com/xmidt-org/argus v0.9.10 // indirect
github.com/xmidt-org/arrange v0.4.0 // indirect
github.com/xmidt-org/chronon v0.1.1 // indirect
github.com/xmidt-org/themis v0.4.8 // indirect
github.com/xmidt-org/webpa-common v1.11.9 // indirect
go.opentelemetry.io/otel v1.14.0 // indirect
go.opentelemetry.io/otel/exporters/jaeger v1.14.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.14.0 // indirect
Expand All @@ -108,8 +106,8 @@ require (
go.opentelemetry.io/otel/trace v1.14.0 // indirect
go.opentelemetry.io/proto/otlp v0.19.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/dig v1.15.0 // indirect
go.uber.org/fx v1.18.2 // indirect
go.uber.org/dig v1.16.1 // indirect
go.uber.org/fx v1.19.3 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.9.0 // indirect
golang.org/x/net v0.10.0 // indirect
Expand All @@ -119,6 +117,8 @@ require (
google.golang.org/grpc v1.55.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/xmidt-org/ancla => /Users/mforti446/Documents/work/untouched-repos/ancla
Loading