metrictank: github.com/grafana/metrictank/schema Index | Files | Directories

package schema

import "github.com/grafana/metrictank/schema"

Index

Package Files

archive.go archive_gen.go key.go key_gen.go method_string.go metric.go metric_gen.go metricpoint.go partition.go point.go point_gen.go reslice.go

Variables

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

func EatDots Uses

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 Uses

func IsSpanValid(span uint32) bool

func Reslice Uses

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

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

func SanitizeNameAsTagValue Uses

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 Uses

func ValidateTag(tag string) error

func ValidateTagKey Uses

func ValidateTagKey(key string) bool

ValidateTagKey validates tag key requirements as defined in graphite docs

func ValidateTagValue Uses

func ValidateTagValue(value string) bool

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

func ValidateTags Uses

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

type AMKey Uses

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 Uses

func AMKeyFromString(s string) (AMKey, error)

func GetAMKey Uses

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

GetAMKey helps to easily get an AMKey from a given MKey

func (AMKey) String Uses

func (a AMKey) String() string

type Archive Uses

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 Uses

func ArchiveFromString(s string) (Archive, error)

func NewArchive Uses

func NewArchive(method Method, span uint32) Archive

important: caller must make sure to call IsSpanValid first

func (*Archive) DecodeMsg Uses

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

DecodeMsg implements msgp.Decodable

func (Archive) EncodeMsg Uses

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

EncodeMsg implements msgp.Encodable

func (Archive) MarshalMsg Uses

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

MarshalMsg implements msgp.Marshaler

func (Archive) Method Uses

func (a Archive) Method() Method

func (Archive) Msgsize Uses

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 Uses

func (a Archive) Span() uint32

func (Archive) String Uses

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 Uses

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

UnmarshalMsg implements msgp.Unmarshaler

type Key Uses

type Key [16]byte

Key identifies a metric

func (*Key) DecodeMsg Uses

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

DecodeMsg implements msgp.Decodable

func (*Key) EncodeMsg Uses

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

EncodeMsg implements msgp.Encodable

func (*Key) MarshalMsg Uses

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

MarshalMsg implements msgp.Marshaler

func (*Key) Msgsize Uses

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 Uses

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

UnmarshalMsg implements msgp.Unmarshaler

type MKey Uses

type MKey struct {
    Key Key
    Org uint32
}

MKey uniquely identifies a metric in a multi-tenant context

func MKeyFromString Uses

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 Uses

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

DecodeMsg implements msgp.Decodable

func (*MKey) EncodeMsg Uses

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

EncodeMsg implements msgp.Encodable

func (*MKey) MarshalMsg Uses

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

MarshalMsg implements msgp.Marshaler

func (*MKey) Msgsize Uses

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 Uses

func (m MKey) String() string

func (*MKey) UnmarshalMsg Uses

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

UnmarshalMsg implements msgp.Unmarshaler

type Method Uses

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

func MethodFromString Uses

func MethodFromString(input string) (Method, error)

func (Method) String Uses

func (i Method) String() string

type MetricData Uses

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 Uses

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

DecodeMsg implements msgp.Decodable

func (*MetricData) EncodeMsg Uses

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

EncodeMsg implements msgp.Encodable

func (*MetricData) MarshalMsg Uses

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

MarshalMsg implements msgp.Marshaler

func (*MetricData) Msgsize Uses

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 Uses

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

func (*MetricData) SetId Uses

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 Uses

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

UnmarshalMsg implements msgp.Unmarshaler

func (*MetricData) Validate Uses

func (m *MetricData) Validate() error

type MetricDataArray Uses

type MetricDataArray []*MetricData

can be used by some encoders, such as msgp

func (*MetricDataArray) DecodeMsg Uses

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

DecodeMsg implements msgp.Decodable

func (MetricDataArray) EncodeMsg Uses

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

EncodeMsg implements msgp.Encodable

func (MetricDataArray) MarshalMsg Uses

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

MarshalMsg implements msgp.Marshaler

func (MetricDataArray) Msgsize Uses

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 Uses

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

UnmarshalMsg implements msgp.Unmarshaler

type MetricDefinition Uses

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 Uses

func MetricDefinitionFromMetricData(d *MetricData) *MetricDefinition

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

func (*MetricDefinition) Clone Uses

func (m *MetricDefinition) Clone() MetricDefinition

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

func (*MetricDefinition) DecodeMsg Uses

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

DecodeMsg implements msgp.Decodable

func (*MetricDefinition) EncodeMsg Uses

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

EncodeMsg implements msgp.Encodable

func (*MetricDefinition) MarshalMsg Uses

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

MarshalMsg implements msgp.Marshaler

func (*MetricDefinition) Msgsize Uses

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 Uses

func (m *MetricDefinition) NameSanitizedAsTagValue() string

func (*MetricDefinition) NameWithTags Uses

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 Uses

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

func (*MetricDefinition) SetId Uses

func (m *MetricDefinition) SetId()

func (*MetricDefinition) UnmarshalMsg Uses

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

UnmarshalMsg implements msgp.Unmarshaler

func (*MetricDefinition) Validate Uses

func (m *MetricDefinition) Validate() error

type MetricPoint Uses

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 Uses

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

Marshal marshals the MetricPoint

func (*MetricPoint) Marshal32 Uses

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 Uses

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

MarshalWithoutOrg marshals in a non-multi-tenancy aware way

func (*MetricPoint) MarshalWithoutOrg28 Uses

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 Uses

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

Unmarshal unmarshals the MetricPoint

func (*MetricPoint) UnmarshalWithoutOrg Uses

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

UnmarshalWithoutOrg unmarshals in a non-multi-tenancy aware way

func (*MetricPoint) Valid Uses

func (m *MetricPoint) Valid() bool

type PartitionByMethod Uses

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 Uses

func PartitonMethodFromString(input string) (PartitionByMethod, error)

type PartitionedMetric Uses

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 Uses

type Point struct {
    Val float64
    Ts  uint32
}

go:generate msgp

func (*Point) DecodeMsg Uses

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

DecodeMsg implements msgp.Decodable

func (Point) EncodeMsg Uses

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

EncodeMsg implements msgp.Encodable

func (Point) MarshalMsg Uses

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

MarshalMsg implements msgp.Marshaler

func (Point) Msgsize Uses

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 Uses

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

UnmarshalMsg implements msgp.Unmarshaler

Directories

PathSynopsis
msg

Package schema imports 18 packages (graph) and is imported by 97 packages. Updated 2020-06-03. Refresh now. Tools for package owners.