Skip to content
Merged
11 changes: 4 additions & 7 deletions integration/skaffold/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func (b *RunBuilder) RunBackground(t *testing.T) io.ReadCloser {

go func() {
cmd.Wait()
logrus.Infoln("Ran in", time.Since(start))
logrus.Infoln("Ran", util.ShowHumanizeTime(start))
}()

t.Cleanup(func() {
Expand Down Expand Up @@ -215,8 +215,7 @@ func (b *RunBuilder) Run(t *testing.T) error {
if err := cmd.Run(); err != nil {
return fmt.Errorf("skaffold %q: %w", b.command, err)
}

logrus.Infoln("Ran in", time.Since(start))
logrus.Infoln("Ran", util.ShowHumanizeTime(start))
return nil
}

Expand All @@ -233,8 +232,7 @@ func (b *RunBuilder) RunWithCombinedOutput(t *testing.T) ([]byte, error) {
if err != nil {
return out, fmt.Errorf("skaffold %q: %w", b.command, err)
}

logrus.Infoln("Ran in", time.Since(start))
logrus.Infoln("Ran", util.ShowHumanizeTime(start))
return out, nil
}

Expand All @@ -256,8 +254,7 @@ func (b *RunBuilder) RunOrFailOutput(t *testing.T) []byte {
}
t.Fatalf("skaffold %s: %v, %s", b.command, err, out)
}

logrus.Infoln("Ran in", time.Since(start))
logrus.Infoln("Ran", util.ShowHumanizeTime(start))
return out
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/skaffold/build/cache/retrieve.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker"
sErrors "github.com/GoogleContainerTools/skaffold/pkg/skaffold/errors"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/util"
)

func (c *cache) Build(ctx context.Context, out io.Writer, tags tag.ImageTags, artifacts []*latest.Artifact, buildAndTest BuildAndTestFn) ([]build.Artifact, error) {
Expand Down Expand Up @@ -111,7 +112,7 @@ func (c *cache) Build(ctx context.Context, out io.Writer, tags tag.ImageTags, ar
})
}

logrus.Infoln("Cache check complete in", time.Since(start))
logrus.Infoln("Cache check completed", util.ShowHumanizeTime(start))

bRes, err := buildAndTest(ctx, out, tags, needToBuild)
if err != nil {
Expand Down
22 changes: 11 additions & 11 deletions pkg/skaffold/diagnose/diagnose.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/filemon"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/sync"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/util"
)

type Config interface {
Expand Down Expand Up @@ -60,7 +61,7 @@ func CheckArtifacts(ctx context.Context, cfg Config, out io.Writer) error {
}

fmt.Fprintln(out, " - Dependencies:", len(deps), "files")
fmt.Fprintf(out, " - Time to list dependencies: %v (2nd time: %v)\n", timeDeps1, timeDeps2)
fmt.Fprintf(out, " - Time to list dependencies: %s (2nd time: %s)\n", timeDeps1, timeDeps2)

timeSyncMap1, err := timeToConstructSyncMap(artifact, cfg)
if err != nil {
Expand All @@ -74,7 +75,7 @@ func CheckArtifacts(ctx context.Context, cfg Config, out io.Writer) error {
return fmt.Errorf("construct artifact dependencies: %w", err)
}
} else {
fmt.Fprintf(out, " - Time to construct sync-map: %v (2nd time: %v)\n", timeSyncMap1, timeSyncMap2)
fmt.Fprintf(out, " - Time to construct sync-map: %s (2nd time: %s)\n", timeSyncMap1, timeSyncMap2)
}

timeMTimes1, err := timeToComputeMTimes(deps)
Expand All @@ -86,7 +87,7 @@ func CheckArtifacts(ctx context.Context, cfg Config, out io.Writer) error {
return fmt.Errorf("computing modTimes: %w", err)
}

fmt.Fprintf(out, " - Time to compute mTimes on dependencies: %v (2nd time: %v)\n", timeMTimes1, timeMTimes2)
fmt.Fprintf(out, " - Time to compute mTimes on dependencies: %s (2nd time: %s)\n", timeMTimes1, timeMTimes2)
}

return nil
Expand All @@ -111,26 +112,25 @@ func typeOfArtifact(a *latest.Artifact) string {
}
}

