tsdbjson

package
v0.0.0-...-fe13f99 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 1, 2018 License: Apache-2.0 Imports: 8 Imported by: 19

Documentation

Overview

Package tsdbjson handles tsdb JSON requests and responses. Package tsdbjson must not depend on any other scotty packages except tsdb and its sub packages. That is tsdbjson translates between JSON and requests that scotty understands but does not fulfill the requests.

Index

Constants

View Source
const (
	// HostName tag name
	HostName = "HostName"
	// AppName tag name
	AppName = "appname"
	// Region tag name
	Region = "region"
	// IpAddress tag name
	IpAddress = "ipaddress"
)

Variables

View Source
var (
	// The filter is unsupported.
	ErrUnsupportedFilter = errors.New("tsdbjson: Unsupported filter")
	// The aggregator is unsupported.
	ErrUnsupportedAggregator = errors.New("tsdbjson: Unsupported aggregator")
	// Bad value in json field.
	ErrBadValue = errors.New("tsdbjson: Bad value")
)

Functions

func AllFilterDescriptions

func AllFilterDescriptions() map[string]*FilterDescription

AllFilterDescriptions returns all the filter descriptions keyed by filter name. The return value is used to serve /api/config/filters OpenTSDB requests.

func Escape

func Escape(s string) string

Escape escapes s for open TSDB. "Health Metric" -> "Health_20Metric"

func NewAggregatorGenerator

func NewAggregatorGenerator(
	aggregator string, downSample *DownSampleSpec, rateSpec *RateSpec) (
	tsdb.AggregatorGenerator, error)

NewAggregatorGenerator creates a new aggregator generator. aggregator is the aggregator type such as "avg" or "sum" downSample is optional and includes the down sample specification. rateSpec is also optional and includes the rate specification.

func NewTagFilter

func NewTagFilter(filterType, filterValue string) (tsdb.TagFilter, error)

NewTagFilter creates a new tag filter. filterType is the filter type such as "literal_or" or "wildcard" filterValue is the filter value.

func Unescape

func Unescape(s string) string

Unescape unescapes s from open TSDB. "Health_20Metric" -> "Health Metric"

Types

type AggregatorSpec

type AggregatorSpec struct {
	// the aggregator type such as "avg" or "sum"
	Type string
	// The optional down sample specification
	DownSample *DownSampleSpec
	// The optional rate specification
	RateOptions *RateSpec
}

AggregatorSpec represents the aggregator specification in a parsed /api/query request

type DownSampleSpec

type DownSampleSpec struct {
	// down sample duration
	DurationInSeconds float64
	// down sample type such as "avg" or "sum"
	Type string
	// down sample fill instruction such as "nan" or "zero" or "null"
	// Empty string means no fill.
	Fill string
}

DownSampleSpec represents the down sample specification in a parsed /api/query request

func (*DownSampleSpec) String

func (d *DownSampleSpec) String() string

type Error

type Error struct {
	E errorCodeType `json:"error"`
}

Error represents an open tsdb error

func NewError

func NewError(status int, err error) *Error

NewError returns a open tsdb error with a particular status

func (*Error) Error

func (e *Error) Error() string

func (*Error) Status

func (e *Error) Status() int

type Filter

type Filter struct {
	// The type such as literal_or, iliteral_or, wildcard, etc.
	Type string `json:"type"`
	// The tag name.
	Tagk string `json:"tagk"`
	// The filter value which depends on the filter type
	Filter string `json:"filter"`
	// True if results should be grouped by this tag
	GroupBy bool `json:"groupBy"`
}

Filter represents a filter in a query request

type FilterDescription

type FilterDescription struct {
	Examples    string `json:"examples"`
	Description string `json:"description"`
}

FilterDescription represents a description of a filter

type FilterSpec

type FilterSpec struct {
	// The filter type such as "literal_or"
	Type string
	// The filter value
	Value string
}

FilterSpec represents a filter specification in a parsed /api/query JSON request

func (*FilterSpec) String

func (f *FilterSpec) String() string

type ParsedQuery

type ParsedQuery struct {
	// The metric name
	Metric string
	// The aggregator specification
	Aggregator AggregatorSpec
	// Start time inclusive in seconds since Jan 1, 1970
	Start float64
	// End time exclusive in seconds since Jan 1, 1970
	End float64
	// Options
	Options ParsedQueryOptions
}

ParsedQuery represents a single query in a parsed /api/query request

func ParseQueryRequest

func ParseQueryRequest(
	request *QueryRequest) ([]ParsedQuery, error)

ParseQueryRequest takes a JSON /api/query request as input and returns zero or more parsed queries.

func (*ParsedQuery) EnsureStartTimeRecentEnough

func (p *ParsedQuery) EnsureStartTimeRecentEnough()

EnsureStartTimeRecentEnough moves start time closer to end time if the rollup span is too small for the time range. Otherwise, it is a no-op.

type ParsedQueryOptions

type ParsedQueryOptions struct {
	// Optional filter on host name
	HostNameFilter *FilterSpec
	// Optional filter on application name
	AppNameFilter *FilterSpec
	// Optional filter on region
	RegionFilter *FilterSpec
	// Optional filter on ipaddress
	IpAddressFilter *FilterSpec
	// True if results should be grouped by host name
	GroupByHostName bool
	// True if results should be grouped by application name
	GroupByAppName bool
	// True if results should be grouped by region
	GroupByRegion bool
	// True if results should be grouped by ip address
	GroupByIpAddress bool
}

ParsedQueryOptions represents the optional items in a parsed query

type Query

type Query struct {
	// The metric name in TSDB escaped form e.g "A_20Metric"
	Metric string `json:"metric"`
	// The aggregator type such as "avg" or "sum"
	Aggregator string `json:"aggregator"`
	// The rate options
	RateOptions *RateSpec `json:"rateOptions,omitempty"`
	// The down sample specification such as "15m_avg"
	DownSample string `json:"downsample"`
	// The filters
	Filters []*Filter `json:"filters"`
	// Tags field for cloud health proxy only. Scotty does not support it.
	Tags map[string]string `json:"tags"`
}

Query represents a single query in an /api/query request

type QueryRequest

type QueryRequest struct {
	// Start time in millis since Jan 1, 1970 inclusive
	StartInMillis int64 `json:"start"`
	// The queries
	Queries []*Query `json:"queries"`
	// End time in millis since Jan 1, 1970 exclusive
	EndInMillis int64 `json:"end"`
}

QueryRequest represents an an /api/query request

type RateSpec

type RateSpec struct {
	Counter    bool    `json:"counter"`
	CounterMax float64 `json:"counterMax"`
	ResetValue float64 `json:"resetValue"`
}

RateSpec represents the rate options for a query

type TimeSeries

type TimeSeries struct {
	// The metric name
	Metric string `json:"metric"`
	// Tag names and values this time series represents
	Tags map[string]string `json:"tags"`
	// List of tag names that are aggregated into this time series
	AggregateTags []string `json:"aggregateTags"`
	// The time series
	Dps tsdb.TimeSeries `json:"dps"`
}

TimeSeries represents a single time series in JSON. The response of an /api/query request is zero or more of these values

func NewTimeSeriesSlice

func NewTimeSeriesSlice(
	timeSeriesSet *tsdb.TaggedTimeSeriesSet) []TimeSeries

NewTimeSeriesSlice creates a tsdb query json response.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL