diff --git a/api/endpoint.go b/api/endpoint.go index 6c3cbfd..7f75c66 100644 --- a/api/endpoint.go +++ b/api/endpoint.go @@ -44,6 +44,7 @@ func retrieveEndpoint(svc callhome.Service) endpoint.Endpoint { To: req.to, Country: req.country, City: req.city, + Version: req.version, } tm, err := svc.Retrieve(ctx, pm, filter) if err != nil { @@ -72,6 +73,7 @@ func retrieveSummaryEndpoint(svc callhome.Service) endpoint.Endpoint { To: req.to, Country: req.country, City: req.city, + Version: req.version, } summary, err := svc.RetrieveSummary(ctx, filter) if err != nil { @@ -95,6 +97,7 @@ func serveUI(svc callhome.Service) endpoint.Endpoint { To: req.to, Country: req.country, City: req.city, + Version: req.version, } res, err := svc.ServeUI(ctx, filter) return uiRes{ diff --git a/api/requests.go b/api/requests.go index a555c54..5f7dde1 100644 --- a/api/requests.go +++ b/api/requests.go @@ -46,6 +46,7 @@ type listTelemetryReq struct { to time.Time country string city string + version string } func (req listTelemetryReq) validate() error { diff --git a/api/transport.go b/api/transport.go index 16b516d..7f621a7 100644 --- a/api/transport.go +++ b/api/transport.go @@ -28,6 +28,7 @@ const ( toKey = "to" countryKey = "country" cityKey = "city" + versionKey = "version" defOffset = 0 defLimit = 10 staticDir = "./web/static" @@ -191,6 +192,11 @@ func decodeRetrieve(_ context.Context, r *http.Request) (interface{}, error) { return nil, err } + ve, err := ReadStringQuery(r, versionKey, "") + if err != nil { + return nil, err + } + req := listTelemetryReq{ offset: o, limit: l, @@ -198,6 +204,7 @@ func decodeRetrieve(_ context.Context, r *http.Request) (interface{}, error) { to: to, country: co, city: ci, + version: ve, } return req, nil } diff --git a/openapi/openapi.yaml b/openapi/openapi.yaml index e876107..a623513 100644 --- a/openapi/openapi.yaml +++ b/openapi/openapi.yaml @@ -29,6 +29,7 @@ paths: - $ref: "#/components/parameters/To" - $ref: "#/components/parameters/Country" - $ref: "#/components/parameters/City" + - $ref: "#/components/parameters/Version" responses: "200": description: found @@ -49,6 +50,7 @@ paths: - $ref: "#/components/parameters/To" - $ref: "#/components/parameters/Country" - $ref: "#/components/parameters/City" + - $ref: "#/components/parameters/Version" responses: "200": description: found @@ -84,6 +86,7 @@ paths: - $ref: "#/components/parameters/To" - $ref: "#/components/parameters/Country" - $ref: "#/components/parameters/City" + - $ref: "#/components/parameters/Version" tags: - telemetry summary: Retrieve telemetry events @@ -159,6 +162,14 @@ components: type: string default: "" required: false + Version: + name: version + description: From version filter. + in: query + schema: + type: string + default: "" + required: false requestBodies: TelemetryReq: content: diff --git a/telemetry.go b/telemetry.go index 2ffd060..b4449fa 100644 --- a/telemetry.go +++ b/telemetry.go @@ -25,6 +25,7 @@ type TelemetryFilters struct { To time.Time Country string City string + Version string } type PageMetadata struct { diff --git a/timescale/timescale.go b/timescale/timescale.go index 6ffd728..5e65359 100644 --- a/timescale/timescale.go +++ b/timescale/timescale.go @@ -171,6 +171,11 @@ func generateQuery(filters callhome.TelemetryFilters) (string, map[string]interf params["city"] = filters.City } + if filters.Version != "" { + queries = append(queries, "mf_version = :version") + params["version"] = filters.Version + } + switch len(queries) { case 0: return "", params