Skip to content

Commit

Permalink
feat: Support generic tracers, bcc, target namespace
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
3 people committed Jul 21, 2021
1 parent b41eb65 commit 250740a
Show file tree
Hide file tree
Showing 13 changed files with 969 additions and 229 deletions.
11 changes: 11 additions & 0 deletions build/Dockerfile.tracerunner
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# syntax = docker/dockerfile:1.2
ARG bpftraceversion=v0.13.0
ARG bccversion=v0.21.0-focal-release
FROM quay.io/iovisor/bpftrace:$bpftraceversion as bpftrace
FROM quay.io/iovisor/bcc:$bccversion as bcc

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

FROM ubuntu:20.04

# Install bcc by copying apt packages from docker image
COPY --from=bcc /root/bcc /tmp/bcc
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y python python3 binutils libelf1 kmod && apt-get clean && \
dpkg -i /tmp/bcc/*.deb && rm -rf /tmp/bcc

# Install CA certificates
RUN apt-get update && apt-get install -y ca-certificates && update-ca-certificates && apt-get clean

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

# Inject some fake tracer 'programs' for integration testing.
COPY /build/test/fake/success /usr/share/fake/success

COPY /build/hooks/prestop /bin/hooks/prestop

ENTRYPOINT ["/bin/trace-runner"]
3 changes: 3 additions & 0 deletions build/test/fake/success
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

exit 0
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/evanphx/json-patch v4.9.0+incompatible
github.com/fntlnz/mountinfo v0.0.0-20171106231217-40cb42681fad
github.com/kr/pretty v0.2.1 // indirect
github.com/spf13/afero v1.3.1
github.com/spf13/cobra v1.1.1
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.6.1
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+o
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.3 h1:CE8S1cTafDpPvMhIxNJKvHsGVBgn1xWYf1NbHQhywc8=
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
Expand Down Expand Up @@ -306,6 +307,7 @@ github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
Expand Down Expand Up @@ -343,7 +345,10 @@ github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
github.com/spf13/afero v1.2.2 h1:5jhuqJyZCZf2JRofRvN/nIFgIWNzPa3/Vz8mYylgbWc=
github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk=
github.com/spf13/afero v1.3.1 h1:GPTpEAuNr98px18yNQ66JllNil98wfRZ/5Ukny8FeQA=
github.com/spf13/afero v1.3.1/go.mod h1:5KUK8ByomD5Ti5Artl0RtHeI5pTF7MIDuXL3yY520V4=
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
github.com/spf13/cobra v1.0.0/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE=
github.com/spf13/cobra v1.1.1 h1:KfztREH0tPxJJ+geloSLaAkaPkr4ki2Er5quFV1TDo4=
Expand Down Expand Up @@ -384,6 +389,7 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20191206172530-e9b2fee46413/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI=
Expand Down
30 changes: 30 additions & 0 deletions integration/cmd_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,33 @@ func (k *KubectlTraceSuite) TestReturnErrOnErr() {
assert.Equal(k.T(), int32(0), job.Status.Succeeded, "No jobs in the batch should have succeeded")
assert.Greater(k.T(), job.Status.Failed, int32(1), "There should be at least one failed job")
}

func (k *KubectlTraceSuite) TestGenericTracer() {
nodeName := k.GetTestNode()

out := k.KubectlTraceCmd(
"run",
"node/"+nodeName,
"--tracer=fake",
"--program=success",
"--deadline=5",
"--imagename="+k.RunnerImage())
assert.Regexp(k.T(), regexp.MustCompile("trace [a-f0-9-]{36} created"), out)

var job batchv1.Job

for {
jobs := k.GetJobs().Items
assert.Equal(k.T(), 1, len(jobs))

job = jobs[0]
if len(job.Status.Conditions) > 0 {
break // on the first condition
}

time.Sleep(1 * time.Second)
}

assert.Equal(k.T(), 1, len(job.Status.Conditions))
assert.Equal(k.T(), "Complete", string(job.Status.Conditions[0].Type))
}
2 changes: 1 addition & 1 deletion pkg/cmd/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func jobsTablePrint(o io.Writer, jobs []tracejob.TraceJob) {
if status == "" {
status = tracejob.TraceJobUnknown
}
fmt.Fprintf(w, "\n"+format, j.Namespace, j.Hostname, j.Name, status, translateTimestampSince(j.StartTime))
fmt.Fprintf(w, "\n"+format, j.Namespace, j.Target.Node, j.Name, status, translateTimestampSince(j.StartTime))
}
fmt.Fprintf(w, "\n")
}
Expand Down
Loading

0 comments on commit 250740a

Please sign in to comment.