metrix: implemented meter.count

pull/1688/head
Panagiotis Siatras 5 months ago
parent f4fd83b83e
commit de98f25df4
No known key found for this signature in database

@ -83,7 +83,7 @@ type Config struct {
Templates *templates.Templates `json:"templates,omitempty"`
CommonName string `json:"commonName,omitempty"`
CRL *CRLConfig `json:"crl,omitempty"`
MetricsAddr string `json:"metricsAddress,omitempty"`
MetricsAddress string `json:"metricsAddress,omitempty"`
SkipValidation bool `json:"-"`
// Keeps record of the filename the Config is read from
@ -328,7 +328,7 @@ func (c *Config) Validate() error {
return errors.Errorf("invalid address %s", c.Address)
}
if addr := c.MetricsAddr; addr != "" {
if addr := c.MetricsAddress; addr != "" {
if _, _, err := net.SplitHostPort(addr); err != nil {
return errors.Errorf("invalid metrics address %s", c.Address)
}

@ -24,12 +24,9 @@ type Meter interface {
// noopMeter implements a noop [Meter].
type noopMeter struct{}
func (noopMeter) X509Signed(string, bool) {}
func (noopMeter) SSHRekeyed(string, bool) {}
func (noopMeter) SSHRenewed(string, bool) {}
func (noopMeter) SSHSigned(string, bool) {}
func (noopMeter) X509Rekeyed(string, bool) {}
func (noopMeter) X509Renewed(string, bool) {}
func (noopMeter) SSHSigned(string, bool) {}
func (noopMeter) SSHRenewed(string, bool) {}
func (noopMeter) SSHRekeyed(string, bool) {}
func (noopMeter) X509Signed(string, bool) {}

@ -191,6 +191,8 @@ func (a *Authority) SignSSH(_ context.Context, key ssh.PublicKey, opts provision
// validate the given SSHOptions
case provisioner.SSHCertOptionsValidator:
if err := o.Valid(opts); err != nil {
measure(false)
return nil, errs.BadRequestErr(err, "error validating ssh certificate options")
}

@ -139,6 +139,8 @@ func (a *Authority) Sign(csr *x509.CertificateRequest, signOpts provisioner.Sign
// Validate the given certificate request.
case provisioner.CertificateRequestValidator:
if err := k.Valid(csr); err != nil {
measure(false)
return nil, errs.ApplyOptions(
errs.ForbiddenErr(err, "error validating certificate request"),
opts...,

@ -166,7 +166,7 @@ func (ca *CA) Init(cfg *config.Config) (*CA, error) {
}
var meter *metrix.Meter
if ca.config.MetricsAddr != "" {
if ca.config.MetricsAddress != "" {
meter = metrix.New()
opts = append(opts, authority.WithMeter(meter))
@ -328,7 +328,7 @@ func (ca *CA) Init(cfg *config.Config) (*CA, error) {
}
if meter != nil {
ca.metricsSrv = server.New(ca.config.MetricsAddr, meter, nil)
ca.metricsSrv = server.New(ca.config.MetricsAddress, meter, nil)
ca.metricsSrv.BaseContext = func(net.Listener) context.Context {
return baseContext
}

@ -83,32 +83,36 @@ type signatures struct {
// SSHRekeyed implements [authority.Meter] for [Meter].
func (m *Meter) SSHRekeyed(provisioner string, success bool) {
m.ssh.rekeyed.WithLabelValues(provisioner, strconv.FormatBool(success)).Inc()
m.count(m.ssh.rekeyed, provisioner, success)
}
// SSHRenewed implements [authority.Meter] for [Meter].
func (m *Meter) SSHRenewed(provisioner string, success bool) {
m.ssh.renewed.WithLabelValues(provisioner, strconv.FormatBool(success)).Inc()
m.count(m.ssh.renewed, provisioner, success)
}
// SSHSigned implements [authority.Meter] for [Meter].
func (m *Meter) SSHSigned(provisioner string, success bool) {
m.ssh.signed.WithLabelValues(provisioner, strconv.FormatBool(success)).Inc()
m.count(m.ssh.signed, provisioner, success)
}
// X509Rekeyed implements [authority.Meter] for [Meter].
func (m *Meter) X509Rekeyed(provisioner string, success bool) {
m.x509.rekeyed.WithLabelValues(provisioner, strconv.FormatBool(success)).Inc()
m.count(m.x509.rekeyed, provisioner, success)
}
// X509Renewed implements [authority.Meter] for [Meter].
func (m *Meter) X509Renewed(provisioner string, success bool) {
m.x509.renewed.WithLabelValues(provisioner, strconv.FormatBool(success)).Inc()
m.count(m.x509.renewed, provisioner, success)
}
// X509Signed implements [authority.Meter] for [Meter].
func (m *Meter) X509Signed(provisioner string, success bool) {
m.x509.signed.WithLabelValues(provisioner, strconv.FormatBool(success)).Inc()
m.count(m.x509.signed, provisioner, success)
}
func (*Meter) count(cv *prometheus.CounterVec, provisioner string, success bool) {
cv.WithLabelValues(provisioner, strconv.FormatBool(success)).Inc()
}
func newCounterVec(subsystem, name, help string, labels ...string) *prometheus.CounterVec {

Loading…
Cancel
Save