github.com/go-graphite/carbonapi@v0.17.0/expr/interfaces/interface.go (about)

     1  package interfaces
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/go-graphite/carbonapi/expr/types"
     7  	"github.com/go-graphite/carbonapi/pkg/parser"
     8  )
     9  
    10  // Evaluator is an interface for any existing expression parser.
    11  type Evaluator interface {
    12  	// Fetch populates the values map being passed into it by translating input expressions into a series of
    13  	// parser.MetricRequest and fetching the raw data from the configured backend.
    14  	//
    15  	// It returns a map of only the data requested in the current invocation, scaled to a common step.
    16  	Fetch(ctx context.Context, e []parser.Expr, from, until int64, values map[parser.MetricRequest][]*types.MetricData) (map[parser.MetricRequest][]*types.MetricData, error)
    17  	// Eval uses the raw data within the values map being passed into it to in order to evaluate the input expression.
    18  	Eval(ctx context.Context, e parser.Expr, from, until int64, values map[parser.MetricRequest][]*types.MetricData) ([]*types.MetricData, error)
    19  }
    20  
    21  type Order int
    22  
    23  const (
    24  	Any Order = iota
    25  	Last
    26  )
    27  
    28  type RewriteFunctionMetadata struct {
    29  	Name     string
    30  	Filename string
    31  	Order    Order
    32  	F        RewriteFunction
    33  }
    34  
    35  type FunctionMetadata struct {
    36  	Name     string
    37  	Filename string
    38  	Order    Order
    39  	F        Function
    40  }
    41  
    42  // Function is interface that all graphite functions should follow
    43  type Function interface {
    44  	Do(ctx context.Context, evaluator Evaluator, e parser.Expr, from, until int64, values map[parser.MetricRequest][]*types.MetricData) ([]*types.MetricData, error)
    45  	Description() map[string]types.FunctionDescription
    46  }
    47  
    48  // RewriteFunction is interface that graphite functions that rewrite expressions should follow
    49  type RewriteFunction interface {
    50  	Do(ctx context.Context, evaluator Evaluator, e parser.Expr, from, until int64, values map[parser.MetricRequest][]*types.MetricData) (bool, []string, error)
    51  	Description() map[string]types.FunctionDescription
    52  }