Documentation ¶
Index ¶
- Constants
- Variables
- func Metrics() []xmetrics.Metric
- func Provide() fx.Option
- func ProvideMetrics() fx.Option
- type Acquirer
- type BasicConfig
- type BasicRegisterer
- type Measures
- type MeasuresIn
- type PeriodicRegisterer
- type PeriodicRegistererIn
- type ReasonCode
- type ReasonCoder
- type Registerer
- type SecretGetter
Constants ¶
const ( DefaultContentType = "wrp" DefaultDeviceRegexp = ".*" DefaultTimeout = 10 * time.Second )
const ( OutcomeLabel = "outcome" ReasonLabel = "reason" )
labels
const ( // outcomes SuccessOutcome = "success" FailureOutcome = "failure" )
const (
WebhookRegistrationOutcome = "webhook_registration"
)
Names for our metrics
Variables ¶
Functions ¶
func Provide ¶ added in v0.2.2
Provide bundles all of the constructors needed to create a new periodic registerer.
func ProvideMetrics ¶ added in v0.2.2
ProvideMetrics provides the metrics relevant to this package as uber/fx options.
Types ¶
type Acquirer ¶
Acquirer gets an Authorization value that can be added to an http request. The format of the string returned should be the key, a space, and then the auth string.
type BasicConfig ¶
type BasicConfig struct { Timeout time.Duration ClientTransport http.RoundTripper RegistrationURL string Request webhook.W }
BasicConfig holds the configuration options for setting up a BasicRegisterer.
type BasicRegisterer ¶
type BasicRegisterer struct {
// contains filtered or unexported fields
}
BasicRegisterer sends POST requests to register at the webhook URL provided.
func NewBasicRegisterer ¶
func NewBasicRegisterer(acquirer Acquirer, secret SecretGetter, config BasicConfig) (*BasicRegisterer, error)
NewBasicRegisterer returns a basic registerer set up with the configuration given. If the acquirer or secretGetter are nil or certain configurations are empty, an error will be returned. Otherwise, some config values are set to defaults if they are invalid and a basic registerer is returned.
func (*BasicRegisterer) Register ¶
func (b *BasicRegisterer) Register() error
Register registers to the webhook using the information the basic registerer has.
type Measures ¶ added in v0.2.0
Measures describes the defined metrics that will be used by clients.
func NewMeasures ¶ added in v0.2.0
NewMeasures realizes desired metrics.
type MeasuresIn ¶ added in v0.2.2
type MeasuresIn struct { fx.In WebhookRegistrationOutcome metrics.Counter `name:"webhook_registration"` }
MeasuresIn is an uber/fx parameter with the webhook registration counter
type PeriodicRegisterer ¶
type PeriodicRegisterer struct {
// contains filtered or unexported fields
}
PeriodicRegisterer uses a register to attempt to register at an interval. If there is a failure, it will be logged.
func NewPeriodicRegisterer ¶
func NewPeriodicRegisterer(registerer Registerer, interval time.Duration, logger *zap.Logger, measures *Measures) (*PeriodicRegisterer, error)
NewPeriodicRegisterer creates a registerer that attempts to register at the interval given.
func (*PeriodicRegisterer) Register ¶
func (p *PeriodicRegisterer) Register() error
Register is just a wrapper to provide the regular Register functionality, but generally the periodic registerer should be started and stopped.
func (*PeriodicRegisterer) Start ¶
func (p *PeriodicRegisterer) Start()
Start begins the periodic webhook registration.
func (*PeriodicRegisterer) Stop ¶
func (p *PeriodicRegisterer) Stop()
Stop stops the periodic webhook registration.
type PeriodicRegistererIn ¶ added in v0.2.2
type PeriodicRegistererIn struct { fx.In Registerer *BasicRegisterer Interval time.Duration `name:"periodic_registration_interval"` Logger *zap.Logger Measures *Measures }
PeriodicRegistererIn is an uber/fx parameter with the in information needed to create a new PeriodicRegisterer.
type ReasonCode ¶ added in v0.2.0
type ReasonCode int
ReasonCode is a way to describe what went wrong when trying to register for a webhook.
const ( UnknownReason ReasonCode = iota GetSecretFail MarshalRequestFail AcquireJWTFail CreateRequestFail DoRequestFail ReadBodyFail Non200Response )
func GetReasonCode ¶ added in v0.2.0
func GetReasonCode(v interface{}) ReasonCode
GetReasonCode returns the ReasonCode if the object is a ReasonCoder. Otherwise, it returns UnknownReason.
func (ReasonCode) LabelValue ¶ added in v0.2.0
func (rc ReasonCode) LabelValue() string
LabelValue returns the metric label value for this reason code, or unknown if it's some wacky value.
type ReasonCoder ¶ added in v0.2.0
type ReasonCoder interface {
ReasonCode() ReasonCode
}
ReasonCoder is anything that can return a ReasonCode.
type Registerer ¶
type Registerer interface {
Register() error
}
A Registerer attempts to register to a webhook. If there is a problem, an error is returned.
type SecretGetter ¶
SecretGetter gets the secret to use when hashing. If getting the secret is unsuccessful, an error can be returned.