Skip to content

Commit

Permalink
Allow adequate time for bpftrace to shut down, so jobs will show as c…
Browse files Browse the repository at this point in the history
…ompleted
  • Loading branch information
dalehamel committed Sep 18, 2019
1 parent 7029bba commit c0f61a9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
5 changes: 3 additions & 2 deletions pkg/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ var (
// DefaultDeadline is the maximum time a tracejob is allowed to run, in seconds
DefaultDeadline = 3600
// DefaultDeadlineGracePeriod is the maximum time to wait to print a map or histogram, in seconds
DefaultDeadlineGracePeriod = 10
// note that it must account for startup time, as the deadline as based on start time
DefaultDeadlineGracePeriod = 30
)

var (
Expand Down Expand Up @@ -136,7 +137,7 @@ func NewRunCommand(factory factory.Factory, streams genericclioptions.IOStreams)
cmd.Flags().StringVar(&o.initImageName, "init-imagename", o.initImageName, "Custom image for the init container responsible to fetch and prepare linux headers")
cmd.Flags().BoolVar(&o.fetchHeaders, "fetch-headers", o.fetchHeaders, "Whether to fetch linux headers or not")
cmd.Flags().Int64Var(&o.deadline, "deadline", o.deadline, "Maximum time to allow trace to run in seconds")
cmd.Flags().Int64Var(&o.deadline, "deadline-grace-period", o.deadlineGracePeriod, "Maximum wait time to print maps or histograms after deadline, in seconds")
cmd.Flags().Int64Var(&o.deadlineGracePeriod, "deadline-grace-period", o.deadlineGracePeriod, "Maximum wait time to print maps or histograms after deadline, in seconds")

return cmd
}
Expand Down
10 changes: 8 additions & 2 deletions pkg/tracejob/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"io"
"io/ioutil"
"strconv"

"github.com/iovisor/kubectl-trace/pkg/meta"
batchv1 "k8s.io/api/batch/v1"
Expand Down Expand Up @@ -186,6 +187,11 @@ func (t *TraceJobClient) DeleteJobs(nf TraceJobFilter) error {
func (t *TraceJobClient) CreateJob(nj TraceJob) (*batchv1.Job, error) {

bpfTraceCmd := []string{
"/bin/timeout",
"--preserve-status",
"--signal",
"INT",
strconv.FormatInt(nj.Deadline, 10),
"/bin/trace-runner",
"--program=/programs/program.bt",
}
Expand Down Expand Up @@ -219,7 +225,7 @@ func (t *TraceJobClient) CreateJob(nj TraceJob) (*batchv1.Job, error) {
job := &batchv1.Job{
ObjectMeta: commonMeta,
Spec: batchv1.JobSpec{
ActiveDeadlineSeconds: int64Ptr(nj.Deadline),
ActiveDeadlineSeconds: int64Ptr(nj.Deadline + nj.DeadlineGracePeriod),
TTLSecondsAfterFinished: int32Ptr(5),
Parallelism: int32Ptr(1),
Completions: int32Ptr(1),
Expand Down Expand Up @@ -306,7 +312,7 @@ func (t *TraceJobClient) CreateJob(nj TraceJob) (*batchv1.Job, error) {
Command: []string{
"/bin/bash",
"-c",
fmt.Sprintf("kill -SIGINT $(pidof bpftrace) && sleep %i", nj.DeadlineGracePeriod),
fmt.Sprintf("kill -SIGINT $(pidof bpftrace) && sleep %i", strconv.FormatInt(nj.DeadlineGracePeriod, 10)),
},
},
},
Expand Down

0 comments on commit c0f61a9

Please sign in to comment.