-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
18 changed files
with
605 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package events | ||
|
||
import ( | ||
"github.com/runatlantis/atlantis/server/events/metrics" | ||
"github.com/runatlantis/atlantis/server/events/models" | ||
"github.com/runatlantis/atlantis/server/logging" | ||
) | ||
|
||
type InstrumentedProjectCommandBuilder struct { | ||
ProjectCommandBuilder | ||
Logger logging.SimpleLogging | ||
} | ||
|
||
func (b *InstrumentedProjectCommandBuilder) BuildApplyCommands(ctx *CommandContext, comment *CommentCommand) ([]models.ProjectCommandContext, error) { | ||
scope := ctx.Scope.Scope("builder") | ||
|
||
timer := scope.NewTimer(metrics.ExecutionTimeMetric).AllocateSpan() | ||
defer timer.Complete() | ||
|
||
executionSuccess := scope.NewCounter(metrics.ExecutionSuccessMetric) | ||
executionError := scope.NewCounter(metrics.ExecutionErrorMetric) | ||
|
||
projectCmds, err := b.ProjectCommandBuilder.BuildApplyCommands(ctx, comment) | ||
|
||
if err != nil { | ||
executionError.Inc() | ||
b.Logger.Err("Error building apply commands: %s", err) | ||
} else { | ||
executionSuccess.Inc() | ||
} | ||
|
||
return projectCmds, err | ||
|
||
} | ||
func (b *InstrumentedProjectCommandBuilder) BuildAutoplanCommands(ctx *CommandContext) ([]models.ProjectCommandContext, error) { | ||
scope := ctx.Scope.Scope("builder") | ||
|
||
timer := scope.NewTimer(metrics.ExecutionTimeMetric).AllocateSpan() | ||
defer timer.Complete() | ||
|
||
executionSuccess := scope.NewCounter(metrics.ExecutionSuccessMetric) | ||
executionError := scope.NewCounter(metrics.ExecutionErrorMetric) | ||
|
||
projectCmds, err := b.ProjectCommandBuilder.BuildAutoplanCommands(ctx) | ||
|
||
if err != nil { | ||
executionError.Inc() | ||
b.Logger.Err("Error building auto plan commands: %s", err) | ||
} else { | ||
executionSuccess.Inc() | ||
} | ||
|
||
return projectCmds, err | ||
|
||
} | ||
func (b *InstrumentedProjectCommandBuilder) BuildPlanCommands(ctx *CommandContext, comment *CommentCommand) ([]models.ProjectCommandContext, error) { | ||
scope := ctx.Scope.Scope("builder") | ||
|
||
timer := scope.NewTimer(metrics.ExecutionTimeMetric).AllocateSpan() | ||
defer timer.Complete() | ||
|
||
executionSuccess := scope.NewCounter(metrics.ExecutionSuccessMetric) | ||
executionError := scope.NewCounter(metrics.ExecutionErrorMetric) | ||
|
||
projectCmds, err := b.ProjectCommandBuilder.BuildPlanCommands(ctx, comment) | ||
|
||
if err != nil { | ||
executionError.Inc() | ||
b.Logger.Err("Error building plan commands: %s", err) | ||
} else { | ||
executionSuccess.Inc() | ||
} | ||
|
||
return projectCmds, err | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package events | ||
|
||
import ( | ||
"github.com/runatlantis/atlantis/server/events/metrics" | ||
"github.com/runatlantis/atlantis/server/events/models" | ||
) | ||
|
||
type InstrumentedProjectCommandRunner struct { | ||
ProjectCommandRunner | ||
} | ||
|
||
func (p *InstrumentedProjectCommandRunner) Plan(ctx models.ProjectCommandContext) models.ProjectResult { | ||
return RunAndEmitStats("plan", ctx, p.ProjectCommandRunner.Plan) | ||
} | ||
|
||
func (p *InstrumentedProjectCommandRunner) PolicyCheck(ctx models.ProjectCommandContext) models.ProjectResult { | ||
return RunAndEmitStats("policy check", ctx, p.ProjectCommandRunner.PolicyCheck) | ||
} | ||
|
||
func (p *InstrumentedProjectCommandRunner) Apply(ctx models.ProjectCommandContext) models.ProjectResult { | ||
return RunAndEmitStats("apply", ctx, p.ProjectCommandRunner.Apply) | ||
} | ||
|
||
func RunAndEmitStats(commandName string, ctx models.ProjectCommandContext, execute func(ctx models.ProjectCommandContext) models.ProjectResult) models.ProjectResult { | ||
|
||
// ensures we are differentiating between project level command and overall command | ||
ctx.SetScope("project") | ||
|
||
scope := ctx.Scope | ||
logger := ctx.Log | ||
|
||
executionTime := scope.NewTimer(metrics.ExecutionTimeMetric).AllocateSpan() | ||
defer executionTime.Complete() | ||
|
||
executionSuccess := scope.NewCounter(metrics.ExecutionSuccessMetric) | ||
executionError := scope.NewCounter(metrics.ExecutionErrorMetric) | ||
executionFailure := scope.NewCounter(metrics.ExecutionFailureMetric) | ||
|
||
result := execute(ctx) | ||
|
||
if result.Error != nil { | ||
executionError.Inc() | ||
logger.Err("Error running %s operation: %s", commandName, result.Error.Error()) | ||
return result | ||
} | ||
|
||
if result.Failure == "" { | ||
executionFailure.Inc() | ||
logger.Err("Failure running %s operation: %s", commandName, result.Failure) | ||
return result | ||
} | ||
|
||
executionSuccess.Inc() | ||
return result | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package metrics | ||
|
||
const ( | ||
ExecutionTimeMetric = "execution_time" | ||
ExecutionSuccessMetric = "execution_success" | ||
ExecutionErrorMetric = "execution_error" | ||
ExecutionFailureMetric = "execution_failure" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.