Documentation ¶
Overview ¶
Package point implements datakits basic data structure.
Index ¶
- Constants
- Variables
- func GetCfg(opts ...Option) *cfg
- func NewRander(opts ...RandOption) *ptRander
- func PB2LP(pb []byte) (lp []byte, err error)
- func PutCfg(c *cfg)
- func PutDecoder(d *Decoder)
- func PutEncoder(e *Encoder)
- type AnyDemo
- type Callback
- type Category
- type Debug
- type DecodeFn
- type Decoder
- type DecoderOption
- type EncodeFn
- type Encoder
- type EncoderOption
- type Encoding
- type Field
- func (*Field) Descriptor() ([]byte, []int)deprecated
- func (x *Field) GetA() *anypb.Any
- func (x *Field) GetB() bool
- func (x *Field) GetD() []byte
- func (x *Field) GetF() float64
- func (x *Field) GetI() int64
- func (x *Field) GetIsTag() bool
- func (x *Field) GetKey() []byte
- func (x *Field) GetType() MetricType
- func (x *Field) GetU() uint64
- func (x *Field) GetUnit() string
- func (m *Field) GetVal() isField_Val
- func (*Field) ProtoMessage()
- func (x *Field) ProtoReflect() protoreflect.Message
- func (x *Field) Reset()
- func (x *Field) String() string
- type Field_A
- type Field_B
- type Field_D
- type Field_F
- type Field_I
- type Field_U
- type JSONPoint
- type KVOption
- type KVs
- func (x KVs) Add(k []byte, v any, isTag, force bool) KVs
- func (x KVs) AddKV(kv *Field, force bool) KVs
- func (x KVs) AddTag(k, v []byte) KVs
- func (x KVs) Del(k []byte) KVs
- func (x KVs) FieldCount() (i int)
- func (x KVs) Fields() (arr KVs)
- func (x KVs) Get(k []byte) *Field
- func (x KVs) GetTag(k []byte) []byte
- func (x KVs) Has(k []byte) bool
- func (x KVs) InfluxFields() map[string]any
- func (x KVs) InfluxTags() (res map[string]string)
- func (x KVs) Keys() *Keys
- func (x KVs) Len() int
- func (x KVs) Less(i, j int) bool
- func (x KVs) MustAddKV(kv *Field) KVs
- func (x KVs) MustAddTag(k, v []byte) KVs
- func (x KVs) Pretty() string
- func (x KVs) Swap(i, j int)
- func (x KVs) TagCount() (i int)
- func (x KVs) Tags() (arr KVs)
- func (x KVs) TrimFields(n int) (arr KVs)
- func (x KVs) TrimTags(n int) (arr KVs)
- type Key
- type KeyType
- type Keys
- type MetricType
- type Option
- func CommonLoggingOptions() []Option
- func DefaultLoggingOptions() []Option
- func DefaultMetricOptions() []Option
- func DefaultMetricOptionsForInflux1X() []Option
- func DefaultObjectOptions() []Option
- func WithCallback(fn Callback) Option
- func WithDisabledKeys(keys ...*Key) Option
- func WithDotInKey(on bool) Option
- func WithEncoding(enc Encoding) Option
- func WithExtraTags(tags map[string]string) Option
- func WithMaxFieldKeyLen(n int) Option
- func WithMaxFieldValLen(n int) Option
- func WithMaxFields(n int) Option
- func WithMaxKVComposeLen(n int) Option
- func WithMaxMeasurementLen(n int) Option
- func WithMaxTagKeyLen(n int) Option
- func WithMaxTagValLen(n int) Option
- func WithMaxTags(n int) Option
- func WithPrecheck(on bool) Option
- func WithPrecision(p Precision) Option
- func WithRequiredKeys(keys ...*Key) Option
- func WithStrField(on bool) Option
- func WithTime(t time.Time) Option
- func WithU64Field(on bool) Option
- type PBPoint
- func (*PBPoint) Descriptor() ([]byte, []int)deprecated
- func (x *PBPoint) GetDebugs() []*Debug
- func (x *PBPoint) GetFields() []*Field
- func (x *PBPoint) GetName() []byte
- func (x *PBPoint) GetTime() int64
- func (x *PBPoint) GetWarns() []*Warn
- func (*PBPoint) ProtoMessage()
- func (x *PBPoint) ProtoReflect() protoreflect.Message
- func (x *PBPoint) Reset()
- func (x *PBPoint) String() string
- type PBPoints
- type Point
- func FromJSONPoint(j *JSONPoint) *Point
- func FromLP(lp *influxdb.Point) *Point
- func FromModelsLP(lp models.Point) *Point
- func FromPB(pb *PBPoint) *Point
- func FromPBJson(j []byte) (*Point, error)
- func MustFromPBJson(j []byte) *Point
- func NewLPPoint(lp *influxdb.Point) *Point
- func NewPoint(name string, tags map[string]string, fields map[string]any, opts ...Option) (*Point, error)deprecated
- func NewPointV2(name []byte, kvs KVs, opts ...Option) *Point
- func RandPoints(count int) []*Point
- func WrapPoint(pts []*influxdb.Point) (arr []*Point)
- func (p *Point) Add(k []byte, v any)
- func (p *Point) AddDebug(d *Debug)
- func (p *Point) AddKV(kv *Field)
- func (p *Point) AddTag(k, v []byte)
- func (p *Point) ClearFlag(f uint64)
- func (p *Point) Del(k []byte)
- func (p *Point) Equal(x *Point) bool
- func (p *Point) EqualWithReason(x *Point) (bool, string)
- func (p *Point) Fields() (arr KVs)
- func (p *Point) Get(k []byte) any
- func (p *Point) GetTag(k []byte) []byte
- func (p *Point) HasFlag(f uint) bool
- func (p *Point) InfluxFields() map[string]any
- func (p *Point) InfluxTags() map[string]string
- func (p *Point) KVs() (arr KVs)
- func (p *Point) Keys() *Keys
- func (p *Point) LPPoint() *influxdb.Point
- func (p *Point) LPSize() int
- func (p *Point) LineProto(prec ...Precision) string
- func (p *Point) MD5() string
- func (p *Point) MarshalJSON() ([]byte, error)
- func (p *Point) MustAdd(k []byte, v any)
- func (p *Point) MustAddKV(kv *Field)
- func (p *Point) MustAddTag(k, v []byte)
- func (p *Point) Name() []byte
- func (p *Point) PBJson() ([]byte, error)
- func (p *Point) PBJsonPretty() ([]byte, error)
- func (p *Point) PBPoint() *PBPoint
- func (p *Point) PBSize() int
- func (p *Point) Pretty() string
- func (p *Point) SetFlag(f uint)
- func (p *Point) SetName(name string)
- func (p *Point) SetTime(t time.Time)
- func (p *Point) Sha256() string
- func (p *Point) Size() int
- func (p *Point) Tags() (arr KVs)
- func (p *Point) Time() time.Time
- func (p *Point) UnmarshalJSON(j []byte) error
- func (p *Point) Warns() []*Warn
- type Precision
- type RandOption
- func WithCategory(c Category) RandOption
- func WithFixedKeys(on bool) RandOption
- func WithFixedTags(on bool) RandOption
- func WithRandFields(n int) RandOption
- func WithRandKeyLen(n int) RandOption
- func WithRandMeasurementPrefix(s string) RandOption
- func WithRandPB(on bool) RandOption
- func WithRandTags(n int) RandOption
- func WithRandText(n int) RandOption
- func WithRandTime(t time.Time) RandOption
- func WithRandValLen(n int) RandOption
- type Warn
Constants ¶
const ( UnknownCategory Category = iota DynamicDWCategory MetricDeprecated Metric Network KeyEvent Object CustomObject Logging Tracing RUM Security Profiling SUnknownCategory = "unknown" SDynamicDWCategory = "dynamic_dw" // NOTE: not used SMetric = "metric" SMetricDeprecated = "metrics" SNetwork = "network" SKeyEvent = "keyevent" SObject = "object" SCustomObject = "custom_object" SLogging = "logging" STracing = "tracing" SRUM = "rum" SSecurity = "security" SProfiling = "profiling" URLUnknownCategory = "/v1/write/unknown" URLDynamicDWCategory = "/v1/write/dynamic_dw" // NOTE: not used URLMetric = "/v1/write/metric" URLMetricDeprecated = "/v1/write/metrics" URLNetwork = "/v1/write/network" URLKeyEvent = "/v1/write/keyevent" URLObject = "/v1/write/object" URLCustomObject = "/v1/write/custom_object" URLLogging = "/v1/write/logging" URLTracing = "/v1/write/tracing" URLRUM = "/v1/write/rum" URLSecurity = "/v1/write/security" URLProfiling = "/v1/write/profiling" CUnknown = "UNKNOWN" CDynamicDW = "DYNAMIC_DW" CM = "M" CN = "N" CE = "E" CO = "O" CCO = "CO" CL = "L" CT = "T" CR = "R" CS = "S" CP = "P" )
const ( WarnMaxTags = "exceed_max_tags" WarnMaxFields = "exceed_max_fields" WarnNoField = "no_field" WarnMaxTagKeyLen = "exceed_max_tag_key_len" WarnMaxTagValueLen = "exceed_max_tag_value_len" WarnMaxFieldKeyLen = "exceed_max_field_key_len" WarnMaxFieldValueLen = "exceed_max_field_value_len" WarnMaxFieldValueInt = "exceed_max_field_value_int" WarnMaxTagKeyValueCompose = "exceed_max_tag_key_value_compose" WarnInvalidTagKey = "invalid_tag_key" WarnInvalidTagValue = "invalid_tag_value" WarnInvalidMeasurement = "invalid_measurement" WarnInvalidFieldValueType = "invalid_field_value_type" WarnAddRequiredKV = "add_required_kv" WarnFieldDisabled = "field_disabled" WarnTagDisabled = "tag_disabled" WarnSameTagFieldKey = "same_tag_field_key" WarnDotInkey = "dot_in_key" WarnFieldB64Encoded = "field_base64_encoded" WarnNilField = "nil_field" )
Point warnnings.
const ( Psent = 1 << iota // The Point has been sent Ppb // the point is Protobuf point Pcheck // checked )
const (
EnvDefaultEncoding = "ENV_DEFAULT_ENCODING"
)
const (
PBContentType = "application/protobuf; proto=com.guance.Point"
)
Variables ¶
var ( ErrNoFields = errors.New("no fields") ErrInvalidLineProtocol = errors.New("invalid lineprotocol") )
var ( KeyType_name = map[int32]string{ 0: "X", 1: "I", 2: "U", 3: "F", 4: "B", 5: "D", 6: "NIL", } KeyType_value = map[string]int32{ "X": 0, "I": 1, "U": 2, "F": 3, "B": 4, "D": 5, "NIL": 6, } )
Enum value maps for KeyType.
var ( MetricType_name = map[int32]string{ 0: "UNSPECIFIED", 1: "COUNT", 2: "RATE", 3: "GAUGE", } MetricType_value = map[string]int32{ "UNSPECIFIED": 0, "COUNT": 1, "RATE": 2, "GAUGE": 3, } )
Enum value maps for MetricType.
var ( DefaultMeasurementName = []byte("__default") KeyTime = NewKey([]byte("time"), KeyType_I) KeyMeasurement = NewKey([]byte("measurement"), KeyType_D) KeySource = NewKey([]byte("source"), KeyType_D) KeyClass = NewKey([]byte("class"), KeyType_D) KeyDate = NewKey([]byte("date"), KeyType_I) KeyName = NewKey([]byte("name"), KeyType_D, []byte(defaultObjectName)) KeyStatus = NewKey([]byte("status"), KeyType_D, []byte(defaultLoggingStatus)) )
var (
DefaultEncoding = LineProtocol
)
var File_point_proto protoreflect.FileDescriptor
Functions ¶
func NewRander ¶
func NewRander(opts ...RandOption) *ptRander
func PutDecoder ¶
func PutDecoder(d *Decoder)
func PutEncoder ¶
func PutEncoder(e *Encoder)
Types ¶
type AnyDemo ¶
type AnyDemo struct { Demo string `protobuf:"bytes,1,opt,name=demo,proto3" json:"demo,omitempty"` // contains filtered or unexported fields }
example of pb.Any
func (*AnyDemo) Descriptor
deprecated
func (*AnyDemo) ProtoMessage ¶
func (*AnyDemo) ProtoMessage()
func (*AnyDemo) ProtoReflect ¶
func (x *AnyDemo) ProtoReflect() protoreflect.Message
type Debug ¶
type Debug struct { Info string `protobuf:"bytes,1,opt,name=info,proto3" json:"info,omitempty"` // contains filtered or unexported fields }
Debug used to attached some debug info for the point, these debug info will encoded into payload, storage can take optional handle on these debug info.
func (*Debug) Descriptor
deprecated
func (*Debug) ProtoMessage ¶
func (*Debug) ProtoMessage()
func (*Debug) ProtoReflect ¶
func (x *Debug) ProtoReflect() protoreflect.Message
type DecodeFn ¶
DecodeFn used to iterate on []*Point payload, if error returned, the iterate terminated.
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
func GetDecoder ¶
func GetDecoder(opts ...DecoderOption) *Decoder
func (*Decoder) DetailedError ¶
type DecoderOption ¶
type DecoderOption func(e *Decoder)
func WithDecEncoding ¶
func WithDecEncoding(enc Encoding) DecoderOption
func WithDecFn ¶
func WithDecFn(fn DecodeFn) DecoderOption
type EncodeFn ¶
EncodeFn used to iterate on []*Point payload, if error returned, the iterate terminated.
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
func GetEncoder ¶
func GetEncoder(opts ...EncoderOption) *Encoder
type EncoderOption ¶
type EncoderOption func(e *Encoder)
func WithEncBatchSize ¶
func WithEncBatchSize(size int) EncoderOption
func WithEncEncoding ¶
func WithEncEncoding(enc Encoding) EncoderOption
func WithEncFn ¶
func WithEncFn(fn EncodeFn) EncoderOption
type Field ¶
type Field struct { Key []byte `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` // field name // See https://developers.google.com/protocol-buffers/docs/proto3#json // // Types that are assignable to Val: // *Field_I // *Field_U // *Field_F // *Field_B // *Field_D // *Field_A Val isField_Val `protobuf_oneof:"val"` IsTag bool `protobuf:"varint,8,opt,name=is_tag,proto3" json:"is_tag,omitempty"` // the field is a tag? Type MetricType `protobuf:"varint,9,opt,name=type,proto3,enum=point.MetricType" json:"type,omitempty"` // field unit name Unit string `protobuf:"bytes,10,opt,name=unit,proto3" json:"unit,omitempty"` // metric unit, such as bytes(B), duration(ms/us) and so on. // contains filtered or unexported fields }
func (*Field) Descriptor
deprecated
func (*Field) GetType ¶
func (x *Field) GetType() MetricType
func (*Field) ProtoMessage ¶
func (*Field) ProtoMessage()
func (*Field) ProtoReflect ¶
func (x *Field) ProtoReflect() protoreflect.Message
type Field_D ¶
type Field_D struct {
D []byte `protobuf:"bytes,6,opt,name=d,proto3,oneof"` // bytes, for string or binary data
}
type Field_F ¶
type Field_F struct {
F float64 `protobuf:"fixed64,4,opt,name=f,proto3,oneof"` // float64
}
type Field_I ¶
type Field_I struct {
I int64 `protobuf:"varint,2,opt,name=i,proto3,oneof"` // signed int
}
type Field_U ¶
type Field_U struct {
U uint64 `protobuf:"varint,3,opt,name=u,proto3,oneof"` // unsigned int
}
type JSONPoint ¶
type KVOption ¶
type KVOption func(kv *Field)
func WithKVTagSet ¶
func WithKVType ¶
func WithKVType(t MetricType) KVOption
func WithKVUnit ¶
type KVs ¶
type KVs []*Field
func (KVs) FieldCount ¶
func (KVs) InfluxFields ¶
InfluxFields convert KVs to map structure.
func (KVs) InfluxTags ¶
InfluxTags convert tag KVs to map structure.
func (KVs) MustAddTag ¶
type Key ¶
type Key struct {
// contains filtered or unexported fields
}
Key is the key-name and it's type composite.
type KeyType ¶
type KeyType int32
func (KeyType) Descriptor ¶
func (KeyType) Descriptor() protoreflect.EnumDescriptor
func (KeyType) EnumDescriptor
deprecated
func (KeyType) Number ¶
func (x KeyType) Number() protoreflect.EnumNumber
func (KeyType) Type ¶
func (KeyType) Type() protoreflect.EnumType
type MetricType ¶
type MetricType int32
const ( MetricType_UNSPECIFIED MetricType = 0 MetricType_COUNT MetricType = 1 MetricType_RATE MetricType = 2 MetricType_GAUGE MetricType = 3 )
func (MetricType) Descriptor ¶
func (MetricType) Descriptor() protoreflect.EnumDescriptor
func (MetricType) Enum ¶
func (x MetricType) Enum() *MetricType
func (MetricType) EnumDescriptor
deprecated
func (MetricType) EnumDescriptor() ([]byte, []int)
Deprecated: Use MetricType.Descriptor instead.
func (MetricType) Number ¶
func (x MetricType) Number() protoreflect.EnumNumber
func (MetricType) String ¶
func (x MetricType) String() string
func (MetricType) Type ¶
func (MetricType) Type() protoreflect.EnumType
type Option ¶
type Option func(*cfg)
func CommonLoggingOptions ¶ added in v0.1.1
func CommonLoggingOptions() []Option
CommonLoggingOptions defined options on RUM/Tracing/Security/Event/Profile/Network point.
func DefaultLoggingOptions ¶
func DefaultLoggingOptions() []Option
DefaultLoggingOptions defined options on Logging point.
func DefaultMetricOptions ¶
func DefaultMetricOptions() []Option
DefaultMetricOptions defined options on Metric point.
func DefaultMetricOptionsForInflux1X ¶
func DefaultMetricOptionsForInflux1X() []Option
DefaultMetricOptionsForInflux1X get influxdb 1.x options. For influxdb 1.x, uint64 not support.
func DefaultObjectOptions ¶
func DefaultObjectOptions() []Option
DefaultObjectOptions defined options on Object/CustomObject point.
func WithCallback ¶
func WithDisabledKeys ¶
func WithDotInKey ¶
func WithEncoding ¶
func WithExtraTags ¶
func WithMaxFieldKeyLen ¶
func WithMaxFieldValLen ¶
func WithMaxFields ¶
func WithMaxKVComposeLen ¶
func WithMaxMeasurementLen ¶
func WithMaxTagKeyLen ¶
func WithMaxTagValLen ¶
func WithMaxTags ¶
func WithPrecheck ¶
func WithPrecision ¶
func WithRequiredKeys ¶
func WithStrField ¶
func WithU64Field ¶
type PBPoint ¶
type PBPoint struct { Name []byte `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` Fields []*Field `protobuf:"bytes,2,rep,name=fields,proto3" json:"fields,omitempty"` Time int64 `protobuf:"varint,3,opt,name=time,proto3" json:"time,omitempty"` // Auxiliary fields for the point, they should not // write to the final storage on production. Warns []*Warn `protobuf:"bytes,4,rep,name=warns,proto3" json:"warns,omitempty"` Debugs []*Debug `protobuf:"bytes,5,rep,name=debugs,proto3" json:"debugs,omitempty"` // contains filtered or unexported fields }
func (*PBPoint) Descriptor
deprecated
func (*PBPoint) ProtoMessage ¶
func (*PBPoint) ProtoMessage()
func (*PBPoint) ProtoReflect ¶
func (x *PBPoint) ProtoReflect() protoreflect.Message
type PBPoints ¶
type PBPoints struct { Arr []*PBPoint `protobuf:"bytes,1,rep,name=arr,proto3" json:"arr,omitempty"` // contains filtered or unexported fields }
Batch of PBPoint.
func (*PBPoints) Descriptor
deprecated
func (*PBPoints) ProtoMessage ¶
func (*PBPoints) ProtoMessage()
func (*PBPoints) ProtoReflect ¶
func (x *PBPoints) ProtoReflect() protoreflect.Message
type Point ¶
type Point struct {
// contains filtered or unexported fields
}
func FromJSONPoint ¶
func FromModelsLP ¶
func FromPBJson ¶
func MustFromPBJson ¶
func NewLPPoint ¶
NewLPPoint create Point based on a lineproto point.
func NewPoint
deprecated
func NewPoint(name string, tags map[string]string, fields map[string]any, opts ...Option) (*Point, error)
NewPoint returns a new Point given name(measurement), tags, fields and optional options.
If fields empty(or nil), error ErrNoField will returned.
Values in fields only allowed for int/uint(8-bit/16-bit/32-bit/64-bit), string, bool, float(32-bit/64-bit) and []byte, other types are ignored.
Deprecated: use NewPointV2.
func (*Point) Equal ¶
Equal test if two point are the same. Equality test not check on warns and debugs. If two points equal, they have the same ID(MD5/Sha256), but same ID do not means they are equal.
func (*Point) InfluxFields ¶
InfluxFields convert fields to map structure.
func (*Point) InfluxTags ¶
InfluxTags convert tags to map structure.
func (*Point) LineProto ¶
LineProto convert point to text lineprotocol(both for lineproto point and protobuf point).
func (*Point) MarshalJSON ¶
MarshalJSON to protobuf json.
func (*Point) MustAddTag ¶
MustAddTag add specific key value to fields, if k exist, override it.
func (*Point) PBJsonPretty ¶
func (*Point) Pretty ¶
Pretty get string representation of point, suffixed with all warning(if any) during build the point.
func (*Point) UnmarshalJSON ¶
UnmarshalJSON unmarshal protobuf json.
type RandOption ¶
type RandOption func(*ptRander)
func WithCategory ¶
func WithCategory(c Category) RandOption
func WithFixedKeys ¶
func WithFixedKeys(on bool) RandOption
func WithFixedTags ¶
func WithFixedTags(on bool) RandOption
func WithRandFields ¶
func WithRandFields(n int) RandOption
func WithRandKeyLen ¶
func WithRandKeyLen(n int) RandOption
func WithRandMeasurementPrefix ¶
func WithRandMeasurementPrefix(s string) RandOption
func WithRandPB ¶
func WithRandPB(on bool) RandOption
func WithRandTags ¶
func WithRandTags(n int) RandOption
func WithRandText ¶
func WithRandText(n int) RandOption
func WithRandTime ¶
func WithRandTime(t time.Time) RandOption
func WithRandValLen ¶
func WithRandValLen(n int) RandOption
type Warn ¶
type Warn struct { Type string `protobuf:"bytes,1,opt,name=type,proto3" json:"type,omitempty"` Msg string `protobuf:"bytes,2,opt,name=msg,json=message,proto3" json:"msg,omitempty"` // contains filtered or unexported fields }
Warn used to attach some warning message during building the point.
func (*Warn) Descriptor
deprecated
func (*Warn) ProtoMessage ¶
func (*Warn) ProtoMessage()
func (*Warn) ProtoReflect ¶
func (x *Warn) ProtoReflect() protoreflect.Message