From 1d4d3668d822cb5f6df706d99057f813504d7121 Mon Sep 17 00:00:00 2001 From: Chris Goller Date: Wed, 21 Sep 2016 08:47:01 -0700 Subject: [PATCH] Update query interface to take database and rp --- influx/influx.go | 12 +++++++++++- mock/handlers.go | 8 ++++++-- models/proxy.go | 8 ++++++++ swagger.yaml | 4 ++++ timeseries.go | 8 ++++++-- 5 files changed, 35 insertions(+), 5 deletions(-) diff --git a/influx/influx.go b/influx/influx.go index 3706e7eb71..05d24c6fd4 100644 --- a/influx/influx.go +++ b/influx/influx.go @@ -34,7 +34,17 @@ func NewClient(host string) (*Client, error) { // include both the database and retention policy. In-flight requests can be // cancelled using the provided context. func (c *Client) Query(ctx context.Context, query mrfusion.Query) (mrfusion.Response, error) { - q := ixClient.NewQuery(string(query), "", "") + db := "" + if len(query.Database) > 0 { + db = query.Database + } + + rp := "" + if len(query.RP) > 0 { + rp = query.RP + } + + q := ixClient.NewQuery(query.Command, db, rp) resps := make(chan (response)) go func() { resp, err := c.ix.Query(q) diff --git a/mock/handlers.go b/mock/handlers.go index 6f09cbd025..436ae21a6c 100644 --- a/mock/handlers.go +++ b/mock/handlers.go @@ -57,8 +57,12 @@ func (m *Handler) SourcesID(ctx context.Context, params op.GetSourcesIDParams) m } func (m *Handler) Proxy(ctx context.Context, params op.PostSourcesIDProxyParams) middleware.Responder { - query := params.Query.Query - response, err := m.TimeSeries.Query(ctx, mrfusion.Query(*query)) + query := mrfusion.Query{ + Command: *params.Query.Query, + Database: params.Query.Database, + RP: params.Query.Rp, + } + response, err := m.TimeSeries.Query(ctx, mrfusion.Query(query)) if err != nil { return op.NewPostSourcesIDProxyDefault(500) } diff --git a/models/proxy.go b/models/proxy.go index a23024d116..0eb22d7643 100644 --- a/models/proxy.go +++ b/models/proxy.go @@ -19,6 +19,10 @@ swagger:model Proxy */ type Proxy struct { + /* database + */ + Database string `json:"database,omitempty"` + /* format */ Format *string `json:"format,omitempty"` @@ -28,6 +32,10 @@ type Proxy struct { Required: true */ Query *string `json:"query"` + + /* rp + */ + Rp string `json:"rp,omitempty"` } // Validate validates this proxy diff --git a/swagger.yaml b/swagger.yaml index dde33f8ad7..2066ab873b 100644 --- a/swagger.yaml +++ b/swagger.yaml @@ -788,6 +788,10 @@ definitions: properties: query: type: string + database: + type: string + rp: + type: string format: type: string enum: diff --git a/timeseries.go b/timeseries.go index a6c7af6f7c..0aafc052b2 100644 --- a/timeseries.go +++ b/timeseries.go @@ -6,8 +6,12 @@ import ( "golang.org/x/net/context" ) -// Used to retrieve a Response from a TimeSeries. -type Query string +// Query retrieves a Response from a TimeSeries. +type Query struct { + Command string // Command is the query itself + Database string // Database is optional and if empty will not be used. + RP string // RP is a retention policy and optional; if empty will not be used. +} // Row represents a single row returned from the execution of a single statement in a `Query`. type Row interface {