|
| 1 | +package events |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/runatlantis/atlantis/server/events/metrics" |
| 5 | + "github.com/runatlantis/atlantis/server/events/models" |
| 6 | + "github.com/runatlantis/atlantis/server/logging" |
| 7 | +) |
| 8 | + |
| 9 | +type InstrumentedProjectCommandBuilder struct { |
| 10 | + ProjectCommandBuilder |
| 11 | + Logger logging.SimpleLogging |
| 12 | +} |
| 13 | + |
| 14 | +func (b *InstrumentedProjectCommandBuilder) BuildApplyCommands(ctx *CommandContext, comment *CommentCommand) ([]models.ProjectCommandContext, error) { |
| 15 | + scope := ctx.Scope.Scope("builder") |
| 16 | + |
| 17 | + timer := scope.NewTimer(metrics.ExecutionTimeMetric).AllocateSpan() |
| 18 | + defer timer.Complete() |
| 19 | + |
| 20 | + executionSuccess := scope.NewCounter(metrics.ExecutionSuccessMetric) |
| 21 | + executionError := scope.NewCounter(metrics.ExecutionErrorMetric) |
| 22 | + |
| 23 | + projectCmds, err := b.ProjectCommandBuilder.BuildApplyCommands(ctx, comment) |
| 24 | + |
| 25 | + if err != nil { |
| 26 | + executionError.Inc() |
| 27 | + b.Logger.Err("Error building apply commands: %s", err) |
| 28 | + } else { |
| 29 | + executionSuccess.Inc() |
| 30 | + } |
| 31 | + |
| 32 | + return projectCmds, err |
| 33 | + |
| 34 | +} |
| 35 | +func (b *InstrumentedProjectCommandBuilder) BuildAutoplanCommands(ctx *CommandContext) ([]models.ProjectCommandContext, error) { |
| 36 | + scope := ctx.Scope.Scope("builder") |
| 37 | + |
| 38 | + timer := scope.NewTimer(metrics.ExecutionTimeMetric).AllocateSpan() |
| 39 | + defer timer.Complete() |
| 40 | + |
| 41 | + executionSuccess := scope.NewCounter(metrics.ExecutionSuccessMetric) |
| 42 | + executionError := scope.NewCounter(metrics.ExecutionErrorMetric) |
| 43 | + |
| 44 | + projectCmds, err := b.ProjectCommandBuilder.BuildAutoplanCommands(ctx) |
| 45 | + |
| 46 | + if err != nil { |
| 47 | + executionError.Inc() |
| 48 | + b.Logger.Err("Error building auto plan commands: %s", err) |
| 49 | + } else { |
| 50 | + executionSuccess.Inc() |
| 51 | + } |
| 52 | + |
| 53 | + return projectCmds, err |
| 54 | + |
| 55 | +} |
| 56 | +func (b *InstrumentedProjectCommandBuilder) BuildPlanCommands(ctx *CommandContext, comment *CommentCommand) ([]models.ProjectCommandContext, error) { |
| 57 | + scope := ctx.Scope.Scope("builder") |
| 58 | + |
| 59 | + timer := scope.NewTimer(metrics.ExecutionTimeMetric).AllocateSpan() |
| 60 | + defer timer.Complete() |
| 61 | + |
| 62 | + executionSuccess := scope.NewCounter(metrics.ExecutionSuccessMetric) |
| 63 | + executionError := scope.NewCounter(metrics.ExecutionErrorMetric) |
| 64 | + |
| 65 | + projectCmds, err := b.ProjectCommandBuilder.BuildPlanCommands(ctx, comment) |
| 66 | + |
| 67 | + if err != nil { |
| 68 | + executionError.Inc() |
| 69 | + b.Logger.Err("Error building plan commands: %s", err) |
| 70 | + } else { |
| 71 | + executionSuccess.Inc() |
| 72 | + } |
| 73 | + |
| 74 | + return projectCmds, err |
| 75 | + |
| 76 | +} |
0 commit comments