Skip to content

Commit

Permalink
Merge pull request #262 from xmidt-org/bascule-metrics-refactor
Browse files Browse the repository at this point in the history
Bug Fix: basculeHelper package Metrics function
  • Loading branch information
maurafortino committed Apr 26, 2023
2 parents 577ed92 + a22b2b9 commit 28599f9
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 19 deletions.
64 changes: 48 additions & 16 deletions basculehelper/basculeHelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ const (
NoCapabilityChecker = "no_capability_checker"
EmptyParsedURL = "empty_parsed_URL"
AuthCapabilityCheckOutcome = "auth_capability_check"
AuthValidationOutcome = "auth_validation"
capabilityCheckHelpMsg = "Counter for the capability checker, providing outcome information by client, partner, and endpoint"
EmptyCapabilitiesList = "empty_capabilities_list"
MissingValues = "auth_is_missing_values"
Expand All @@ -60,6 +59,16 @@ const (
EndpointLabel = "endpoint"
PartnerIDLabel = "partnerid"
ServerLabel = "server"

// Names for Auth Validation metrics
AuthValidationOutcome = "auth_validation"
NBFHistogram = "auth_from_nbf_seconds"
EXPHistogram = "auth_from_exp_seconds"

// Help messages for Auth Validation metrics
authValidationOutcomeHelpMsg = "Counter for success and failure reason results through bascule"
nbfHelpMsg = "Difference (in seconds) between time of JWT validation and nbf (including leeway)"
expHelpMsg = "Difference (in seconds) between time of JWT validation and exp (including leeway)"
)

// AuthCapabilityCheckMeasures describes the defined metrics that will be used by clients
Expand All @@ -75,6 +84,19 @@ func NewAuthCapabilityCheckMeasures(p provider.Provider) *AuthCapabilityCheckMea
}
}

// AuthCapabilitiesMetrics returns the Metrics relevant to this package targeting our older non uber/fx applications.
// To initialize the metrics, use NewAuthCapabilityCheckMeasures().
func AuthCapabilitiesMetrics() []xmetrics.Metric {
return []xmetrics.Metric{
{
Name: AuthCapabilityCheckOutcome,
Type: xmetrics.CounterType,
Help: capabilityCheckHelpMsg,
LabelNames: []string{OutcomeLabel, ReasonLabel, ClientIDLabel, PartnerIDLabel, EndpointLabel},
},
}
}

// AuthValidationMeasures describes the defined metrics that will be used by clients
type AuthValidationMeasures struct {
NBFHistogram metrics.Histogram
Expand All @@ -90,6 +112,31 @@ func NewAuthValidationMeasures(r xmetrics.Registry) *AuthValidationMeasures {
}
}

// AuthValidationMetrics returns the Metrics relevant to this package targeting our older non uber/fx applications.
// To initialize the metrics, use NewAuthValidationMeasures().
func AuthValidationMetrics() []xmetrics.Metric {
return []xmetrics.Metric{
{
Name: AuthValidationOutcome,
Type: xmetrics.CounterType,
Help: authValidationOutcomeHelpMsg,
LabelNames: []string{OutcomeLabel},
},
{
Name: NBFHistogram,
Type: xmetrics.HistogramType,
Help: nbfHelpMsg,
Buckets: []float64{-61, -11, -2, -1, 0, 9, 60}, // defines the upper inclusive (<=) bounds
},
{
Name: EXPHistogram,
Type: xmetrics.HistogramType,
Help: expHelpMsg,
Buckets: []float64{-61, -11, -2, -1, 0, 9, 60},
},
}
}

// MetricValidator determines if a request is authorized and then updates a
// metric to show those results.
type MetricValidator struct {
Expand Down Expand Up @@ -505,18 +552,3 @@ type ConstCheck string
func (c ConstCheck) Authorized(capability, _, _ string) bool {
return string(c) == capability
}

//Metric

// Metrics returns the Metrics relevant to this package targeting our older non uber/fx applications.
// To initialize the metrics, use NewAuthCapabilityCheckMeasures().
func Metrics() []xmetrics.Metric {
return []xmetrics.Metric{
{
Name: AuthCapabilityCheckOutcome,
Type: xmetrics.CounterType,
Help: capabilityCheckHelpMsg,
LabelNames: []string{OutcomeLabel, ReasonLabel, ClientIDLabel, PartnerIDLabel, EndpointLabel},
},
}
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/xmidt-org/scytale
go 1.19

require (
github.com/SermoDigital/jose v0.9.2-0.20161205224733-f6df55f235c2
github.com/go-kit/kit v0.12.0
github.com/go-kit/log v0.2.1
github.com/goph/emperror v0.17.3-0.20190703203600-60a8d9faa17b
Expand All @@ -22,13 +23,13 @@ require (
github.com/xmidt-org/webpa-common/v2 v2.0.7
github.com/xmidt-org/wrp-go/v3 v3.1.6
go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux v0.40.0
go.uber.org/multierr v1.11.0
go.uber.org/zap v1.24.0
)

require (
emperror.dev/emperror v0.33.0 // indirect
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.1 // indirect
github.com/aws/aws-sdk-go v1.44.103 // indirect
Expand Down Expand Up @@ -111,7 +112,6 @@ require (
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.11.0 // indirect
golang.org/x/crypto v0.2.0 // indirect
golang.org/x/mod v0.7.0 // indirect
golang.org/x/net v0.7.0 // indirect
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func scytale(arguments []string) int {
f = pflag.NewFlagSet(applicationName, pflag.ContinueOnError)
v = viper.New()

logger, metricsRegistry, webPA, err = server.Initialize(applicationName, arguments, f, v, webhook.Metrics, aws.Metrics, basculehelper.Metrics, basculehelper.Metrics, consul.Metrics, Metrics, service.Metrics)
logger, metricsRegistry, webPA, err = server.Initialize(applicationName, arguments, f, v, webhook.Metrics, aws.Metrics, basculehelper.AuthCapabilitiesMetrics, basculehelper.AuthValidationMetrics, consul.Metrics, Metrics, service.Metrics)
)

if parseErr, done := printVersion(f, arguments); done {
Expand Down

0 comments on commit 28599f9

Please sign in to comment.