Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

feat: add evaluation duration #596

Merged
merged 5 commits into from
May 3, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: change start time to first app init
  • Loading branch information
shmuelsa committed May 3, 2022
commit 141873ce6ab154bae1666b929bf270a3e466d621
5 changes: 5 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package cmd

import (
"time"

"github.com/datreeio/datree/bl/evaluation"
"github.com/datreeio/datree/bl/files"
"github.com/datreeio/datree/bl/messager"
Expand Down Expand Up @@ -31,6 +33,7 @@ var rootCmd = &cobra.Command{
var CliVersion string

func NewRootCommand(app *App) *cobra.Command {
startEvaluationTime := time.Now()

rootCmd.AddCommand(test.New(&test.TestCommandContext{
CliVersion: CliVersion,
Expand All @@ -43,6 +46,7 @@ func NewRootCommand(app *App) *cobra.Command {
CliClient: app.Context.CliClient,
FilesExtractor: app.Context.FilesExtractor,
CiContext: app.Context.CiContext,
StartTime: startEvaluationTime,
}))

rootCmd.AddCommand(kustomize.New(&test.TestCommandContext{
Expand All @@ -55,6 +59,7 @@ func NewRootCommand(app *App) *cobra.Command {
K8sValidator: app.Context.K8sValidator,
CliClient: app.Context.CliClient,
FilesExtractor: app.Context.FilesExtractor,
StartTime: startEvaluationTime,
}, &kustomize.KustomizeContext{CommandRunner: app.Context.CommandRunner}))

rootCmd.AddCommand(version.New(&version.VersionCommandContext{
Expand Down
4 changes: 2 additions & 2 deletions cmd/test/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ type TestCommandContext struct {
Reader Reader
CliClient CliClient
FilesExtractor files.FilesExtractorInterface
StartTime time.Time
}

func LoadVersionMessages(ctx *TestCommandContext, args []string, cmd *cobra.Command) error {
Expand Down Expand Up @@ -407,7 +408,6 @@ type EvaluationResultData struct {
}

func evaluate(ctx *TestCommandContext, filesPaths []string, prerunData *TestCommandData) (EvaluationResultData, error) {
startEvaluationTime := time.Now()
isInteractiveMode := !evaluation.IsFormattedOutputOption(prerunData.Output)

var _spinner *spinner.Spinner
Expand Down Expand Up @@ -498,7 +498,7 @@ func evaluate(ctx *TestCommandContext, filesPaths []string, prerunData *TestComm

ciContext := ciContext.Extract()
endEvaluationTime := time.Now()
EvaluationDurationSeconds := endEvaluationTime.Sub(startEvaluationTime).Seconds()
EvaluationDurationSeconds := endEvaluationTime.Sub(ctx.StartTime).Seconds()
evaluationRequestData := evaluation.EvaluationRequestData{
Token: prerunData.Token,
ClientId: prerunData.ClientId,
Expand Down