github.com/m3db/m3@v1.5.0/src/query/executor/types.go (about)

     1  // Copyright (c) 2019 Uber Technologies, Inc.
     2  //
     3  // Permission is hereby granted, free of charge, to any person obtaining a copy
     4  // of this software and associated documentation files (the "Software"), to deal
     5  // in the Software without restriction, including without limitation the rights
     6  // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     7  // copies of the Software, and to permit persons to whom the Software is
     8  // furnished to do so, subject to the following conditions:
     9  //
    10  // The above copyright notice and this permission notice shall be included in
    11  // all copies or substantial portions of the Software.
    12  //
    13  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    14  // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    15  // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    16  // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    17  // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    18  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    19  // THE SOFTWARE.
    20  
    21  package executor
    22  
    23  import (
    24  	"context"
    25  	"time"
    26  
    27  	"github.com/m3db/m3/src/query/block"
    28  	"github.com/m3db/m3/src/query/models"
    29  	"github.com/m3db/m3/src/query/parser"
    30  	"github.com/m3db/m3/src/query/parser/promql"
    31  	"github.com/m3db/m3/src/query/storage"
    32  	"github.com/m3db/m3/src/x/instrument"
    33  )
    34  
    35  // Engine executes a Query.
    36  type Engine interface {
    37  	// ExecuteProm runs the query and returns the result in a
    38  	// Prometheus-compatible format (primarily used for remote read paths).
    39  	ExecuteProm(
    40  		ctx context.Context,
    41  		query *storage.FetchQuery,
    42  		opts *QueryOptions,
    43  		fetchOpts *storage.FetchOptions,
    44  	) (storage.PromResult, error)
    45  
    46  	// ExecuteExpr runs the query DAG and closes the results channel once done.
    47  	ExecuteExpr(
    48  		ctx context.Context,
    49  		parser parser.Parser,
    50  		opts *QueryOptions,
    51  		fetchOpts *storage.FetchOptions,
    52  		params models.RequestParams,
    53  	) (block.Block, error)
    54  
    55  	// Options returns the currently configured options.
    56  	Options() EngineOptions
    57  
    58  	// Close kills all running queries and prevents new queries from being attached.
    59  	Close() error
    60  }
    61  
    62  // EngineOptions are used to create an engine.
    63  type EngineOptions interface {
    64  	// InstrumentOptions returns the instrument options and scope used
    65  	// for metrics.
    66  	InstrumentOptions() instrument.Options
    67  	// SetInstrumentOptions sets the instrument options and scope used
    68  	// for metrics.
    69  	SetInstrumentOptions(instrument.Options) EngineOptions
    70  
    71  	// Store returns the storage.
    72  	Store() storage.Storage
    73  	// SetStore sets the storage.
    74  	SetStore(storage.Storage) EngineOptions
    75  
    76  	// LookbackDuration returns the query lookback duration.
    77  	LookbackDuration() time.Duration
    78  	// SetLookbackDuration sets the query lookback duration.
    79  	SetLookbackDuration(time.Duration) EngineOptions
    80  
    81  	// ParseOptions returns the parse options.
    82  	ParseOptions() promql.ParseOptions
    83  	// SetParseOptions sets the parse options.
    84  	SetParseOptions(p promql.ParseOptions) EngineOptions
    85  }