Files
atlantis/server/events/instrumented_pull_closed_executor.go
Alberto Llamas 9829fa23c2 Fix: Error when enabling prometheus metrics (#2379) (#2528)
Prometheus metrics names have some restrictions that must match the regex `[a-zA-Z_:][a-zA-Z0-9_:]*`
2022-09-20 21:27:30 -07:00

54 lines
1.2 KiB
Go

package events
import (
"strconv"
"github.com/runatlantis/atlantis/server/events/models"
"github.com/runatlantis/atlantis/server/logging"
"github.com/runatlantis/atlantis/server/metrics"
"github.com/uber-go/tally"
)
type InstrumentedPullClosedExecutor struct {
scope tally.Scope
log logging.SimpleLogging
cleaner PullCleaner
}
func NewInstrumentedPullClosedExecutor(
scope tally.Scope, log logging.SimpleLogging, cleaner PullCleaner,
) PullCleaner {
return &InstrumentedPullClosedExecutor{
scope: scope.SubScope("pullclosed_cleanup"),
log: log,
cleaner: cleaner,
}
}
func (e *InstrumentedPullClosedExecutor) CleanUpPull(repo models.Repo, pull models.PullRequest) error {
log := e.log.With(
"repository", repo.FullName,
"pull-num", strconv.Itoa(pull.Num),
)
executionSuccess := e.scope.Counter(metrics.ExecutionSuccessMetric)
executionError := e.scope.Counter(metrics.ExecutionErrorMetric)
executionTime := e.scope.Timer(metrics.ExecutionTimeMetric).Start()
defer executionTime.Stop()
log.Info("Initiating cleanup of pull data.")
err := e.cleaner.CleanUpPull(repo, pull)
if err != nil {
executionError.Inc(1)
log.Err("error during cleanup of pull data", err)
return err
}
executionSuccess.Inc(1)
return nil
}