Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/go_modules/github.com/ugorji/go/c…
Browse files Browse the repository at this point in the history
…odec-1.2.11
  • Loading branch information
denopink authored Oct 17, 2023
2 parents 44c29e5 + fcdef68 commit cb22398
Show file tree
Hide file tree
Showing 20 changed files with 680 additions and 284 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@ on:
- MAINTAINERS.md
- LICENSE
- NOTICE
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
pull_request:
workflow_dispatch:

jobs:
ci:
uses: xmidt-org/.github/.github/workflows/go-ci.yml@go-ci-v1
uses: xmidt-org/shared-go/.github/workflows/ci.yml@d0737af7255c581ce3cc09b69b96ba16a5913b4e # v4.0.0
with:
lint-skip: true
style-skip: true
copyright-skip: true
lint-skip: true
style-skip: true
release-type: library
secrets: inherit
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]

## [v2.1.1]
- Removed gokit/logger and replaced with zap.logger as part of the webpa-common deprecation for scytale, caduceus, and talaria (https://github.com/xmidt-org/webpa-common/issues/655)

## [v2.1.0]
- Patch writePump performance hit [#613](https://github.com/xmidt-org/webpa-common/pull/613)
- [Remove `logging` package and replace go-kit/kit/log & go-kit/log with `zap` #686](https://github.com/xmidt-org/webpa-common/issues/686)
Expand Down Expand Up @@ -253,7 +256,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- The first official release. We will be better about documenting changes
moving forward.

[Unreleased]: https://github.com/xmidt-org/webpa-common/compare/v2.1.0...HEAD
[Unreleased]: https://github.com/xmidt-org/webpa-common/compare/v2.1.1...HEAD
[v2.1.1]: https://github.com/xmidt-org/webpa-common/compare/v2.1.0...v2.1.1
[v2.1.0]: https://github.com/xmidt-org/webpa-common/compare/v2.0.7...v2.1.0
[v2.0.7]: https://github.com/xmidt-org/webpa-common/compare/v2.0.6...v2.0.7
[v2.0.6]: https://github.com/xmidt-org/webpa-common/compare/v2.0.5...v2.0.6
Expand Down
30 changes: 30 additions & 0 deletions adapter/adapter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package adapter

import (
"github.com/xmidt-org/sallust"
"go.uber.org/zap"
)

type Logger struct {
*zap.Logger
}

// this method makes Adapter implement log.Logger
func (l Logger) Log(keyvals ...interface{}) error {
fields := make([]zap.Field, 0, len(keyvals))
for i := 0; i < len(keyvals); i += 2 {
fields = append(fields, zap.Any(keyvals[i].(string), keyvals[i+1]))
}

// ignore the case where there's an odd number of keyvals ... that would be a bug
// and we're deprecating webpa-common anyway

l.Logger.Info("", fields...)
return nil
}

func DefaultLogger() *Logger {
return &Logger{
Logger: sallust.Default(),
}
}
29 changes: 14 additions & 15 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,36 @@ module github.com/xmidt-org/webpa-common/v2
go 1.13

require (
github.com/armon/go-metrics v0.4.1 // indirect
github.com/aws/aws-sdk-go v1.44.241
github.com/aws/aws-sdk-go v1.45.11
github.com/billhathaway/consistentHash v0.0.0-20140718022140-addea16d2229
github.com/c9s/goprocinfo v0.0.0-20210130143923-c95fcf8c64a8
github.com/go-kit/kit v0.12.0
github.com/go-kit/kit v0.13.0
github.com/go-kit/log v0.2.1
github.com/go-zookeeper/zk v1.0.3
github.com/gorilla/mux v1.8.0
github.com/gorilla/schema v1.2.0
github.com/gorilla/websocket v1.5.0
github.com/hashicorp/consul/api v1.20.0
github.com/hashicorp/go-hclog v1.4.0 // indirect
github.com/hashicorp/consul/api v1.25.1
github.com/influxdata/influxdb1-client v0.0.0-20220302092344-a9ab5670611c // indirect
github.com/justinas/alice v1.2.0
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/miekg/dns v1.1.53
github.com/miekg/dns v1.1.56
github.com/mitchellh/mapstructure v1.5.0
github.com/prometheus/client_golang v1.14.0
github.com/prometheus/client_golang v1.16.0
github.com/prometheus/client_model v0.4.0 // indirect
github.com/segmentio/ksuid v1.0.4
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/spf13/cast v1.5.0
github.com/spf13/cast v1.5.1
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.15.0
github.com/stretchr/testify v1.8.2
github.com/spf13/viper v1.16.0
github.com/stretchr/testify v1.8.4
github.com/ugorji/go v1.2.7 // indirect
github.com/ugorji/go/codec v1.2.11
github.com/xmidt-org/argus v0.9.10
github.com/xmidt-org/candlelight v0.0.15
github.com/xmidt-org/candlelight v0.0.16
github.com/xmidt-org/sallust v0.2.2
github.com/xmidt-org/themis v0.4.14
github.com/xmidt-org/wrp-go/v3 v3.1.4
github.com/xmidt-org/wrp-go/v3 v3.1.6
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.40.0
go.uber.org/fx v1.19.2
go.uber.org/zap v1.24.0
go.uber.org/fx v1.20.0
go.uber.org/zap v1.25.0
)
518 changes: 470 additions & 48 deletions go.sum

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions server/webpa.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"io/ioutil"
"net"
"net/http"
_ "net/http/pprof"
"runtime"
"sync"
"time"
Expand Down
22 changes: 11 additions & 11 deletions service/consul/datacenterWatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ import (
"sync"
"time"

"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/mitchellh/mapstructure"
"github.com/xmidt-org/argus/chrysom"
"github.com/xmidt-org/argus/model"
"github.com/xmidt-org/sallust"
"github.com/xmidt-org/webpa-common/v2/adapter"
"github.com/xmidt-org/webpa-common/v2/service"
"go.uber.org/zap"
)

// datacenterWatcher checks if datacenters have been updated, based on an interval.
type datacenterWatcher struct {
logger log.Logger
logger *zap.Logger
environment Environment
options Options
inactiveDatacenters map[string]bool
Expand All @@ -36,10 +36,10 @@ var (
defaultWatchInterval = 5 * time.Minute
)

func newDatacenterWatcher(logger log.Logger, environment Environment, options Options) (*datacenterWatcher, error) {
func newDatacenterWatcher(logger *zap.Logger, environment Environment, options Options) (*datacenterWatcher, error) {

if logger == nil {
logger = log.NewNopLogger()
logger = adapter.DefaultLogger().Logger
}

if options.DatacenterWatchInterval <= 0 {
Expand Down Expand Up @@ -86,13 +86,13 @@ func newDatacenterWatcher(logger log.Logger, environment Environment, options Op
//create chrysom client and start it
datacenterWatcher.stopListener = listener.Stop
listener.Start(context.Background())
logger.Log(level.Key(), level.DebugValue(), "msg", "started chrysom, argus client")
logger.Debug("started chrysom, argus client")
}

//start consul watch
ticker := time.NewTicker(datacenterWatcher.consulWatchInterval)
go datacenterWatcher.watchDatacenters(ticker)
logger.Log(level.Key(), level.DebugValue(), "msg", "started consul datacenter watch")
logger.Debug("started consul datacenter watch")
return datacenterWatcher, nil

}
Expand Down Expand Up @@ -144,7 +144,7 @@ func (d *datacenterWatcher) updateInstancers(datacenters []string) {

}

func updateInactiveDatacenters(items []model.Item, inactiveDatacenters map[string]bool, lock *sync.RWMutex, logger log.Logger) {
func updateInactiveDatacenters(items []model.Item, inactiveDatacenters map[string]bool, lock *sync.RWMutex, logger *zap.Logger) {
chrysomMap := make(map[string]bool)
for _, item := range items {

Expand All @@ -154,7 +154,7 @@ func updateInactiveDatacenters(items []model.Item, inactiveDatacenters map[strin
err := mapstructure.Decode(item.Data, &df)

if err != nil {
logger.Log(level.Key(), level.ErrorValue(), "msg", "failed to decode database results into datacenter filter struct")
logger.Error("failed to decode database results into datacenter filter struct")
continue
}

Expand Down Expand Up @@ -186,7 +186,7 @@ func createNewInstancer(keys map[string]bool, instancersToAdd service.Instancers
dw.lock.RUnlock()

if found {
dw.logger.Log(level.Key(), level.InfoValue(), "msg", "datacenter set as inactive", "datacenter name: ", datacenter)
dw.logger.Info("datacenter set as inactive", zap.Any("datacenter name: ", datacenter))
return
}

Expand All @@ -203,7 +203,7 @@ func createNewInstancer(keys map[string]bool, instancersToAdd service.Instancers

// don't create new instancer if it was already created and added to the new instancers map
if instancersToAdd.Has(key) {
dw.logger.Log(level.Key(), level.WarnValue(), "msg", "skipping duplicate watch", "service", w.Service, "tags", w.Tags, "passingOnly", w.PassingOnly, "datacenter", w.QueryOptions.Datacenter)
dw.logger.Warn("skipping duplicate watch", zap.String("service", w.Service), zap.Any("tags", w.Tags), zap.Bool("passingOnly", w.PassingOnly), zap.String("datacenter", w.QueryOptions.Datacenter))
return
}

Expand Down
11 changes: 6 additions & 5 deletions service/consul/datacenterWatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@ import (
"testing"
"time"

"github.com/go-kit/log"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/xmidt-org/argus/chrysom"
"github.com/xmidt-org/argus/model"
"github.com/xmidt-org/webpa-common/v2/adapter"
"github.com/xmidt-org/webpa-common/v2/service"
"github.com/xmidt-org/webpa-common/v2/xmetrics"
"go.uber.org/zap"
)

func TestNewDatacenterWatcher(t *testing.T) {
logger := log.NewNopLogger()
logger := adapter.DefaultLogger().Logger
r, err := xmetrics.NewRegistry(nil, Metrics)
require.Nil(t, err)
envShutdownChan := make(<-chan struct{})
Expand Down Expand Up @@ -46,7 +47,7 @@ func TestNewDatacenterWatcher(t *testing.T) {

tests := []struct {
description string
logger log.Logger
logger *zap.Logger
environment Environment
options Options
ctx context.Context
Expand Down Expand Up @@ -156,7 +157,7 @@ func TestNewDatacenterWatcher(t *testing.T) {
DatacenterWatchInterval: 10 * time.Second,
},
expectedWatcher: &datacenterWatcher{
logger: log.NewNopLogger(),
logger: logger,
environment: environment{
mockServiceEnvironment, new(mockClient),
},
Expand Down Expand Up @@ -247,7 +248,7 @@ func TestNewDatacenterWatcher(t *testing.T) {
}

func TestUpdateInactiveDatacenters(t *testing.T) {
logger := log.NewNopLogger()
logger := adapter.DefaultLogger().Logger

tests := []struct {
description string
Expand Down
Loading

0 comments on commit cb22398

Please sign in to comment.