tenseleyflow/shithub / 26489d3

Browse files

metrics: actions trigger counters + match-duration histogram (S41b)

Adds two metrics per the S41 campaign's observability commitments:

- shithub_actions_runs_enqueued_total{event,result}
Incremented in trigger.Enqueue. Result is 'fresh' for newly
inserted runs or 'already_exists' when ON CONFLICT DO NOTHING
fired (worker retry / admin replay landing on the same
trigger_event_id). Lets dashboards show the dedup-effectiveness.

- shithub_actions_trigger_match_duration_seconds (histogram)
Wall-clock time the trigger handler spends discovering +
parsing + matching workflows for one triggering event. The
'HEAD scan cost' pitfall in the sprint spec — alert when p95
drifts up.

Both register against the shared metrics.Registry. Instrumentation
sites: enqueue.Enqueue (counter) and handler.Handler (histogram via
deferred Observe so the timer covers the entire match loop).
Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
26489d394b97557e272ff309716b4f527d96fa36
Parents
802a1c3
Tree
0a89b9a

3 changed files

StatusFile+-
M internal/actions/trigger/enqueue.go 3 0
M internal/actions/trigger/handler.go 7 0
M internal/infra/metrics/metrics.go 21 0
internal/actions/trigger/enqueue.gomodified
@@ -17,6 +17,7 @@ import (
1717
 	actionsdb "github.com/tenseleyFlow/shithub/internal/actions/sqlc"
1818
 	"github.com/tenseleyFlow/shithub/internal/actions/workflow"
1919
 	"github.com/tenseleyFlow/shithub/internal/checks"
20
+	"github.com/tenseleyFlow/shithub/internal/infra/metrics"
2021
 )
2122
 
2223
 // Deps wires the trigger pipeline against runtime infra.
@@ -167,6 +168,7 @@ func Enqueue(ctx context.Context, deps Deps, p EnqueueParams) (Result, error) {
167168
 			if lookupErr != nil {
168169
 				return Result{}, fmt.Errorf("trigger: existing-run lookup: %w", lookupErr)
169170
 			}
171
+			metrics.ActionsRunsEnqueuedTotal.WithLabelValues(string(p.EventKind), "already_exists").Inc()
170172
 			return Result{
171173
 				RunID:         existing.ID,
172174
 				RunIndex:      existing.RunIndex,
@@ -272,6 +274,7 @@ func Enqueue(ctx context.Context, deps Deps, p EnqueueParams) (Result, error) {
272274
 		_ = jobIDs[i] // job_id linkage to check_run lands in S41c when the runner consumes both
273275
 	}
274276
 
277
+	metrics.ActionsRunsEnqueuedTotal.WithLabelValues(string(p.EventKind), "fresh").Inc()
275278
 	return Result{
276279
 		RunID:       run.ID,
277280
 		RunIndex:    run.RunIndex,
internal/actions/trigger/handler.gomodified
@@ -7,11 +7,13 @@ import (
77
 	"encoding/json"
88
 	"errors"
99
 	"fmt"
10
+	"time"
1011
 
1112
 	"github.com/jackc/pgx/v5"
1213
 	"github.com/jackc/pgx/v5/pgxpool"
1314
 
1415
 	"github.com/tenseleyFlow/shithub/internal/actions/workflow"
16
+	"github.com/tenseleyFlow/shithub/internal/infra/metrics"
1517
 	"github.com/tenseleyFlow/shithub/internal/infra/storage"
1618
 	orgsdb "github.com/tenseleyFlow/shithub/internal/orgs/sqlc"
1719
 	reposdb "github.com/tenseleyFlow/shithub/internal/repos/sqlc"
@@ -105,6 +107,11 @@ func Handler(deps JobDeps) worker.Handler {
105107
 			return fmt.Errorf("trigger: repo path: %w", err)
106108
 		}
107109
 
110
+		matchStart := time.Now()
111
+		defer func() {
112
+			metrics.ActionsTriggerMatchDurationSeconds.Observe(time.Since(matchStart).Seconds())
113
+		}()
114
+
108115
 		files, skips, err := Discover(ctx, gitDir, p.HeadSHA)
109116
 		if err != nil {
110117
 			return fmt.Errorf("trigger: discover: %w", err)
internal/infra/metrics/metrics.gomodified
@@ -112,6 +112,25 @@ var (
112112
 	)
113113
 )
114114
 
115
+// Actions trigger pipeline metrics (S41b). Incremented from
116
+// internal/actions/trigger.
117
+var (
118
+	ActionsRunsEnqueuedTotal = prometheus.NewCounterVec(
119
+		prometheus.CounterOpts{
120
+			Name: "shithub_actions_runs_enqueued_total",
121
+			Help: "Total workflow runs enqueued by triggering event kind. Result is 'fresh' for new runs or 'already_exists' when ON CONFLICT noop'd.",
122
+		},
123
+		[]string{"event", "result"},
124
+	)
125
+	ActionsTriggerMatchDurationSeconds = prometheus.NewHistogram(
126
+		prometheus.HistogramOpts{
127
+			Name:    "shithub_actions_trigger_match_duration_seconds",
128
+			Help:    "Wall-clock time spent in the trigger handler discovering + parsing + matching workflows for one triggering event.",
129
+			Buckets: prometheus.ExponentialBuckets(0.005, 2.0, 12),
130
+		},
131
+	)
132
+)
133
+
115134
 func init() {
116135
 	Registry.MustRegister(
117136
 		HTTPRequestsTotal,
@@ -125,6 +144,8 @@ func init() {
125144
 		WorkerJobsProcessedTotal,
126145
 		WorkerJobDurationSeconds,
127146
 		WorkerInFlight,
147
+		ActionsRunsEnqueuedTotal,
148
+		ActionsTriggerMatchDurationSeconds,
128149
 	)
129150
 }
130151