Skip to content

Commit

Permalink
Addressed the comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
fbarl committed Jun 20, 2017
1 parent 90350f1 commit c65b510
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
23 changes: 13 additions & 10 deletions app/api_topologies.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,14 +415,17 @@ type topologyStats struct {
FilteredNodes int `json:"filtered_nodes"`
}

// deserializedTimestamp converts the ISO8601 query param into a proper timestamp.
func deserializedTimestamp(timestampStr string) time.Time {
// If no timestamp is given, assume the current time.
timestamp := time.Now()
if timestampStr != "" {
timestamp, _ = time.Parse(time.RFC3339, timestampStr)
}
return timestamp
// deserializeTimestamp converts the ISO8601 query param into a proper timestamp.
func deserializeTimestamp(timestamp string) time.Time {
if timestamp != "" {
result, err := time.Parse(time.RFC3339, timestamp)
if err != nil {
log.Errorf("Error parsing timestamp '%s' - make sure the time format is correct", timestamp)
}
return result
}
// Default to current time if no timestamp is provided.
return time.Now()
}

// AddContainerFilters adds to the default Registry (topologyRegistry)'s containerFilters
Expand Down Expand Up @@ -487,7 +490,7 @@ func (r *Registry) walk(f func(APITopologyDesc)) {
// makeTopologyList returns a handler that yields an APITopologyList.
func (r *Registry) makeTopologyList(rep Reporter) CtxHandlerFunc {
return func(ctx context.Context, w http.ResponseWriter, req *http.Request) {
timestamp := deserializedTimestamp(req.URL.Query().Get("timestamp"))
timestamp := deserializeTimestamp(req.URL.Query().Get("timestamp"))
report, err := rep.Report(ctx, timestamp)
if err != nil {
respondWith(w, http.StatusInternalServerError, err)
Expand Down Expand Up @@ -577,7 +580,7 @@ func (r *Registry) captureRenderer(rep Reporter, f rendererHandler) CtxHandlerFu
return func(ctx context.Context, w http.ResponseWriter, req *http.Request) {
var (
topologyID = mux.Vars(req)["topology"]
timestamp = deserializedTimestamp(req.URL.Query().Get("timestamp"))
timestamp = deserializeTimestamp(req.URL.Query().Get("timestamp"))
)
if _, ok := r.get(topologyID); !ok {
http.NotFound(w, req)
Expand Down
2 changes: 1 addition & 1 deletion app/api_topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func handleWebsocket(
tick = time.Tick(loop)
wait = make(chan struct{}, 1)
topologyID = mux.Vars(r)["topology"]
startReportingAt = deserializedTimestamp(r.Form.Get("timestamp"))
startReportingAt = deserializeTimestamp(r.Form.Get("timestamp"))
channelOpenedAt = time.Now()
)

Expand Down

0 comments on commit c65b510

Please sign in to comment.