schema

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2020 License: AGPL-3.0, Apache-2.0 Imports: 18 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidEmptyName = errors.New("name cannot be empty")
View Source
var ErrInvalidFormat = errors.New("invalid format")
View Source
var ErrInvalidInput = errors.New("invalid input")
View Source
var ErrInvalidIntervalzero = errors.New("interval cannot be 0")
View Source
var ErrInvalidMtype = errors.New("invalid mtype")
View Source
var ErrInvalidOrgIdzero = errors.New("org-id cannot be 0")
View Source
var ErrStringTooShort = errors.New("string too short")
View Source
var ErrUnknownPartitionMethod = errors.New("unknown partition method")

Functions

func EatDots

func EatDots(name string) string

EatDots removes multiple consecutive, leading, and trailing dots from name. If the provided name is only dots, it will return an empty string The vast majority of names will not need to be modified, so we optimize for that case. This function only requires allocations if the name does need to be modified.

func IsSpanValid

func IsSpanValid(span uint32) bool

func Reslice

func Reslice(in []*MetricData, size int) [][]*MetricData

Reslice reslices a slice into smaller slices of the given max size.

func SanitizeNameAsTagValue

func SanitizeNameAsTagValue(name string) string

SanitizeNameAsTagValue takes a name and potentially modifies it to ensure it is a valid value that can be used as a tag value. This is important when we index metric names as values of the tag "name"

func ValidateTag

func ValidateTag(tag string) error

func ValidateTagKey

func ValidateTagKey(key string) bool

ValidateTagKey validates tag key requirements as defined in graphite docs

func ValidateTagValue

func ValidateTagValue(value string) bool

ValidateTagValue is the same as the above ValidateTagKey, but for the tag value

func ValidateTags

func ValidateTags(tags []string) error

ValidateTags returns whether all tags are in a valid format. a valid format is anything that looks like key=value, the length of key and value must be >0 and both cannot contain the certain prohibited characters

Types

type AMKey

type AMKey struct {
	MKey    MKey
	Archive Archive
}

AMKey is a multi-tenant key with archive extension so you can refer to rollup archives

func AMKeyFromString

func AMKeyFromString(s string) (AMKey, error)

func GetAMKey

func GetAMKey(m MKey, method Method, span uint32) AMKey

GetAMKey helps to easily get an AMKey from a given MKey

func (AMKey) String

func (a AMKey) String() string

type Archive

type Archive uint16

Archive represents a metric archive the zero value represents a raw metric any non-zero value represents a certain aggregation method (lower 8 bits) and aggregation span (higher 8 bits)

func ArchiveFromString

func ArchiveFromString(s string) (Archive, error)

func NewArchive

func NewArchive(method Method, span uint32) Archive

important: caller must make sure to call IsSpanValid first

func (*Archive) DecodeMsg

func (z *Archive) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (Archive) EncodeMsg

func (z Archive) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (Archive) MarshalMsg

func (z Archive) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (Archive) Method

func (a Archive) Method() Method

func (Archive) Msgsize

func (z Archive) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (Archive) Span

func (a Archive) Span() uint32

func (Archive) String

func (a Archive) String() string

String returns the traditional key suffix like sum_600 etc (invalid to call this for raw archives)

func (*Archive) UnmarshalMsg

func (z *Archive) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type Key

type Key [16]byte

Key identifies a metric

func (*Key) DecodeMsg

func (z *Key) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (*Key) EncodeMsg

func (z *Key) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (*Key) MarshalMsg

func (z *Key) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (*Key) Msgsize

func (z *Key) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*Key) UnmarshalMsg

func (z *Key) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type MKey

type MKey struct {
	Key Key
	Org uint32
}

MKey uniquely identifies a metric in a multi-tenant context

func MKeyFromString

func MKeyFromString(s string) (MKey, error)

KeyFromString parses a string id to an MKey string id must be of form orgid.<hexadecimal 128bit hash>

func (*MKey) DecodeMsg

func (z *MKey) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (*MKey) EncodeMsg

func (z *MKey) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (*MKey) MarshalMsg

func (z *MKey) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (*MKey) Msgsize

func (z *MKey) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (MKey) String

func (m MKey) String() string

func (*MKey) UnmarshalMsg

func (z *MKey) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type Method

type Method uint8
const (
	Avg Method = iota + 1 // avg
	Sum                   // sum
	Lst                   // lst
	Max                   // max
	Min                   // min
	Cnt                   // cnt
)

func MethodFromString

func MethodFromString(input string) (Method, error)

func (Method) String

func (i Method) String() string

type MetricData

type MetricData struct {
	Id       string   `json:"id"`
	OrgId    int      `json:"org_id"`
	Name     string   `json:"name"`
	Interval int      `json:"interval"`
	Value    float64  `json:"value"`
	Unit     string   `json:"unit"`
	Time     int64    `json:"time"`
	Mtype    string   `json:"mtype"`
	Tags     []string `json:"tags"`
}

MetricData contains all metric metadata (some as fields, some as tags) and a datapoint

func (*MetricData) DecodeMsg

func (z *MetricData) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (*MetricData) EncodeMsg

func (z *MetricData) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (*MetricData) MarshalMsg

func (z *MetricData) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (*MetricData) Msgsize

func (z *MetricData) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*MetricData) PartitionID

func (m *MetricData) PartitionID(method PartitionByMethod, partitions int32) (int32, error)

func (*MetricData) SetId

func (m *MetricData) SetId()

returns a id (hash key) in the format OrgId.md5Sum the md5sum is a hash of the the concatenation of the metric + each tag key:value pair (in metrics2.0 sense, so also fields), sorted alphabetically.

func (*MetricData) UnmarshalMsg

