|
@@ -9,7 +9,6 @@ import (
|
9
|
9
|
restful "github.com/emicklei/go-restful"
|
10
|
10
|
restfulspec "github.com/emicklei/go-restful-openapi"
|
11
|
11
|
redis_client "github.com/garyburd/redigo/redis"
|
12
|
|
- "gogs.dyne.org/DECODE/decode-prototype-da/utils"
|
13
|
12
|
)
|
14
|
13
|
|
15
|
14
|
// ErrorResponse signals error messages back to the client
|
|
@@ -51,9 +50,7 @@ func (e dataResource) WebService() *restful.WebService {
|
51
|
50
|
tags := []string{"data"}
|
52
|
51
|
|
53
|
52
|
ws.Route(ws.GET("/").To(e.getAll).
|
54
|
|
- Doc("returns all of the data stored in a logical 'bucket'.").
|
55
|
|
- Param(ws.QueryParameter("from", "return data from this ISO8601 timestamp. Defaults to 24 hours ago.").DataType("date").DataFormat(utils.ISO8601)).
|
56
|
|
- Param(ws.QueryParameter("to", "finish at this ISO8601 timestamp ").DataType("date").DataFormat(utils.ISO8601)).
|
|
53
|
+ Doc("returns all of the data stored in a logical 'bucket' in the last 24 hours.").
|
57
|
54
|
Param(ws.QueryParameter("bucket-uid", "name of the 'bucket' of data").DataType("string")).
|
58
|
55
|
Metadata(restfulspec.KeyOpenAPITags, tags).
|
59
|
56
|
Writes([]DataResponse{}).
|
|
@@ -73,48 +70,20 @@ func (e dataResource) WebService() *restful.WebService {
|
73
|
70
|
}
|
74
|
71
|
func (e dataResource) getAll(request *restful.Request, response *restful.Response) {
|
75
|
72
|
|
76
|
|
- fromStr := request.QueryParameter("from")
|
77
|
|
- toStr := request.QueryParameter("to")
|
78
|
73
|
prefix := request.QueryParameter("bucket-uid")
|
79
|
74
|
|
80
|
75
|
timestep := time.Second
|
81
|
|
- expiry := time.Duration(0)
|
|
76
|
+ expiry := time.Duration(time.Hour * 24)
|
82
|
77
|
|
83
|
78
|
ts := NewTimeSeries(prefix, timestep, expiry, e.pool)
|
84
|
|
- var from, to time.Time
|
85
|
|
- var err error
|
86
|
79
|
|
87
|
80
|
// TODO : review should this be UTC?
|
88
|
|
- now := time.Now()
|
89
|
|
-
|
90
|
|
- if fromStr == "" {
|
91
|
|
- // default to 24 hours ago
|
92
|
|
- from = now.Add(-(time.Hour * 24))
|
93
|
|
- } else {
|
94
|
|
-
|
95
|
|
- from, err = time.Parse(utils.ISO8601, fromStr)
|
96
|
|
-
|
97
|
|
- if err != nil {
|
98
|
|
- response.WriteHeaderAndEntity(http.StatusBadRequest, ErrorResponse{Error: err.Error()})
|
99
|
|
- return
|
100
|
|
- }
|
101
|
|
-
|
102
|
|
- }
|
103
|
|
- if toStr == "" {
|
104
|
|
- //default to now
|
105
|
|
- to = now
|
106
|
|
- } else {
|
107
|
|
- to, err = time.Parse(utils.ISO8601, toStr)
|
108
|
|
-
|
109
|
|
- if err != nil {
|
110
|
|
- response.WriteHeaderAndEntity(http.StatusBadRequest, ErrorResponse{Error: err.Error()})
|
111
|
|
- return
|
112
|
|
- }
|
113
|
|
- }
|
|
81
|
+ to := time.Now()
|
|
82
|
+ from := to.Add(-(time.Hour * 24))
|
114
|
83
|
|
115
|
84
|
data := []*DataResponse{}
|
116
|
85
|
|
117
|
|
- err = ts.FetchRange(from, to, &data)
|
|
86
|
+ err := ts.FetchRange(from, to, &data)
|
118
|
87
|
|
119
|
88
|
if err != nil {
|
120
|
89
|
response.WriteHeaderAndEntity(http.StatusInternalServerError, ErrorResponse{Error: err.Error()})
|
|
@@ -140,7 +109,7 @@ func (e dataResource) append(request *restful.Request, response *restful.Respons
|
140
|
109
|
|
141
|
110
|
prefix := data.Bucket
|
142
|
111
|
timestep := time.Second
|
143
|
|
- expiry := time.Duration(0)
|
|
112
|
+ expiry := time.Duration(time.Hour * 24)
|
144
|
113
|
|
145
|
114
|
ts := NewTimeSeries(prefix, timestep, expiry, e.pool)
|
146
|
115
|
|