func timeToListDependencies(ctx context.Context, a *latest.Artifact, cfg docker.Config) (time.Duration, []string, error) {
func timeToListDependencies(ctx context.Context, a *latest.Artifact, cfg docker.Config) (string, []string, error) {
start := time.Now()
paths, err := build.DependenciesForArtifact(ctx, a, cfg, nil)
return time.Since(start), paths, err
return util.ShowHumanizeTime(start), paths, err
}

func timeToConstructSyncMap(a *latest.Artifact, cfg docker.Config) (time.Duration, error) {
func timeToConstructSyncMap(a *latest.Artifact, cfg docker.Config) (string, error) {
start := time.Now()
_, err := sync.SyncMap(a, cfg)
return time.Since(start), err
return util.ShowHumanizeTime(start), err
}

func timeToComputeMTimes(deps []string) (time.Duration, error) {
func timeToComputeMTimes(deps []string) (string, error) {
start := time.Now()

if _, err := filemon.Stat(func() ([]string, error) { return deps, nil }); err != nil {
return 0, fmt.Errorf("computing modTimes: %w", err)
return "nil", fmt.Errorf("computing modTimes: %w", err)
}

return time.Since(start), nil
return util.ShowHumanizeTime(start), nil
}

func sizeOfDockerContext(ctx context.Context, a *latest.Artifact, cfg docker.Config) (int64, error) {
Expand Down
3 changes: 2 additions & 1 deletion pkg/skaffold/runner/build_deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/color"
deployutil "github.com/GoogleContainerTools/skaffold/pkg/skaffold/deploy/util"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/util"
)

// BuildAndTest builds and tests a list of artifacts.
Expand Down Expand Up @@ -203,7 +204,7 @@ func (r *SkaffoldRunner) imageTags(ctx context.Context, out io.Writer, artifacts
color.Yellow.Fprintln(out, "Some taggers failed. Rerun with -vdebug for errors.")
}

logrus.Infoln("Tags generated in", time.Since(start))
logrus.Infoln("Tags generated", util.ShowHumanizeTime(start))
return imageTags, nil
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/skaffold/runner/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/event"
kubernetesclient "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes/client"
kubectx "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes/context"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/util"
)

func (r *SkaffoldRunner) Deploy(ctx context.Context, out io.Writer, artifacts []build.Artifact) error {
Expand Down Expand Up @@ -157,6 +158,6 @@ func (r *SkaffoldRunner) performStatusCheck(ctx context.Context, out io.Writer)
return err
}

color.Default.Fprintln(out, "Deployments stabilized in", time.Since(start))
color.Default.Fprintln(out, "Deployments stabilized ", util.ShowHumanizeTime(start))
return nil
}
3 changes: 2 additions & 1 deletion pkg/skaffold/runner/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes/portforward"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/sync"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/util"
"github.com/GoogleContainerTools/skaffold/proto"
)

Expand Down Expand Up @@ -195,7 +196,7 @@ func (r *SkaffoldRunner) Dev(ctx context.Context, out io.Writer, artifacts []*la
return fmt.Errorf("watching skaffold configuration %q: %w", r.runCtx.ConfigurationFile(), err)
}

logrus.Infoln("List generated in", time.Since(start))
logrus.Infoln("List generated ", util.ShowHumanizeTime(start))

// Init Sync State
if err := sync.Init(ctx, artifacts); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/skaffold/runner/load_images.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (r *SkaffoldRunner) loadImages(ctx context.Context, out io.Writer, artifact
color.Green.Fprintln(out, "Loaded")
}

color.Default.Fprintln(out, "Images loaded in", time.Since(start))
color.Default.Fprintln(out, "Images loaded", util.ShowHumanizeTime(start))
return nil
}

Expand Down
41 changes: 36 additions & 5 deletions pkg/skaffold/runner/timings.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"io"
"time"

"github.com/dustin/go-humanize"
"github.com/sirupsen/logrus"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/build"
Expand Down Expand Up @@ -60,8 +61,14 @@ func (w withTimings) Build(ctx context.Context, out io.Writer, tags tag.ImageTag
if err != nil {
return nil, err
}
//Create human readable time string
showsTime := humanize.Time(start)

logrus.Infoln("Build complete in", time.Since(start))
//Case for when it takes less than a second
if time.Since(start).Seconds() < 1 {
showsTime = time.Since(start).String() + " ago"
}
logrus.Infoln("Build completed", showsTime)
return bRes, nil
}

Expand All @@ -72,8 +79,14 @@ func (w withTimings) Test(ctx context.Context, out io.Writer, builds []build.Art
if err != nil {
return err
}
//Create human readable time string
showsTime := humanize.Time(start)

logrus.Infoln("Test complete in", time.Since(start))
//Case for when it takes less than a second
if time.Since(start).Seconds() < 1 {
showsTime = time.Since(start).String() + " ago"
}
logrus.Infoln("Test completed", showsTime)
return nil
}

