Skip to content

Commit 100f9a1

Browse files
authored
feat: Record summary of execution times of support bundle operations (collect/redact/analyse) (#935)
When running a support bundle, we want to know how long each operation (collect, redact, analyze) takes. This commit adds a new trace exporter that records the start and end times of each operation, and then prints a summary of the execution. The summary is also stored in the support bundle. Related to #923
1 parent e156b8c commit 100f9a1

File tree

20 files changed

+795
-60
lines changed

20 files changed

+795
-60
lines changed

Makefile

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ define LDFLAGS
3535
endef
3636

3737
BUILDFLAGS = -tags "netgo containers_image_ostree_stub exclude_graphdriver_devicemapper exclude_graphdriver_btrfs containers_image_openpgp" -installsuffix netgo
38+
BUILDPATHS = ./pkg/... ./cmd/... ./internal/...
3839

3940
all: test support-bundle preflight collect analyze
4041

@@ -45,16 +46,16 @@ ffi: fmt vet
4546
.PHONY: test
4647
test: generate fmt vet
4748
if [ -n $(RUN) ]; then \
48-
go test ${BUILDFLAGS} ./pkg/... ./cmd/... -coverprofile cover.out -run $(RUN); \
49+
go test ${BUILDFLAGS} ${BUILDPATHS} -coverprofile cover.out -run $(RUN); \
4950
else \
50-
go test ${BUILDFLAGS} ./pkg/... ./cmd/... -coverprofile cover.out; \
51+
go test ${BUILDFLAGS} ${BUILDPATHS} -coverprofile cover.out; \
5152
fi
5253

5354
# Go tests that require a K8s instance
5455
# TODOLATER: merge with test, so we get unified coverage reports? it'll add 21~sec to the test job though...
5556
.PHONY: test-integration
5657
test-integration:
57-
go test -v --tags "integration exclude_graphdriver_devicemapper exclude_graphdriver_btrfs" ./pkg/... ./cmd/...
58+
go test -v --tags "integration exclude_graphdriver_devicemapper exclude_graphdriver_btrfs" ${BUILDPATHS}
5859

5960
.PHONY: preflight-e2e-test
6061
preflight-e2e-test:
@@ -82,11 +83,11 @@ collect:
8283

8384
.PHONY: fmt
8485
fmt:
85-
go fmt ./pkg/... ./cmd/...
86+
go fmt ${BUILDPATHS}
8687

8788
.PHONY: vet
8889
vet:
89-
go vet ${BUILDFLAGS} ./pkg/... ./cmd/...
90+
go vet ${BUILDFLAGS} ${BUILDPATHS}
9091

9192
.PHONY: generate
9293
generate: controller-gen client-gen
@@ -213,8 +214,8 @@ scan:
213214

214215
.PHONY: lint
215216
lint:
216-
golangci-lint run --new -c .golangci.yaml pkg/... cmd/...
217+
golangci-lint run --new -c .golangci.yaml ${BUILDPATHS}
217218

218219
.PHONY: lint-and-fix
219220
lint-and-fix:
220-
golangci-lint run --new --fix -c .golangci.yaml pkg/... cmd/...
221+
golangci-lint run --new --fix -c .golangci.yaml ${BUILDPATHS}

cmd/preflight/cli/root.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package cli
22

33
import (
4+
"fmt"
45
"os"
56
"strings"
67

78
"github.com/go-logr/logr"
89
"github.com/replicatedhq/troubleshoot/cmd/util"
10+
"github.com/replicatedhq/troubleshoot/internal/traces"
911
"github.com/replicatedhq/troubleshoot/pkg/k8sutil"
1012
"github.com/replicatedhq/troubleshoot/pkg/logger"
1113
"github.com/replicatedhq/troubleshoot/pkg/preflight"
@@ -37,7 +39,19 @@ that a cluster meets the requirements to run an application.`,
3739
},
3840
RunE: func(cmd *cobra.Command, args []string) error {
3941
v := viper.GetViper()
40-
return preflight.RunPreflights(v.GetBool("interactive"), v.GetString("output"), v.GetString("format"), args)
42+
closer, err := traces.ConfigureTracing("preflight")
43+
if err != nil {
44+
// Do not fail running preflights if tracing fails
45+
logger.Printf("Failed to initialize open tracing provider: %v", err)
46+
} else {
47+
defer closer()
48+
}
49+
50+
err = preflight.RunPreflights(v.GetBool("interactive"), v.GetString("output"), v.GetString("format"), args)
51+
if v.GetBool("debug") {
52+
fmt.Printf("\n%s", traces.GetExporterInstance().GetSummary())
53+
}
54+
return err
4155
},
4256
PostRun: func(cmd *cobra.Command, args []string) {
4357
if err := util.StopProfiling(); err != nil {

cmd/troubleshoot/cli/root.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package cli
22

33
import (
4+
"fmt"
45
"os"
56
"strings"
67

78
"github.com/go-logr/logr"
89
"github.com/replicatedhq/troubleshoot/cmd/util"
10+
"github.com/replicatedhq/troubleshoot/internal/traces"
911
"github.com/replicatedhq/troubleshoot/pkg/k8sutil"
1012
"github.com/replicatedhq/troubleshoot/pkg/logger"
1113
"github.com/spf13/cobra"
@@ -40,7 +42,20 @@ from a server that can be used to assist when troubleshooting a Kubernetes clust
4042
RunE: func(cmd *cobra.Command, args []string) error {
4143
v := viper.GetViper()
4244

43-
return runTroubleshoot(v, args)
45+
closer, err := traces.ConfigureTracing("support-bundle")
46+
if err != nil {
47+
// Do not fail running support-bundle if tracing fails
48+
logger.Printf("Failed to initialize open tracing provider: %v", err)
49+
} else {
50+
defer closer()
51+
}
52+
53+
err = runTroubleshoot(v, args)
54+
if v.GetBool("debug") {
55+
fmt.Printf("\n%s", traces.GetExporterInstance().GetSummary())
56+
}
57+
58+
return err
4459
},
4560
PersistentPostRun: func(cmd *cobra.Command, args []string) {
4661
if err := util.StopProfiling(); err != nil {

cmd/troubleshoot/cli/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func writeVersionFile(path string) error {
4040
return err
4141
}
4242

43-
filename := filepath.Join(path, constants.VersionFilename)
43+
filename := filepath.Join(path, constants.VERSION_FILENAME)
4444
err = ioutil.WriteFile(filename, b, 0644)
4545
if err != nil {
4646
return err

examples/support-bundle/sample-supportbundle.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ kind: SupportBundle
33
metadata:
44
name: example
55
spec:
6+
hostCollectors:
7+
- hostOS: {}
68
collectors:
79
- logs:
810
selector:

go.mod

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ require (
3434
github.com/spf13/viper v1.15.0
3535
github.com/stretchr/testify v1.8.1
3636
github.com/tj/go-spin v1.1.0
37+
go.opentelemetry.io/otel v1.12.0
38+
go.opentelemetry.io/otel/sdk v1.11.2
3739
golang.org/x/sync v0.1.0
3840
gopkg.in/yaml.v2 v2.4.0
3941
k8s.io/api v0.26.1
@@ -53,6 +55,7 @@ require (
5355
github.com/docker/distribution v2.8.1+incompatible // indirect
5456
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
5557
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
58+
github.com/go-logr/stdr v1.2.2 // indirect
5659
github.com/googleapis/enterprise-certificate-proxy v0.2.1 // indirect
5760
github.com/jackc/pgpassfile v1.0.0 // indirect
5861
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b // indirect
@@ -61,6 +64,7 @@ require (
6164
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
6265
github.com/russross/blackfriday/v2 v2.1.0 // indirect
6366
github.com/sylabs/sif/v2 v2.9.0 // indirect
67+
go.opentelemetry.io/otel/trace v1.12.0 // indirect
6468
golang.org/x/mod v0.7.0 // indirect
6569
golang.org/x/tools v0.4.0 // indirect
6670
)
@@ -186,7 +190,7 @@ require (
186190
golang.org/x/oauth2 v0.4.0 // indirect
187191
golang.org/x/sys v0.4.0 // indirect
188192
golang.org/x/term v0.4.0 // indirect
189-
golang.org/x/text v0.6.0 // indirect
193+
golang.org/x/text v0.6.0
190194
golang.org/x/time v0.3.0 // indirect
191195
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
192196
google.golang.org/api v0.107.0 // indirect

go.sum

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,8 +399,11 @@ github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KE
399399
github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas=
400400
github.com/go-logr/logr v0.2.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU=
401401
github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
402+
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
402403
github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0=
403404
github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
405+
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
406+
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
404407
github.com/go-logr/zapr v1.2.3 h1:a9vnzlIBPQBBkeaR9IuMUfmVOrQlkoC4YfPoFkX3T7A=
405408
github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY=
406409
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
@@ -1031,6 +1034,12 @@ go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
10311034
go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk=
10321035
go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0=
10331036
go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo=
1037+
go.opentelemetry.io/otel v1.12.0 h1:IgfC7kqQrRccIKuB7Cl+SRUmsKbEwSGPr0Eu+/ht1SQ=
1038+
go.opentelemetry.io/otel v1.12.0/go.mod h1:geaoz0L0r1BEOR81k7/n9W4TCXYCJ7bPO7K374jQHG0=
1039+
go.opentelemetry.io/otel/sdk v1.11.2 h1:GF4JoaEx7iihdMFu30sOyRx52HDHOkl9xQ8SMqNXUiU=
1040+
go.opentelemetry.io/otel/sdk v1.11.2/go.mod h1:wZ1WxImwpq+lVRo4vsmSOxdd+xwoUJ6rqyLc3SyX9aU=
1041+
go.opentelemetry.io/otel/trace v1.12.0 h1:p28in++7Kd0r2d8gSt931O57fdjUyWxkVbESuILAeUc=
1042+
go.opentelemetry.io/otel/trace v1.12.0/go.mod h1:pHlgBynn6s25qJ2szD+Bv+iwKJttjHSI3lUAyf0GNuQ=
10341043
go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI=
10351044
go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5 h1:+FNtrFTmVw0YZGpBGX56XDee331t6JAXeK2bcyhLOOc=
10361045
go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5/go.mod h1:nmDLcffg48OtT/PSW0Hg7FvpRQsQh5OSqIylirxKC7o=

0 commit comments

Comments
 (0)