From 1faab44aa4f8d882b9e1feb2dc201c582b4c0703 Mon Sep 17 00:00:00 2001 From: TJ Hoplock Date: Fri, 9 Aug 2024 14:00:42 -0400 Subject: [PATCH] fix(metrics): always increment module run metric for test runs If a test script exists and we're asked to run it, always increment the total module runs for the script, regardless of whether it errors or fails -- we were still asked to run it and the count should reflect that. --- internal/manager/module.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/manager/module.go b/internal/manager/module.go index 6b8ac9a..e56f1e0 100644 --- a/internal/manager/module.go +++ b/internal/manager/module.go @@ -146,6 +146,8 @@ func (mgr *Manager) RunModule(ctx context.Context, logger *slog.Logger, mod Modu } testRC, err = shell.Run(ctx, runID, mod.m.Test, renderedTest, allVars) + // update metrics regardless of error, so do them before handling error + metricManagerModuleRunTotal.With(labels).Inc() switch { case err != nil: // if test script for a module fails, log a warning for user and continue with apply @@ -166,7 +168,6 @@ func (mgr *Manager) RunModule(ctx context.Context, logger *slog.Logger, mod Modu slog.Any("exit_code", testRC), ) default: - metricManagerModuleRunTotal.With(labels).Inc() metricManagerModuleRunSuccessTimestamp.With(labels).Set(float64(testStart.Unix())) }