From 2d8437fdd8a629cd75f3364110d4c1ce5a973ae0 Mon Sep 17 00:00:00 2001 From: Filip Barl Date: Tue, 20 Jun 2017 11:45:04 +0200 Subject: [PATCH] Addressed the comments. --- app/api_topologies.go | 23 +++++++++++--------- app/api_topology.go | 2 +- client/app/scripts/components/time-travel.js | 2 +- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/app/api_topologies.go b/app/api_topologies.go index 334ecdd596..bb16836fe9 100644 --- a/app/api_topologies.go +++ b/app/api_topologies.go @@ -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 @@ -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) @@ -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) diff --git a/app/api_topology.go b/app/api_topology.go index 5315ce22e7..173e275b99 100644 --- a/app/api_topology.go +++ b/app/api_topology.go @@ -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() ) diff --git a/client/app/scripts/components/time-travel.js b/client/app/scripts/components/time-travel.js index d59e2ca8a1..282e7dc634 100644 --- a/client/app/scripts/components/time-travel.js +++ b/client/app/scripts/components/time-travel.js @@ -269,7 +269,7 @@ function mapStateToProps({ scope, root }, { params }) { const cloudInstance = root.instances[params.orgId] || {}; const featureFlags = cloudInstance.featureFlags || []; return { - hasTimeTravel: featureFlags.includes('time-travel') || true, + hasTimeTravel: featureFlags.includes('time-travel'), timeTravelTransitioning: scope.get('timeTravelTransitioning'), topologyViewMode: scope.get('topologyViewMode'), currentTopology: scope.get('currentTopology'),