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.
@@ -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)
