Skip to content

Commit d8c9104

Browse files
committed
Improve output
Signed-off-by: David Gageot <[email protected]>
1 parent 9a1cb2a commit d8c9104

File tree

1 file changed

+47
-26
lines changed

1 file changed

+47
-26
lines changed

cmd/skaffold/app/cmd/diagnose.go

+47-26
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"io/ioutil"
2323
"time"
2424

25+
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/color"
2526
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker"
2627
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner"
2728
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
@@ -56,55 +57,75 @@ func doDiagnose(out io.Writer) error {
5657
fmt.Fprintln(out, "Configuration version:", config.APIVersion)
5758
fmt.Fprintln(out, "Number of artifacts:", len(config.Build.Artifacts))
5859

59-
fmt.Fprintln(out, "\nRunning a diagnostic on artifacts and their dependencies:")
60-
6160
if err := diagnoseArtifacts(out, config.Build.Artifacts); err != nil {
6261
return errors.Wrap(err, "running diagnostic on artifacts")
6362
}
6463

65-
fmt.Fprintln(out, "\nSecond run (that benefits from cache):")
66-
67-
if err := diagnoseArtifacts(out, config.Build.Artifacts); err != nil {
68-
return errors.Wrap(err, "running second diagnostic on artifacts")
69-
}
70-
7164
return nil
7265
}
7366

7467
func diagnoseArtifacts(out io.Writer, artifacts []*latest.Artifact) error {
7568
for _, artifact := range artifacts {
76-
start := time.Now()
77-
deps, err := runner.DependenciesForArtifact(artifact)
78-
if err != nil {
79-
return errors.Wrap(err, "listing artifact dependencies")
80-
}
81-
82-
fmt.Fprintln(out, "Type:", typeOfArtifact(artifact))
83-
fmt.Fprintln(out, " - Dependencies to watch:", len(deps))
84-
fmt.Fprintln(out, " - Time to list dependencies:", time.Since(start))
69+
color.Default.Fprintf(out, "\n%s: %s\n", typeOfArtifact(artifact), artifact.ImageName)
8570

8671
if artifact.DockerArtifact != nil {
87-
size, err := sizeOfTheDockerContext(artifact)
72+
size, err := sizeOfDockerContext(artifact)
8873
if err != nil {
8974
return errors.Wrap(err, "computing the size of the Docker context")
9075
}
9176

92-
fmt.Fprintln(out, " - Size of the Docker context:", size)
77+
fmt.Fprintf(out, " - Size of the context: %vbytes\n", size)
9378
}
9479

95-
start = time.Now()
96-
_, err = watch.Stat(func() ([]string, error) { return deps, nil })
80+
timeDeps1, deps, err := timeToListDependencies(artifact)
81+
if err != nil {
82+
return errors.Wrap(err, "listing artifact dependencies")
83+
}
84+
timeDeps2, _, err := timeToListDependencies(artifact)
85+
if err != nil {
86+
return errors.Wrap(err, "listing artifact dependencies")
87+
}
88+
89+
fmt.Fprintln(out, " - Dependencies:", len(deps), "files")
90+
fmt.Fprintf(out, " - Time to list dependencies: %v (2nd time: %v)\n", timeDeps1, timeDeps2)
91+
92+
timeMTimes1, err := timeToComputeMTimes(deps)
93+
if err != nil {
94+
return errors.Wrap(err, "computing modTimes")
95+
}
96+
timeMTimes2, err := timeToComputeMTimes(deps)
9797
if err != nil {
9898
return errors.Wrap(err, "computing modTimes")
9999
}
100100

101-
fmt.Fprintln(out, " - Time to compute mTimes for all dependencies:", time.Since(start))
101+
fmt.Fprintf(out, " - Time to compute mTimes on dependencies: %v (2nd time: %v)\n", timeMTimes1, timeMTimes2)
102102
}
103103

104104
return nil
105105
}
106106

107-
func sizeOfTheDockerContext(a *latest.Artifact) (int64, error) {
107+
func timeToListDependencies(a *latest.Artifact) (time.Duration, []string, error) {
108+
start := time.Now()
109+
110+
deps, err := runner.DependenciesForArtifact(a)
111+
if err != nil {
112+
return 0, nil, errors.Wrap(err, "listing artifact dependencies")
113+
}
114+
115+
return time.Since(start), deps, nil
116+
}
117+
118+
func timeToComputeMTimes(deps []string) (time.Duration, error) {
119+
start := time.Now()
120+
121+
if _, err := watch.Stat(func() ([]string, error) { return deps, nil }); err != nil {
122+
return 0, errors.Wrap(err, "computing modTimes")
123+
}
124+
125+
return time.Since(start), nil
126+
}
127+
128+
func sizeOfDockerContext(a *latest.Artifact) (int64, error) {
108129
buildCtx, buildCtxWriter := io.Pipe()
109130
go func() {
110131
err := docker.CreateDockerTarContext(buildCtxWriter, a.Workspace, a.DockerArtifact)
@@ -121,10 +142,10 @@ func sizeOfTheDockerContext(a *latest.Artifact) (int64, error) {
121142
func typeOfArtifact(a *latest.Artifact) string {
122143
switch {
123144
case a.DockerArtifact != nil:
124-
return "Docker"
145+
return "Docker artifact"
125146
case a.BazelArtifact != nil:
126-
return "Bazel"
147+
return "Bazel artifact"
127148
default:
128-
return "Unknown"
149+
return "Unknown artifact"
129150
}
130151
}

0 commit comments

Comments
 (0)