Skip to content

Commit

Permalink
Merge branch 'main' into update-workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
schmidtw authored Aug 14, 2023
2 parents 0327ea8 + 97d054b commit a132f55
Show file tree
Hide file tree
Showing 16 changed files with 1,095 additions and 351 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

## [v0.7.0]
- Added zap logger and basculehelper package [#403] (https://github.com/xmidt-org/caduceus/pull/403)

## [v0.6.13]
- Updated tracing configuration documentation in caduceus.yaml to reflect changes in Candlelight [#372](https://github.com/xmidt-org/caduceus/pull/372)
- Updated bascule config in docker env [#388] (https://github.com/xmidt-org/caduceus/pull/388/files)
Expand Down Expand Up @@ -220,7 +223,8 @@ fixed build upload
### Added
- Initial creation

[Unreleased]: https://github.com/xmidt-org/caduceus/compare/v0.6.13...HEAD
[Unreleased]: https://github.com/xmidt-org/caduceus/compare/v0.7.0...HEAD
[v0.7.0]: https://github.com/xmidt-org/caduceus/compare/v0.6.13...v0.7.0
[v0.6.13]: https://github.com/xmidt-org/caduceus/compare/v0.6.12...v0.6.13
[v0.6.12]: https://github.com/xmidt-org/caduceus/compare/v0.6.11...v0.6.12
[v0.6.11]: https://github.com/xmidt-org/caduceus/compare/v0.6.10...v0.6.11
Expand Down
26 changes: 26 additions & 0 deletions anclaHelper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package main

import (
"github.com/xmidt-org/ancla"

// nolint:staticcheck
"github.com/xmidt-org/webpa-common/v2/xmetrics"
)

func NewHelperMeasures(p xmetrics.Registry) ancla.Measures {
return ancla.Measures{
ChrysomPollsTotalCounterName: p.NewCounterVec(ancla.ChrysomPollsTotalCounterName),
WebhookListSizeGaugeName: p.NewPrometheusGauge(ancla.WebhookListSizeGaugeName),
}
}

func AnclaHelperMetrics() []xmetrics.Metric {
return []xmetrics.Metric{
{
Name: ancla.ChrysomPollsTotalCounterName,
Type: xmetrics.CounterType,
Help: "Counter for the number of polls (and their success/failure outcomes) to fetch new items.",
LabelNames: []string{ancla.OutcomeLabel},
},
}
}
29 changes: 20 additions & 9 deletions basculeLogging.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package main

import (
"context"
"fmt"
"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 +24,30 @@ 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...)))
delegate.ServeHTTP(w, ctx)
ctx := r.Context()
ctx = addFieldsToLog(ctx, logger, kvs)
delegate.ServeHTTP(w, r.WithContext(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
}

func addFieldsToLog(ctx context.Context, logger *zap.Logger, kvs []interface{}) context.Context {

for i := 0; i <= len(kvs)-2; i += 2 {
logger = logger.With(zap.Any(fmt.Sprint(kvs[i]), kvs[i+1]))
}

return sallust.With(ctx, 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
103 changes: 51 additions & 52 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,58 +4,58 @@ go 1.19

require (
emperror.dev/emperror v0.33.0
github.com/davecgh/go-spew v1.1.1
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
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.14.0
github.com/prometheus/client_golang v1.16.0
github.com/satori/go.uuid v1.2.0
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.15.0
github.com/stretchr/testify v1.8.2
github.com/xmidt-org/ancla v0.3.10
github.com/xmidt-org/bascule v0.11.1
github.com/xmidt-org/candlelight v0.0.15
github.com/spf13/viper v1.16.0
github.com/stretchr/testify v1.8.4
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/httpaux v0.4.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/wrp-go/v3 v3.1.4
github.com/xmidt-org/webpa-common/v2 v2.2.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
go.uber.org/zap v1.24.0
go.uber.org/zap v1.25.0
)

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
github.com/cenkalti/backoff/v4 v4.2.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
github.com/fatih/color v1.14.1 // 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.2 // indirect
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/golang/protobuf v1.5.2 // 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/hashicorp/consul/api v1.18.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.15.1 // indirect
github.com/hashicorp/consul/api v1.24.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.5.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,58 +67,57 @@ 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.11 // 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/matttproud/golang_protobuf_extensions v1.0.1 // 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.6 // 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/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_model v0.4.0 // indirect
github.com/prometheus/common v0.42.0 // indirect
github.com/prometheus/procfs v0.10.1 // indirect
github.com/segmentio/asm v1.2.0 // indirect
github.com/segmentio/ksuid v1.0.4 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/spf13/afero v1.9.3 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/afero v1.9.5 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/stretchr/objx v0.5.0 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
github.com/ugorji/go/codec v1.2.7 // indirect
github.com/xmidt-org/argus v0.9.1 // indirect
github.com/xmidt-org/arrange v0.3.0 // indirect
github.com/ugorji/go/codec v1.2.11 // 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
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.14.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.14.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.14.0 // indirect
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.14.0 // indirect
go.opentelemetry.io/otel/exporters/zipkin v1.13.0 // indirect
go.opentelemetry.io/otel/exporters/zipkin v1.14.0 // indirect
go.opentelemetry.io/otel/metric v0.37.0 // indirect
go.opentelemetry.io/otel/sdk v1.14.0 // indirect
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/multierr v1.8.0 // indirect
golang.org/x/crypto v0.0.0-20221010152910-d6f0a8c073c2 // indirect
golang.org/x/net v0.7.0 // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/text v0.7.0 // indirect
google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f // indirect
google.golang.org/grpc v1.53.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
go.uber.org/dig v1.17.0 // indirect
go.uber.org/fx v1.20.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.11.0 // indirect
golang.org/x/exp v0.0.0-20230321023759-10a507213a29 // indirect
golang.org/x/net v0.13.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/text v0.11.0 // indirect
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
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
)
Loading

0 comments on commit a132f55

Please sign in to comment.