Files
atlantis/server/events/instrumented_project_command_builder.go
Fabiano Soares Honorato 6a7f79e749 Metrics initialization (#2767)
* Add builder metrics initialization

* Add pull_closed metrics initialization

* Add builder metrics initialization

* use InitCounter from metrics package to initialize prometheus counters
2022-12-16 22:22:06 -06:00

73 lines
2.1 KiB
Go

package events
import (
"github.com/runatlantis/atlantis/server/events/command"
"github.com/runatlantis/atlantis/server/logging"
"github.com/runatlantis/atlantis/server/metrics"
"github.com/uber-go/tally"
)
type InstrumentedProjectCommandBuilder struct {
ProjectCommandBuilder
Logger logging.SimpleLogging
scope tally.Scope
}
func (b *InstrumentedProjectCommandBuilder) BuildApplyCommands(ctx *command.Context, comment *CommentCommand) ([]command.ProjectContext, error) {
timer := b.scope.Timer(metrics.ExecutionTimeMetric).Start()
defer timer.Stop()
executionSuccess := b.scope.Counter(metrics.ExecutionSuccessMetric)
executionError := b.scope.Counter(metrics.ExecutionErrorMetric)
projectCmds, err := b.ProjectCommandBuilder.BuildApplyCommands(ctx, comment)
if err != nil {
executionError.Inc(1)
b.Logger.Err("Error building apply commands: %s", err)
} else {
executionSuccess.Inc(1)
}
return projectCmds, err
}
func (b *InstrumentedProjectCommandBuilder) BuildAutoplanCommands(ctx *command.Context) ([]command.ProjectContext, error) {
timer := b.scope.Timer(metrics.ExecutionTimeMetric).Start()
defer timer.Stop()
executionSuccess := b.scope.Counter(metrics.ExecutionSuccessMetric)
executionError := b.scope.Counter(metrics.ExecutionErrorMetric)
projectCmds, err := b.ProjectCommandBuilder.BuildAutoplanCommands(ctx)
if err != nil {
executionError.Inc(1)
b.Logger.Err("Error building auto plan commands: %s", err)
} else {
executionSuccess.Inc(1)
}
return projectCmds, err
}
func (b *InstrumentedProjectCommandBuilder) BuildPlanCommands(ctx *command.Context, comment *CommentCommand) ([]command.ProjectContext, error) {
timer := b.scope.Timer(metrics.ExecutionTimeMetric).Start()
defer timer.Stop()
executionSuccess := b.scope.Counter(metrics.ExecutionSuccessMetric)
executionError := b.scope.Counter(metrics.ExecutionErrorMetric)
projectCmds, err := b.ProjectCommandBuilder.BuildPlanCommands(ctx, comment)
if err != nil {
executionError.Inc(1)
b.Logger.Err("Error building plan commands: %s", err)
} else {
executionSuccess.Inc(1)
}
return projectCmds, err
}