Skip to content

Commit

Permalink
Support passing the start time through the API.
Browse files Browse the repository at this point in the history
  • Loading branch information
ericsnowcurrently committed Jun 21, 2016
1 parent fc2313a commit 8aa1b39
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
11 changes: 11 additions & 0 deletions apiserver/debuglog.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"net/url"
"strconv"
"syscall"
"time"

"github.com/juju/errors"
"github.com/juju/loggo"
Expand Down Expand Up @@ -149,6 +150,7 @@ func (s *debugLogSocketImpl) sendError(err error) {

// debugLogParams contains the parsed debuglog API request parameters.
type debugLogParams struct {
start time.Time
maxLines uint
fromTheStart bool
noTail bool
Expand All @@ -165,6 +167,15 @@ type debugLogParams struct {
func readDebugLogParams(queryMap url.Values) (*debugLogParams, error) {
params := new(debugLogParams)

if value := queryMap.Get("startTime"); value != "" {
unix, err := strconv.ParseUint(value, 10, 64)
if err != nil {
return nil, errors.Errorf("startTime value %q is not a valid number", value)
}
// 1 second granularity is good enough.
params.start = time.Unix(int64(unix), 0)
}

if value := queryMap.Get("maxLines"); value != "" {
num, err := strconv.ParseUint(value, 10, 64)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions apiserver/debuglog_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func handleDebugLogDBRequest(

func makeLogTailerParams(reqParams *debugLogParams) *state.LogTailerParams {
params := &state.LogTailerParams{
StartTime: reqParams.start,
MinLevel: reqParams.filterLevel,
NoTail: reqParams.noTail,
InitialLines: int(reqParams.backlog),
Expand All @@ -85,6 +86,7 @@ func makeLogTailerParams(reqParams *debugLogParams) *state.LogTailerParams {
}
if reqParams.fromTheStart {
params.InitialLines = 0
params.StartTime = time.Time{}
}
return params
}
Expand Down

0 comments on commit 8aa1b39

Please sign in to comment.