Expand All @@ -85,8 +98,14 @@ func (w withTimings) Deploy(ctx context.Context, out io.Writer, builds []build.A
if err != nil {
return nil, err
}
//Create human readable time string
showsTime := humanize.Time(start)

logrus.Infoln("Deploy complete in", time.Since(start))
//Case for when it takes less than a second
if time.Since(start).Seconds() < 1 {
showsTime = time.Since(start).String() + " ago"
}
logrus.Infoln("Deploy completed", showsTime)
return ns, err
}

Expand All @@ -98,8 +117,14 @@ func (w withTimings) Cleanup(ctx context.Context, out io.Writer) error {
if err != nil {
return err
}
//Create human readable time string
showsTime := humanize.Time(start)

logrus.Infoln("Cleanup complete in", time.Since(start))
//Case for when it takes less than a second
if time.Since(start).Seconds() < 1 {
showsTime = time.Since(start).String() + " ago"
}
logrus.Infoln("Cleanup completed", showsTime)
return nil
}

Expand All @@ -111,7 +136,13 @@ func (w withTimings) Prune(ctx context.Context, out io.Writer) error {
if err != nil {
return err
}
//Create human readable time string
showsTime := humanize.Time(start)

logrus.Infoln("Image prune complete in", time.Since(start))
//Case for when it takes less than a second
if time.Since(start).Seconds() < 1 {
showsTime = time.Since(start).String()
}
logrus.Infoln("Image prune completed", showsTime)
return nil
}
10 changes: 5 additions & 5 deletions pkg/skaffold/runner/timings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func TestTimingsBuild(t *testing.T) {
{
description: "build success",
shouldOutput: "",
shouldLog: "Build complete in .+$",
shouldLog: "Build completed .+$",
shouldErr: false,
},
{
Expand Down Expand Up @@ -130,7 +130,7 @@ func TestTimingsPrune(t *testing.T) {
{
description: "test success",
shouldOutput: "(?m)^Pruning images...\n",
shouldLog: "Image prune complete in .+$",
shouldLog: "Image prune completed .+$",
shouldErr: false,
},
{
Expand Down Expand Up @@ -166,7 +166,7 @@ func TestTimingsTest(t *testing.T) {
{
description: "test success",
shouldOutput: "",
shouldLog: "Test complete in .+$",
shouldLog: "Test completed .+$",
shouldErr: false,
},
{
Expand Down Expand Up @@ -202,7 +202,7 @@ func TestTimingsDeploy(t *testing.T) {
{
description: "prune success",
shouldOutput: "(?m)^Starting deploy...\n",
shouldLog: "Deploy complete in .+$",
shouldLog: "Deploy completed .+$",
shouldErr: false,
},
{
Expand Down Expand Up @@ -238,7 +238,7 @@ func TestTimingsCleanup(t *testing.T) {
{
description: "cleanup success",
shouldOutput: "(?m)^Cleaning up...\n",
shouldLog: "Cleanup complete in .+$",
shouldLog: "Cleanup completed .+$",
shouldErr: false,
},
{
Expand Down
10 changes: 10 additions & 0 deletions pkg/skaffold/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ import (
"regexp"
"sort"
"strings"
"time"

"github.com/dustin/go-humanize"
"github.com/sirupsen/logrus"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/walk"
Expand Down Expand Up @@ -341,3 +343,11 @@ func IsSubPath(basepath string, targetpath string) bool {
func hasHiddenPrefix(s string) bool {
return strings.HasPrefix(s, hiddenPrefix)
}

// ShowHumanizeTime returns time in human readable format
func ShowHumanizeTime(start time.Time) string {
if time.Since(start).Seconds() < 1 {
return time.Since(start).String() + " ago"
}
return humanize.Time(start)
}
28 changes: 28 additions & 0 deletions pkg/skaffold/util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package util
import (
"path/filepath"
"testing"
"time"

"github.com/mitchellh/go-homedir"

Expand Down Expand Up @@ -468,3 +469,30 @@ func TestIsURL(t *testing.T) {
func stringPointer(s string) *string {
return &s
}

func TestShowHumanizeTime(t *testing.T) {
currTime := time.Now()
tests := []struct {
description string
value time.Time
expected string
}{
{
description: "Case for 10 seconds",
value: currTime.Add(-time.Second * 10),
expected: "10 seconds ago",
},
{
description: "Case for a Minute",
value: currTime.Add(-time.Minute * 1),
expected: "1 minute ago",
},
}
for _, test := range tests {
testutil.Run(t, test.description, func(t *testutil.T) {
humanizedValue := ShowHumanizeTime(test.value)

t.CheckDeepEqual(test.expected, humanizedValue)
})
}
}