Files
atlantis/server/events/instrumented_project_command_builder.go
Sarvar Muminov 90e92e3a13 chore: move CommandContext and CommandResult to models (#193) (#2093)
* Moved CommandContext and CommandResult to models (#193)

* Moved CommandContext and CommandResult to models

* move from models to command

rename CommandContext -> Context
rename CommandResult -> Result

* moved command related helpers into command package

* move ProjectCommandContext and ProjectResult to command/project package

* move project command context and project result

* revert unrelated code

* move tests

* fix left over

* fix linting

* fix tests

* remove unused import

* fix project context dependencies

* fix depenedecies

* fix typo
2022-03-21 10:36:13 -07:00

77 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"
)
type InstrumentedProjectCommandBuilder struct {
ProjectCommandBuilder
Logger logging.SimpleLogging
}
func (b *InstrumentedProjectCommandBuilder) BuildApplyCommands(ctx *command.Context, comment *CommentCommand) ([]command.ProjectContext, error) {
scope := ctx.Scope.SubScope("builder")
timer := scope.Timer(metrics.ExecutionTimeMetric).Start()
defer timer.Stop()
executionSuccess := scope.Counter(metrics.ExecutionSuccessMetric)
executionError := 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) {
scope := ctx.Scope.SubScope("builder")
timer := scope.Timer(metrics.ExecutionTimeMetric).Start()
defer timer.Stop()
executionSuccess := scope.Counter(metrics.ExecutionSuccessMetric)
executionError := 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) {
scope := ctx.Scope.SubScope("builder")
timer := scope.Timer(metrics.ExecutionTimeMetric).Start()
defer timer.Stop()
executionSuccess := scope.Counter(metrics.ExecutionSuccessMetric)
executionError := 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
}