Skip to content

Commit 7fd3007

Browse files
dalehamelhonkfestivalzqureshi
committed
feat: Support generic tracers, bcc, target namespace
This adds support for generic tracers, fixing #125 The new "--tracer" flag allows specifying arbitrary generic tracers. The bcc suite of tools is added to take advantage of this, as well as a "fake" tracer for integration testing this functionality, fixing #112 The primary original author of this functionality was Zeeshan Qureshi. In order to pull this change in, it was necessary to also pull in functionality that refactored how trace job targets are specified. This introduces a new flag which allows specifying the target namespace separately from the namespace where the trace is created, which fixes #147. This functionality was co-authored with Aaron Olson. Co-authored-by: Aaron Olson <[email protected]> Co-authored-by: Zeeshan Qureshi <[email protected]>
1 parent b41eb65 commit 7fd3007

File tree

13 files changed

+921
-228
lines changed

13 files changed

+921
-228
lines changed

build/Dockerfile.tracerunner

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# syntax = docker/dockerfile:1.2
22
ARG bpftraceversion=v0.13.0
3+
ARG bccversion=v0.21.0-focal-release
34
FROM quay.io/iovisor/bpftrace:$bpftraceversion as bpftrace
5+
FROM quay.io/iovisor/bcc:$bccversion as bcc
46

57
FROM golang:1.15-buster as gobuilder
68
ARG GIT_ORG=iovisor
@@ -26,12 +28,21 @@ RUN --mount=type=cache,target=/root/.cache/go-build make _output/bin/trace-runne
2628

2729
FROM ubuntu:20.04
2830

31+
# Install bcc by copying apt packages from docker image
32+
COPY --from=bcc /root/bcc /tmp/bcc
33+
RUN apt-get update && \
34+
DEBIAN_FRONTEND=noninteractive apt-get install -y python python3 binutils libelf1 kmod && apt-get clean && \
35+
dpkg -i /tmp/bcc/*.deb && rm -rf /tmp/bcc
36+
2937
# Install CA certificates
3038
RUN apt-get update && apt-get install -y ca-certificates && update-ca-certificates && apt-get clean
3139

3240
COPY --from=bpftrace /usr/bin/bpftrace /usr/bin/bpftrace
3341
COPY --from=gobuilder /go/src/github.com/iovisor/kubectl-trace/_output/bin/trace-runner /bin/trace-runner
3442

43+
# Inject some fake tracer 'programs' for integration testing.
44+
COPY /build/test/fake/success /usr/share/fake/success
45+
3546
COPY /build/hooks/prestop /bin/hooks/prestop
3647

3748
ENTRYPOINT ["/bin/trace-runner"]

build/test/fake/success

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
exit 0

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ require (
66
github.com/evanphx/json-patch v4.9.0+incompatible
77
github.com/fntlnz/mountinfo v0.0.0-20171106231217-40cb42681fad
88
github.com/kr/pretty v0.2.1 // indirect
9+
github.com/spf13/afero v1.3.1
910
github.com/spf13/cobra v1.1.1
1011
github.com/spf13/pflag v1.0.5
1112
github.com/stretchr/testify v1.6.1

go.sum

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+o
240240
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
241241
github.com/konsorten/go-windows-terminal-sequences v1.0.3 h1:CE8S1cTafDpPvMhIxNJKvHsGVBgn1xWYf1NbHQhywc8=
242242
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
243+
github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
243244
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
244245
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
245246
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
@@ -306,6 +307,7 @@ github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
306307
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
307308
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
308309
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
310+
github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI=
309311
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
310312
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
311313
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
@@ -343,7 +345,10 @@ github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9
343345
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
344346
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
345347
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
348+
github.com/spf13/afero v1.2.2 h1:5jhuqJyZCZf2JRofRvN/nIFgIWNzPa3/Vz8mYylgbWc=
346349
github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk=
350+
github.com/spf13/afero v1.3.1 h1:GPTpEAuNr98px18yNQ66JllNil98wfRZ/5Ukny8FeQA=
351+
github.com/spf13/afero v1.3.1/go.mod h1:5KUK8ByomD5Ti5Artl0RtHeI5pTF7MIDuXL3yY520V4=
347352
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
348353
github.com/spf13/cobra v1.0.0/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE=
349354
github.com/spf13/cobra v1.1.1 h1:KfztREH0tPxJJ+geloSLaAkaPkr4ki2Er5quFV1TDo4=
@@ -384,6 +389,7 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk
384389
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
385390
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
386391
golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
392+
golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
387393
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
388394
golang.org/x/crypto v0.0.0-20191206172530-e9b2fee46413/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
389395
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI=

integration/cmd_run_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,33 @@ func (k *KubectlTraceSuite) TestReturnErrOnErr() {
4444
assert.Equal(k.T(), int32(0), job.Status.Succeeded, "No jobs in the batch should have succeeded")
4545
assert.Greater(k.T(), job.Status.Failed, int32(1), "There should be at least one failed job")
4646
}
47+
48+
func (k *KubectlTraceSuite) TestGenericTracer() {
49+
nodeName := k.GetTestNode()
50+
51+
out := k.KubectlTraceCmd(
52+
"run",
53+
"node/"+nodeName,
54+
"--tracer=fake",
55+
"--program=success",
56+
"--deadline=5",
57+
"--imagename="+k.RunnerImage())
58+
assert.Regexp(k.T(), regexp.MustCompile("trace [a-f0-9-]{36} created"), out)
59+
60+
var job batchv1.Job
61+
62+
for {
63+
jobs := k.GetJobs().Items
64+
assert.Equal(k.T(), 1, len(jobs))
65+
66+
job = jobs[0]
67+
if len(job.Status.Conditions) > 0 {
68+
break // on the first condition
69+
}
70+
71+
time.Sleep(1 * time.Second)
72+
}
73+
74+
assert.Equal(k.T(), 1, len(job.Status.Conditions))
75+
assert.Equal(k.T(), "Complete", string(job.Status.Conditions[0].Type))
76+
}

pkg/cmd/get.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ func jobsTablePrint(o io.Writer, jobs []tracejob.TraceJob) {
193193
if status == "" {
194194
status = tracejob.TraceJobUnknown
195195
}
196-
fmt.Fprintf(w, "\n"+format, j.Namespace, j.Hostname, j.Name, status, translateTimestampSince(j.StartTime))
196+
fmt.Fprintf(w, "\n"+format, j.Namespace, j.Target.Node, j.Name, status, translateTimestampSince(j.StartTime))
197197
}
198198
fmt.Fprintf(w, "\n")
199199
}

0 commit comments

Comments
 (0)