Skip to content

Commit

Permalink
Build metric listener directly (#579)
Browse files Browse the repository at this point in the history
* no need to expose intermediary metrics

* add release notes

* update deps

* update code with latest candlelight changes
  • Loading branch information
joe94 authored May 12, 2021
1 parent 7f28b2e commit 381eb2a
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 24 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]
- Deprecate basculechecks and basculemetrics packages. [#578](https://github.com/xmidt-org/webpa-common/pull/578)
- Fix bug around metric listener creation in basculemetrics. [#579](https://github.com/xmidt-org/webpa-common/pull/579)

## [v1.11.6]
- Use updated Argus client with OpenTelemetry integration. [#573](https://github.com/xmidt-org/webpa-common/pull/573) thanks to @utsavbatra5
Expand Down
21 changes: 11 additions & 10 deletions basculemetrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,13 @@ type BaseMeasuresIn struct {
ValidationOutcome *prometheus.CounterVec `name:"auth_validation"`
}

// MeasuresFactory facilitates the creation of child metrics based on server labels.
type MeasuresFactory struct {
// ListenerFactory facilitates the creation of a server-aware metric listener.
type ListenerFactory struct {
ServerName string
}

// NewMeasures builds the metric listener from the provided raw metrics.
func (m MeasuresFactory) NewMeasures(in BaseMeasuresIn) (*AuthValidationMeasures, error) {
// New builds the metric listener from the provided metrics.
func (m ListenerFactory) New(in BaseMeasuresIn) (*MetricListener, error) {
in.Logger.Log(level.Key(), level.DebugValue(), xlog.MessageKey(), "building auth validation measures", ServerLabel, m.ServerName)
nbfHistogramVec, err := in.NBFHistogram.CurryWith(prometheus.Labels{ServerLabel: m.ServerName})
if err != nil {
Expand All @@ -155,17 +155,18 @@ func (m MeasuresFactory) NewMeasures(in BaseMeasuresIn) (*AuthValidationMeasures
return nil, err
}

return &AuthValidationMeasures{
measures := &AuthValidationMeasures{
NBFHistogram: gokitprometheus.NewHistogram(nbfHistogramVec.(*prometheus.HistogramVec)),
ExpHistogram: gokitprometheus.NewHistogram(expHistogramVec.(*prometheus.HistogramVec)),
ValidationOutcome: gokitprometheus.NewCounter(validationOutcomeCounterVec),
}, nil
}
return NewMetricListener(measures), nil
}

// Annotated provides the measures as an annotated component with the name "[SERVER]_bascule_validation_measures"
func (m MeasuresFactory) Annotated() fx.Annotated {
// Annotated provides the listener as an annotated component with the name "[SERVER]_bascule_metric_listener"
func (m ListenerFactory) Annotated() fx.Annotated {
return fx.Annotated{
Name: fmt.Sprintf("%s_bascule_validation_measures", m.ServerName),
Target: m.NewMeasures,
Name: fmt.Sprintf("%s_bascule_metric_listener", m.ServerName),
Target: m.New,
}
}
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ require (
github.com/davecgh/go-spew v1.1.1
github.com/go-kit/kit v0.10.0
github.com/goph/emperror v0.17.3-0.20190703203600-60a8d9faa17b
github.com/gorilla/mux v1.7.4
github.com/gorilla/mux v1.8.0
github.com/gorilla/schema v1.0.3-0.20180614150749-e0e4b92809ac
github.com/gorilla/websocket v1.4.2
github.com/hashicorp/consul/api v1.7.0
github.com/jtacoma/uritemplates v1.0.0
github.com/justinas/alice v1.2.0
github.com/miekg/dns v1.1.26
github.com/mitchellh/mapstructure v1.3.3
github.com/prometheus/client_golang v1.4.1
github.com/prometheus/client_golang v1.10.0
github.com/rubyist/circuitbreaker v2.2.0+incompatible
github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da
github.com/segmentio/ksuid v1.0.2
Expand All @@ -27,10 +27,10 @@ require (
github.com/spf13/viper v1.7.1
github.com/stretchr/testify v1.7.0
github.com/ugorji/go/codec v1.1.7
github.com/xmidt-org/argus v0.3.14
github.com/xmidt-org/bascule v0.9.0
github.com/xmidt-org/candlelight v0.0.4
github.com/xmidt-org/themis v0.4.4
github.com/xmidt-org/argus v0.3.16-0.20210510235618-dc9d9b848b40
github.com/xmidt-org/bascule v0.9.1-0.20210506212507-4df8762472bc
github.com/xmidt-org/candlelight v0.0.5
github.com/xmidt-org/themis v0.4.7
github.com/xmidt-org/wrp-go/v3 v3.0.1
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.19.0
go.uber.org/fx v1.13.1
Expand Down
Loading

0 comments on commit 381eb2a

Please sign in to comment.