Skip to content

Find, verify, and analyze leaked credentials

Add prometheus metrics to measure hook execution time (#2312)

Miccah2d96b895548c
diff --git a/pkg/sources/job_progress.go b/pkg/sources/job_progress.go
index d7bbc5b83..029e758fa 100644
--- a/pkg/sources/job_progress.go
+++ b/pkg/sources/job_progress.go
@@ -183,6 +183,10 @@ func (jp *JobProgress) TrackProgress(progress *Progress) {
// executeHooks is a helper method to execute all the hooks for the given
// closure.
func (jp *JobProgress) executeHooks(todo func(hook JobProgressHook)) {
+ defer func(start time.Time) {
+ elapsed := time.Since(start).Milliseconds()
+ hooksExecTime.WithLabelValues().Observe(float64(elapsed))
+ }(time.Now())
for _, hook := range jp.hooks {
// TODO: Non-blocking?
todo(hook)
diff --git a/pkg/sources/metrics.go b/pkg/sources/metrics.go
new file mode 100644
index 000000000..158059da7
--- /dev/null
+++ b/pkg/sources/metrics.go
@@ -0,0 +1,17 @@
+package sources
+
+import (
+ "github.com/prometheus/client_golang/prometheus"
+ "github.com/prometheus/client_golang/prometheus/promauto"
+ "github.com/trufflesecurity/trufflehog/v3/pkg/common"
+)
+
+var (
+ hooksExecTime = promauto.NewHistogramVec(prometheus.HistogramOpts{
+ Namespace: common.MetricsNamespace,
+ Subsystem: common.MetricsSubsystem,
+ Name: "hooks_exec_time_ms",
+ Help: "Time spent executing hooks (ms)",
+ Buckets: []float64{5, 50, 500, 1000},
+ }, nil)
+)