From 9b0091d487cfadc7f6b967178a31193006cc1dbb Mon Sep 17 00:00:00 2001 From: Tobias Schmidt Date: Sun, 12 Nov 2017 01:27:45 +0100 Subject: [PATCH] Add storage.Queryable and storage.QueryableFunc In order to compose different querier implementations more easily, this change introduces a separate storage.Queryable interface grouping the query (Querier) function of the storage. Furthermore, it adds a QueryableFunc type to ease writing very simple queryable implementations. --- storage/interface.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/storage/interface.go b/storage/interface.go index 2b2179252..f9bfc6a27 100644 --- a/storage/interface.go +++ b/storage/interface.go @@ -31,12 +31,11 @@ var ( // Storage ingests and manages samples, along with various indexes. All methods // are goroutine-safe. Storage implements storage.SampleAppender. type Storage interface { + Queryable + // StartTime returns the oldest timestamp stored in the storage. StartTime() (int64, error) - // Querier returns a new Querier on the storage. - Querier(ctx context.Context, mint, maxt int64) (Querier, error) - // Appender returns a new appender against the storage. Appender() (Appender, error) @@ -44,6 +43,12 @@ type Storage interface { Close() error } +// A Queryable handles queries against a storage. +type Queryable interface { + // Querier returns a new Querier on the storage. + Querier(ctx context.Context, mint, maxt int64) (Querier, error) +} + // Querier provides reading access to time series data. type Querier interface { // Select returns a set of series that matches the given label matchers. @@ -56,6 +61,15 @@ type Querier interface { Close() error } +// QueryableFunc is an adapter to allow the use of ordinary functions as +// Queryables. It follows the idea of http.HandlerFunc. +type QueryableFunc func(ctx context.Context, mint, maxt int64) (Querier, error) + +// Querier calls f() with the given parameters. +func (f QueryableFunc) Querier(ctx context.Context, mint, maxt int64) (Querier, error) { + return f(ctx, mint, maxt) +} + // Appender provides batched appends against a storage. type Appender interface { Add(l labels.Labels, t int64, v float64) (uint64, error)