Skip to content

Commit

Permalink
Merge branch 'denopink/release/v0.3.11' of https://github.com/xmidt-o…
Browse files Browse the repository at this point in the history
…rg/ancla into denopink/release/v0.3.11
  • Loading branch information
denopink committed Jan 10, 2023
2 parents 8ba2fda + f1762a1 commit 4a8e8fb
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 17 deletions.
5 changes: 3 additions & 2 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
package ancla

import (
"context"
"net/http"
"time"

kithttp "github.com/go-kit/kit/transport/http"
"github.com/xmidt-org/sallust"
"go.uber.org/zap"
)

// NewAddWebhookHandler returns an HTTP handler for adding
Expand Down Expand Up @@ -52,7 +53,7 @@ func NewGetAllWebhooksHandler(s Service, config HandlerConfig) http.Handler {
type HandlerConfig struct {
V Validator
DisablePartnerIDs bool
GetLogger sallust.GetLoggerFunc
GetLogger func(context.Context) *zap.Logger
}

func newTransportConfig(hConfig HandlerConfig) transportConfig {
Expand Down
7 changes: 4 additions & 3 deletions metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ type MeasuresIn struct {
}

// NewMeasures realizes desired metrics.
func NewMeasures(in MeasuresIn) (*MeasuresOut, error) {
func NewMeasures(in MeasuresIn) (MeasuresOut, error) {
var metricErr error
wlm, err := in.Factory.NewGauge(
prometheus.GaugeOpts{
Expand All @@ -73,15 +73,16 @@ func NewMeasures(in MeasuresIn) (*MeasuresOut, error) {
},
)
err = multierr.Append(err, metricErr)
cpm, err := in.Factory.NewCounterVec(
cpm, err2 := in.Factory.NewCounterVec(
prometheus.CounterOpts{
Name: ChrysomPollsTotalCounterName,
Help: ChrysomPollsTotalCounterHelp,
},
OutcomeLabel,
)
err = multierr.Append(err, err2)

return &MeasuresOut{
return MeasuresOut{
M: &Measures{
WebhookListSizeGaugeName: wlm,
ChrysomPollsTotalCounterName: cpm,
Expand Down
3 changes: 1 addition & 2 deletions service.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ type service struct {
}

// NewService builds the Argus client service from the given configuration.
func NewService(cfg Config, getLogger sallust.GetLoggerFunc) (*service, error) {
func NewService(cfg Config, getLogger func(context.Context) *zap.Logger) (*service, error) {
if cfg.Logger == nil {
cfg.Logger = sallust.Default()
}
Expand Down Expand Up @@ -175,7 +175,6 @@ func (s *service) GetAll(ctx context.Context) ([]InternalWebhook, error) {
}

func prepArgusBasicClientConfig(cfg *Config) error {
cfg.BasicClientConfig.Logger = cfg.Logger
p, err := newJWTAcquireParser(cfg.JWTParserType)
if err != nil {
return err
Expand Down
3 changes: 2 additions & 1 deletion service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ import (
"github.com/xmidt-org/argus/chrysom"
"github.com/xmidt-org/argus/model"
"github.com/xmidt-org/sallust"
"go.uber.org/zap"
)

func TestNewService(t *testing.T) {
tcs := []struct {
desc string
config Config
getLogger sallust.GetLoggerFunc
getLogger func(context.Context) *zap.Logger
expectedErr bool
}{
{
Expand Down
11 changes: 3 additions & 8 deletions transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"
"strings"
"time"
Expand All @@ -31,7 +31,6 @@ import (
"github.com/spf13/cast"
"github.com/xmidt-org/bascule/basculechecks"
"github.com/xmidt-org/httpaux/erraux"
"github.com/xmidt-org/sallust"
"go.uber.org/zap"

"github.com/xmidt-org/bascule"
Expand Down Expand Up @@ -99,7 +98,7 @@ func addWebhookRequestDecoder(config transportConfig) kithttp.DecodeRequestFunc
}

return func(c context.Context, r *http.Request) (request interface{}, err error) {
requestPayload, err := ioutil.ReadAll(r.Body)
requestPayload, err := io.ReadAll(r.Body)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -217,11 +216,7 @@ func (wv webhookValidator) setWebhookDefaults(webhook *Webhook, requestOriginHos

}

func errorEncoder(getLogger sallust.GetLoggerFunc) kithttp.ErrorEncoder {
if getLogger == nil {
getLogger = sallust.Get
}

func errorEncoder(getLogger func(context.Context) *zap.Logger) kithttp.ErrorEncoder {
return func(ctx context.Context, err error, w http.ResponseWriter) {
w.Header().Set(contentTypeHeader, jsonContentType)
code := http.StatusInternalServerError
Expand Down
3 changes: 2 additions & 1 deletion transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ import (
"github.com/stretchr/testify/require"
"github.com/xmidt-org/argus/store"
"github.com/xmidt-org/bascule"
"github.com/xmidt-org/sallust"
)

func TestErrorEncoder(t *testing.T) {
mockHandlerConfig := HandlerConfig{}
mockHandlerConfig := HandlerConfig{GetLogger: sallust.Get}

type testCase struct {
Description string
Expand Down

0 comments on commit 4a8e8fb

Please sign in to comment.