github.com/m3db/m3@v1.5.0/src/query/models/params.go (about)

     1  // Copyright (c) 2018 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 models
    22  
    23  import (
    24  	"fmt"
    25  	"time"
    26  
    27  	xtime "github.com/m3db/m3/src/x/time"
    28  )
    29  
    30  // FormatType describes what format to return the data in.
    31  type FormatType int
    32  
    33  const (
    34  	// FormatPromQL returns results in Prom format
    35  	FormatPromQL FormatType = iota
    36  
    37  	infoMsg = "if this is causing issues for your use case, please file an " +
    38  		"issue on https://github.com/m3db/m3"
    39  )
    40  
    41  var (
    42  	// ErrMultiBlockDisabled indicates multi blocks are temporarily disabled.
    43  	ErrMultiBlockDisabled = fmt.Errorf("multiblock is temporarily disabled %s",
    44  		infoMsg)
    45  )
    46  
    47  // FetchedBlockType determines the type for fetched blocks, and how they are
    48  // transformed from storage type.
    49  type FetchedBlockType uint8
    50  
    51  const (
    52  	// TypeSingleBlock represents a single block which contains each encoded fetched
    53  	// series. Default block type for Prometheus queries.
    54  	TypeSingleBlock FetchedBlockType = iota
    55  	// TypeMultiBlock represents multiple blocks, each containing a time-based slice
    56  	// of encoded fetched series. Default block type for non-Prometheus queries.
    57  	//
    58  	// NB: Currently disabled.
    59  	TypeMultiBlock
    60  )
    61  
    62  // RequestParams represents the params from the request.
    63  type RequestParams struct {
    64  	Start xtime.UnixNano
    65  	End   xtime.UnixNano
    66  	// Now captures the current time and fixes it throughout the request, we
    67  	// may let people override it in the future.
    68  	Now              time.Time
    69  	Timeout          time.Duration
    70  	Step             time.Duration
    71  	Query            string
    72  	Debug            bool
    73  	KeepNans         bool
    74  	IncludeEnd       bool
    75  	BlockType        FetchedBlockType
    76  	FormatType       FormatType
    77  	LookbackDuration time.Duration
    78  }
    79  
    80  // ExclusiveEnd returns the end exclusive.
    81  func (r RequestParams) ExclusiveEnd() xtime.UnixNano {
    82  	if r.IncludeEnd {
    83  		return r.End.Add(r.Step)
    84  	}
    85  
    86  	return r.End
    87  }