Skip to content

Commit

Permalink
Merge pull request #22 from 1998-felix/service-filter
Browse files Browse the repository at this point in the history
NOISSUE-Add service filter
  • Loading branch information
drasko authored Aug 3, 2023
2 parents dca6147 + 03f9d09 commit 1a73c9a
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 0 deletions.
3 changes: 3 additions & 0 deletions api/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func retrieveEndpoint(svc callhome.Service) endpoint.Endpoint {
Country: req.country,
City: req.city,
Version: req.version,
Service: req.service,
}
tm, err := svc.Retrieve(ctx, pm, filter)
if err != nil {
Expand Down Expand Up @@ -74,6 +75,7 @@ func retrieveSummaryEndpoint(svc callhome.Service) endpoint.Endpoint {
Country: req.country,
City: req.city,
Version: req.version,
Service: req.service,
}
summary, err := svc.RetrieveSummary(ctx, filter)
if err != nil {
Expand All @@ -98,6 +100,7 @@ func serveUI(svc callhome.Service) endpoint.Endpoint {
Country: req.country,
City: req.city,
Version: req.version,
Service: req.service,
}
res, err := svc.ServeUI(ctx, filter)
return uiRes{
Expand Down
1 change: 1 addition & 0 deletions api/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type listTelemetryReq struct {
country string
city string
version string
service string
}

func (req listTelemetryReq) validate() error {
Expand Down
7 changes: 7 additions & 0 deletions api/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const (
countryKey = "country"
cityKey = "city"
versionKey = "version"
serviceKey = "service"
defOffset = 0
defLimit = 10
staticDir = "./web/static"
Expand Down Expand Up @@ -197,6 +198,11 @@ func decodeRetrieve(_ context.Context, r *http.Request) (interface{}, error) {
return nil, err
}

se, err := ReadStringQuery(r, serviceKey, "")
if err != nil {
return nil, err
}

req := listTelemetryReq{
offset: o,
limit: l,
Expand All @@ -205,6 +211,7 @@ func decodeRetrieve(_ context.Context, r *http.Request) (interface{}, error) {
country: co,
city: ci,
version: ve,
service: se,
}
return req, nil
}
Expand Down
11 changes: 11 additions & 0 deletions openapi/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ paths:
- $ref: "#/components/parameters/Country"
- $ref: "#/components/parameters/City"
- $ref: "#/components/parameters/Version"
- $ref: "#/components/parameters/Service"
responses:
"200":
description: found
Expand All @@ -51,6 +52,7 @@ paths:
- $ref: "#/components/parameters/Country"
- $ref: "#/components/parameters/City"
- $ref: "#/components/parameters/Version"
- $ref: "#/components/parameters/Service"
responses:
"200":
description: found
Expand Down Expand Up @@ -87,6 +89,7 @@ paths:
- $ref: "#/components/parameters/Country"
- $ref: "#/components/parameters/City"
- $ref: "#/components/parameters/Version"
- $ref: "#/components/parameters/Service"
tags:
- telemetry
summary: Retrieve telemetry events
Expand Down Expand Up @@ -170,6 +173,14 @@ components:
type: string
default: ""
required: false
Service:
name: service
description: From service filter.
in: query
schema:
type: string
default: ""
required: false
requestBodies:
TelemetryReq:
content:
Expand Down
1 change: 1 addition & 0 deletions telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type TelemetryFilters struct {
Country string
City string
Version string
Service string
}

type PageMetadata struct {
Expand Down
5 changes: 5 additions & 0 deletions timescale/timescale.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,11 @@ func generateQuery(filters callhome.TelemetryFilters) (string, map[string]interf
params["version"] = filters.Version
}

if filters.Service != "" {
queries = append(queries, "service = :service")
params["service"] = filters.Service
}

switch len(queries) {
case 0:
return "", params
Expand Down

0 comments on commit 1a73c9a

Please sign in to comment.