From 79fceb53aa7e4d51bffbbfaff65f172add0f39ed Mon Sep 17 00:00:00 2001 From: felixgateru Date: Wed, 2 Aug 2023 08:14:55 +0300 Subject: [PATCH 1/2] Add version filter Signed-off-by: felixgateru --- api/endpoint.go | 3 +++ api/requests.go | 1 + api/transport.go | 7 +++++++ openapi/openapi.yaml | 11 +++++++++++ telemetry.go | 1 + timescale/timescale.go | 5 +++++ 6 files changed, 28 insertions(+) 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..7274e99 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, "version = :version") + params["version"] = filters.Version + } + switch len(queries) { case 0: return "", params From f841931a372cf8c818221805652d3d0d36500813 Mon Sep 17 00:00:00 2001 From: felixgateru Date: Thu, 3 Aug 2023 13:01:13 +0300 Subject: [PATCH 2/2] Update timescale/timescale.go Signed-off-by: felixgateru --- timescale/timescale.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/timescale/timescale.go b/timescale/timescale.go index 7274e99..5e65359 100644 --- a/timescale/timescale.go +++ b/timescale/timescale.go @@ -172,7 +172,7 @@ func generateQuery(filters callhome.TelemetryFilters) (string, map[string]interf } if filters.Version != "" { - queries = append(queries, "version = :version") + queries = append(queries, "mf_version = :version") params["version"] = filters.Version }