func (z *MetricData) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

func (*MetricData) Validate

func (m *MetricData) Validate() error

type MetricDataArray

type MetricDataArray []*MetricData

can be used by some encoders, such as msgp

func (*MetricDataArray) DecodeMsg

func (z *MetricDataArray) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (MetricDataArray) EncodeMsg

func (z MetricDataArray) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (MetricDataArray) MarshalMsg

func (z MetricDataArray) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (MetricDataArray) Msgsize

func (z MetricDataArray) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*MetricDataArray) UnmarshalMsg

func (z *MetricDataArray) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type MetricDefinition

type MetricDefinition struct {
	Id       MKey   `json:"mkey"`
	OrgId    uint32 `json:"org_id"`
	Name     string `json:"name"`
	Interval int    `json:"interval"`
	Unit     string `json:"unit"`
	Mtype    string `json:"mtype"`

	// some users of MetricDefinition (f.e. MetricTank) might add a "name" tag
	// to this slice which allows querying by name as a tag. this special tag
	// should not be stored or transmitted over the network, otherwise it may
	// just get overwritten by the receiver.
	Tags       []string `json:"tags"`
	LastUpdate int64    `json:"lastUpdate"` // unix timestamp
	Partition  int32    `json:"partition"`
	// contains filtered or unexported fields
}

func MetricDefinitionFromMetricData

func MetricDefinitionFromMetricData(d *MetricData) *MetricDefinition

MetricDefinitionFromMetricData yields a MetricDefinition that has no references to the original MetricData

func (*MetricDefinition) Clone

Clone() returns a copy of the MetricDefinition. It uses atomic operations to read certain properties that get updated atomically

func (*MetricDefinition) DecodeMsg

func (z *MetricDefinition) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (*MetricDefinition) EncodeMsg

func (z *MetricDefinition) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (*MetricDefinition) MarshalMsg

func (z *MetricDefinition) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (*MetricDefinition) Msgsize

func (z *MetricDefinition) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*MetricDefinition) NameSanitizedAsTagValue

func (m *MetricDefinition) NameSanitizedAsTagValue() string

func (*MetricDefinition) NameWithTags

func (m *MetricDefinition) NameWithTags() string

NameWithTags deduplicates the name and tags strings by storing their content as a single string in .nameWithTags and then makes .Name and the .Tags slices of it. Once this has been done it won't do it a second time, but just reuse the already generated .nameWithTags. It returns the deduplicated name with tags.

func (*MetricDefinition) PartitionID

func (m *MetricDefinition) PartitionID(method PartitionByMethod, partitions int32) (int32, error)

func (*MetricDefinition) SetId

func (m *MetricDefinition) SetId()

func (*MetricDefinition) UnmarshalMsg

func (z *MetricDefinition) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

func (*MetricDefinition) Validate

func (m *MetricDefinition) Validate() error

type MetricPoint

type MetricPoint struct {
	MKey  MKey
	Value float64
	Time  uint32
}

MetricPoint is a simple way to represent a point of a metric it can be serialized/deserialized with and without the Org field of the key.

func (*MetricPoint) Marshal

func (m *MetricPoint) Marshal(b []byte) (o []byte, err error)

Marshal marshals the MetricPoint

func (*MetricPoint) Marshal32

func (m *MetricPoint) Marshal32(b []byte) (o []byte, err error)

Marshal32 marshals the MetricPoint directly to b. b must have a cap-len difference of at least 32 bytes.

func (*MetricPoint) MarshalWithoutOrg

func (m *MetricPoint) MarshalWithoutOrg(b []byte) (o []byte, err error)

MarshalWithoutOrg marshals in a non-multi-tenancy aware way

func (*MetricPoint) MarshalWithoutOrg28

func (m *MetricPoint) MarshalWithoutOrg28(b []byte) (o []byte, err error)

MarshalWithoutOrg28 marshals directly to b in a non-multi-tenancy aware way b must have a cap-len difference of at least 28 bytes.

func (*MetricPoint) Unmarshal

func (m *MetricPoint) Unmarshal(bts []byte) (o []byte, err error)

Unmarshal unmarshals the MetricPoint

func (*MetricPoint) UnmarshalWithoutOrg

func (m *MetricPoint) UnmarshalWithoutOrg(bts []byte) (o []byte, err error)

UnmarshalWithoutOrg unmarshals in a non-multi-tenancy aware way

func (*MetricPoint) Valid

func (m *MetricPoint) Valid() bool

type PartitionByMethod

type PartitionByMethod uint8
const (
	// partition by organization id only
	PartitionByOrg PartitionByMethod = iota

	// partition by the metric name only
	PartitionBySeries

	// partition by metric name and tags, with the best distribution
	// recommended for new deployments.
	PartitionBySeriesWithTags

	// partition by metric name and tags, with a sub-optimal distribution when using tags.
	// compatible with PartitionBySeries if a metric has no tags,
	// making it possible to adopt tags for existing PartitionBySeries deployments without a migration.
	PartitionBySeriesWithTagsFnv
)

func PartitonMethodFromString

func PartitonMethodFromString(input string) (PartitionByMethod, error)

type PartitionedMetric

type PartitionedMetric interface {
	Validate() error
	SetId()
	// PartitionID returns the partition id that should be used for this metric.
	PartitionID(method PartitionByMethod, partitions int32) (int32, error)
}

type Point

type Point struct {
	Val float64
	Ts  uint32
}

func (*Point) DecodeMsg

func (z *Point) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (Point) EncodeMsg

func (z Point) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (Point) MarshalMsg

func (z Point) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (Point) Msgsize

func (z Point) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*Point) UnmarshalMsg

func (z *Point) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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