diff --git a/pkg/cmd/run.go b/pkg/cmd/run.go index 44ecb8fb..c66e7c33 100644 --- a/pkg/cmd/run.go +++ b/pkg/cmd/run.go @@ -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 ( @@ -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 } diff --git a/pkg/tracejob/job.go b/pkg/tracejob/job.go index 019798aa..215239ac 100644 --- a/pkg/tracejob/job.go +++ b/pkg/tracejob/job.go @@ -4,6 +4,7 @@ import ( "fmt" "io" "io/ioutil" + "strconv" "github.com/iovisor/kubectl-trace/pkg/meta" batchv1 "k8s.io/api/batch/v1" @@ -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", } @@ -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), @@ -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)), }, }, },