瀏覽代碼

fix: Webhook-related instruments

* fix: also instrument webhooks that do not reach the wire
* fix: register the webhook instrumentation
Panagiotis Siatras 2 年之前
父節點
當前提交
fb4cd6fe81
共有 3 個文件被更改,包括 8 次插入 和 8 次删除
  1. 2 4
      authority/ssh.go
  2. 2 4
      authority/tls.go
  3. 4 0
      internal/metrix/meter.go

+ 2 - 4
authority/ssh.go

@@ -675,14 +675,13 @@ func (a *Authority) callEnrichingWebhooksSSH(ctx context.Context, prov provision
 	if webhookCtl == nil {
 	if webhookCtl == nil {
 		return
 		return
 	}
 	}
+	defer func() { a.meter.SSHWebhookEnriched(prov, err) }()
 
 
 	var whEnrichReq *webhook.RequestBody
 	var whEnrichReq *webhook.RequestBody
 	if whEnrichReq, err = webhook.NewRequestBody(
 	if whEnrichReq, err = webhook.NewRequestBody(
 		webhook.WithSSHCertificateRequest(cr),
 		webhook.WithSSHCertificateRequest(cr),
 	); err == nil {
 	); err == nil {
 		err = webhookCtl.Enrich(ctx, whEnrichReq)
 		err = webhookCtl.Enrich(ctx, whEnrichReq)
-
-		a.meter.SSHWebhookEnriched(prov, err)
 	}
 	}
 
 
 	return
 	return
@@ -692,14 +691,13 @@ func (a *Authority) callAuthorizingWebhooksSSH(ctx context.Context, prov provisi
 	if webhookCtl == nil {
 	if webhookCtl == nil {
 		return
 		return
 	}
 	}
+	defer func() { a.meter.SSHWebhookAuthorized(prov, err) }()
 
 
 	var whAuthBody *webhook.RequestBody
 	var whAuthBody *webhook.RequestBody
 	if whAuthBody, err = webhook.NewRequestBody(
 	if whAuthBody, err = webhook.NewRequestBody(
 		webhook.WithSSHCertificate(cert, certTpl),
 		webhook.WithSSHCertificate(cert, certTpl),
 	); err == nil {
 	); err == nil {
 		err = webhookCtl.Authorize(ctx, whAuthBody)
 		err = webhookCtl.Authorize(ctx, whAuthBody)
-
-		a.meter.SSHWebhookAuthorized(prov, err)
 	}
 	}
 
 
 	return
 	return

+ 2 - 4
authority/tls.go

@@ -999,6 +999,7 @@ func (a *Authority) callEnrichingWebhooksX509(ctx context.Context, prov provisio
 	if webhookCtl == nil {
 	if webhookCtl == nil {
 		return
 		return
 	}
 	}
+	defer func() { a.meter.X509WebhookEnriched(prov, err) }()
 
 
 	var attested *webhook.AttestationData
 	var attested *webhook.AttestationData
 	if attData != nil {
 	if attData != nil {
@@ -1013,8 +1014,6 @@ func (a *Authority) callEnrichingWebhooksX509(ctx context.Context, prov provisio
 		webhook.WithAttestationData(attested),
 		webhook.WithAttestationData(attested),
 	); err == nil {
 	); err == nil {
 		err = webhookCtl.Enrich(ctx, whEnrichReq)
 		err = webhookCtl.Enrich(ctx, whEnrichReq)
-
-		a.meter.X509WebhookEnriched(prov, err)
 	}
 	}
 
 
 	return
 	return
@@ -1024,6 +1023,7 @@ func (a *Authority) callAuthorizingWebhooksX509(ctx context.Context, prov provis
 	if webhookCtl == nil {
 	if webhookCtl == nil {
 		return
 		return
 	}
 	}
+	defer func() { a.meter.X509WebhookAuthorized(prov, err) }()
 
 
 	var attested *webhook.AttestationData
 	var attested *webhook.AttestationData
 	if attData != nil {
 	if attData != nil {
@@ -1038,8 +1038,6 @@ func (a *Authority) callAuthorizingWebhooksX509(ctx context.Context, prov provis
 		webhook.WithAttestationData(attested),
 		webhook.WithAttestationData(attested),
 	); err == nil {
 	); err == nil {
 		err = webhookCtl.Authorize(ctx, whAuthBody)
 		err = webhookCtl.Authorize(ctx, whAuthBody)
-
-		a.meter.X509WebhookAuthorized(prov, err)
 	}
 	}
 
 
 	return
 	return

+ 4 - 0
internal/metrix/meter.go

@@ -42,9 +42,13 @@ func New() (m *Meter) {
 		m.ssh.rekeyed,
 		m.ssh.rekeyed,
 		m.ssh.renewed,
 		m.ssh.renewed,
 		m.ssh.signed,
 		m.ssh.signed,
+		m.ssh.webhookAuthorized,
+		m.ssh.webhookEnriched,
 		m.x509.rekeyed,
 		m.x509.rekeyed,
 		m.x509.renewed,
 		m.x509.renewed,
 		m.x509.signed,
 		m.x509.signed,
+		m.x509.webhookAuthorized,
+		m.x509.webhookEnriched,
 		m.kms.signed,
 		m.kms.signed,
 		m.kms.errors,
 		m.kms.errors,
 	)
 	)