mirror of
https://github.com/mainflux/mainflux.git
synced 2025-05-02 22:17:10 +08:00

* Upgrade InfluxDB from 1.x to 2.x Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Influx DB configuration updated Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Connection to InfluxDBv2 Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Token cannot be created Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Connected to InfluxDB2 Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Connected to InfluxDB2 Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * InfluxDB v2 Consumer Implementation Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * quickfix Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Influxdb-Writer Unit Tests Update Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Consumer Update Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * InfluxDB Writer Tests Implemented Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * fix Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * InfluxDB Connection Check Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Resolving Remarks Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Resolved consumer-test remark Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * consumer-test slow working version Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * reader changes Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Consumer tests time issue fixed Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Eof warning fixed Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Resolved Reviews Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Makefile Fixed Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Resolved Reviews Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Resolved Reviews Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Resolved Reviews Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Resolved Reviews Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Resolved Reviews Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Readers Initial Setup Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * consumer json fix Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * readers simple version Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * readers simple version fix Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * readers simple version fix Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * readers simple version fix Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * readers simple version fix Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * readers simple version fix Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * readers simple version fix Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Influxdb Reader Parsers Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Influxdb Reader Parsers Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Influxdb Reader Parsers Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Bugfix and resolves comments. Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * one test fails Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * solved last page read Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * writers future time problem fixed Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * weird Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * weird Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Tests Passes Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Resolve Semaphore Issues Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * UUID comment on consumer tests resolved Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Inclusive from and Exclusive to Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Inclusive from and Exclusive to Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * 1 second limits Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * 1 second limits Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * resolved review Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * resolved review Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * resolved review Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * resolved review Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * fixed json time Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * fixed CI error Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * resolved request Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * resolved request Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * resolved requests Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * removed blank line Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * resolved comment Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * deleted unnecessary string builder Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * initial commit Signed-off-by: aryan <aryangodara03@gmail.com> * change influxdb docker image version. Signed-off-by: aryan <aryangodara03@gmail.com> * go mod and vendor fixing Signed-off-by: aryan <aryangodara03@gmail.com> * Upgrade InfluxDB from 1.x to 2.x Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Influx DB configuration updated Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Connection to InfluxDBv2 Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Token cannot be created Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Connected to InfluxDB2 Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Connected to InfluxDB2 Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * InfluxDB v2 Consumer Implementation Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * quickfix Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Influxdb-Writer Unit Tests Update Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Consumer Update Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * InfluxDB Writer Tests Implemented Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * fix Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * InfluxDB Connection Check Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Resolving Remarks Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Resolved consumer-test remark Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * consumer-test slow working version Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * reader changes Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Consumer tests time issue fixed Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Resolved Reviews Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Resolved Reviews Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Resolved Reviews Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Resolved Reviews Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Resolved Reviews Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Resolved Reviews Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Readers Initial Setup Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * consumer json fix Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * readers simple version Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * readers simple version fix Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * readers simple version fix Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * readers simple version fix Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * readers simple version fix Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * readers simple version fix Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * readers simple version fix Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Influxdb Reader Parsers Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Influxdb Reader Parsers Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Influxdb Reader Parsers Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Bugfix and resolves comments. Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * one test fails Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * solved last page read Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * writers future time problem fixed Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * weird Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * weird Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Tests Passes Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Resolve Semaphore Issues Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * UUID comment on consumer tests resolved Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Inclusive from and Exclusive to Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Inclusive from and Exclusive to Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * 1 second limits Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * 1 second limits Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * resolved review Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * resolved review Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * resolved review Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * resolved review Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * fixed json time Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * fixed CI error Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * resolved request Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * resolved request Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * resolved requests Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * removed blank line Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * resolved comment Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * deleted unnecessary string builder Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * initial commit Signed-off-by: aryan <aryangodara03@gmail.com> * change influxdb docker image version. Signed-off-by: aryan <aryangodara03@gmail.com> * go mod and vendor fixing Signed-off-by: aryan <aryangodara03@gmail.com> * go mod fixing Signed-off-by: aryan <aryangodara03@gmail.com> * make tests pass locally, fix errors Signed-off-by: aryan <aryangodara03@gmail.com> * rem unsused variables/consts Signed-off-by: aryan <aryangodara03@gmail.com> * go mod tidy vendor Signed-off-by: aryan <aryangodara03@gmail.com> * add env var and data types Signed-off-by: aryan <aryangodara03@gmail.com> * update influxdb version to latest (2.3 to 2.12) Signed-off-by: aryan <aryangodara03@gmail.com> * change time precision for message tests Signed-off-by: aryan <aryangodara03@gmail.com> * renamed influxdb2 to influxdata Signed-off-by: aryan <aryangodara03@gmail.com> * address remarks on PR Signed-off-by: aryan <aryangodara03@gmail.com> * update influxbd according to latest mf commit Signed-off-by: aryan <aryangodara03@gmail.com> * temp commit, rem before pushing Signed-off-by: aryan <aryangodara03@gmail.com> * update main files and cassandra-reader messages_tests Signed-off-by: aryan <aryangodara03@gmail.com> * fix name of logger while importing Signed-off-by: aryan <aryangodara03@gmail.com> * remove unnecessary print lines Signed-off-by: aryan <aryangodara03@gmail.com> * correct env var name Signed-off-by: aryan <aryangodara03@gmail.com> * change to async consume Signed-off-by: aryan <aryangodara03@gmail.com> * add option to switch bw sync and async Signed-off-by: aryan <aryangodara03@gmail.com> * test for both async and sync Signed-off-by: aryan <aryangodara03@gmail.com> * update consumer and add writeAPIs to config Signed-off-by: aryan <aryangodara03@gmail.com> * revert back to sync consuming Signed-off-by: aryan <aryangodara03@gmail.com> * temp fix for default timeout value Signed-off-by: aryan <aryangodara03@gmail.com> * set default timeout in config. Signed-off-by: aryan <aryangodara03@gmail.com> * remove unwanted env vars, add required ones. Signed-off-by: aryan <aryangodara03@gmail.com> * rem unused username password from config Signed-off-by: aryan <aryangodara03@gmail.com> * update readme, env vars, and remove grafana Signed-off-by: aryan <aryangodara03@gmail.com> * update readme Signed-off-by: aryan <aryangodara03@gmail.com> * fix typo Signed-off-by: aryan <aryangodara03@gmail.com> * update readme description. Signed-off-by: aryan <aryangodara03@gmail.com> * fix more typos. Signed-off-by: aryan <aryangodara03@gmail.com> * add link to official docs to readme. Signed-off-by: aryan <aryangodara03@gmail.com> --------- Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> Signed-off-by: aryan <aryangodara03@gmail.com> Co-authored-by: fatih <fatihdurmaz@sabanciuniv.edu> Co-authored-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com>
429 lines
7.9 KiB
Go
429 lines
7.9 KiB
Go
package protocol
|
|
|
|
import (
|
|
"fmt"
|
|
"hash/fnv"
|
|
"sort"
|
|
"time"
|
|
)
|
|
|
|
// Tag holds the keys and values for a bunch of Tag k/v pairs.
|
|
type Tag struct {
|
|
Key string
|
|
Value string
|
|
}
|
|
|
|
// Field holds the keys and values for a bunch of Metric Field k/v pairs where Value can be a uint64, int64, int, float32, float64, string, or bool.
|
|
type Field struct {
|
|
Key string
|
|
Value interface{}
|
|
}
|
|
|
|
// Metric is the interface for marshaling, if you implement this interface you can be marshalled into the line protocol. Woot!
|
|
type Metric interface {
|
|
Time() time.Time
|
|
Name() string
|
|
TagList() []*Tag
|
|
FieldList() []*Field
|
|
}
|
|
|
|
// MutableMetric represents a metric that can be be modified.
|
|
type MutableMetric interface {
|
|
Metric
|
|
SetTime(time.Time)
|
|
AddTag(key, value string)
|
|
AddField(key string, value interface{})
|
|
}
|
|
|
|
// FieldSortOrder is a type for controlling if Fields are sorted
|
|
type FieldSortOrder int
|
|
|
|
const (
|
|
// NoSortFields tells the Decoder to not sort the fields.
|
|
NoSortFields FieldSortOrder = iota
|
|
|
|
// SortFields tells the Decoder to sort the fields.
|
|
SortFields
|
|
)
|
|
|
|
// FieldTypeSupport is a type for the parser to understand its type support.
|
|
type FieldTypeSupport int
|
|
|
|
const (
|
|
// UintSupport means the parser understands uint64s and can store them without having to convert to int64.
|
|
UintSupport FieldTypeSupport = 1 << iota
|
|
)
|
|
|
|
// MetricError is an error causing a metric to be unserializable.
|
|
type MetricError struct {
|
|
s string
|
|
}
|
|
|
|
func (e MetricError) Error() string {
|
|
return e.s
|
|
}
|
|
|
|
// FieldError is an error causing a field to be unserializable.
|
|
type FieldError struct {
|
|
s string
|
|
}
|
|
|
|
func (e FieldError) Error() string {
|
|
return e.s
|
|
}
|
|
|
|
var (
|
|
// ErrNeedMoreSpace tells us that the Decoder's io.Reader is full.
|
|
ErrNeedMoreSpace = &MetricError{"need more space"}
|
|
|
|
// ErrInvalidName tells us that the chosen name is invalid.
|
|
ErrInvalidName = &MetricError{"invalid name"}
|
|
|
|
// ErrNoFields tells us that there were no serializable fields in the line/metric.
|
|
ErrNoFields = &MetricError{"no serializable fields"}
|
|
)
|
|
|
|
type metric struct {
|
|
name string
|
|
tags []*Tag
|
|
fields []*Field
|
|
tm time.Time
|
|
}
|
|
|
|
// New creates a new metric via maps.
|
|
func New(
|
|
name string,
|
|
tags map[string]string,
|
|
fields map[string]interface{},
|
|
tm time.Time,
|
|
) (MutableMetric, error) {
|
|
m := &metric{
|
|
name: name,
|
|
tags: nil,
|
|
fields: nil,
|
|
tm: tm,
|
|
}
|
|
|
|
if len(tags) > 0 {
|
|
m.tags = make([]*Tag, 0, len(tags))
|
|
for k, v := range tags {
|
|
m.tags = append(m.tags,
|
|
&Tag{Key: k, Value: v})
|
|
}
|
|
sort.Slice(m.tags, func(i, j int) bool { return m.tags[i].Key < m.tags[j].Key })
|
|
}
|
|
|
|
if len(fields) > 0 {
|
|
m.fields = make([]*Field, 0, len(fields))
|
|
for k, v := range fields {
|
|
v := convertField(v)
|
|
if v == nil {
|
|
continue
|
|
}
|
|
m.AddField(k, v)
|
|
}
|
|
}
|
|
|
|
return m, nil
|
|
}
|
|
|
|
// FromMetric returns a deep copy of the metric with any tracking information
|
|
// removed.
|
|
func FromMetric(other Metric) Metric {
|
|
m := &metric{
|
|
name: other.Name(),
|
|
tags: make([]*Tag, len(other.TagList())),
|
|
fields: make([]*Field, len(other.FieldList())),
|
|
tm: other.Time(),
|
|
}
|
|
|
|
for i, tag := range other.TagList() {
|
|
m.tags[i] = &Tag{Key: tag.Key, Value: tag.Value}
|
|
}
|
|
|
|
for i, field := range other.FieldList() {
|
|
m.fields[i] = &Field{Key: field.Key, Value: field.Value}
|
|
}
|
|
return m
|
|
}
|
|
|
|
func (m *metric) String() string {
|
|
return fmt.Sprintf("%s %v %v %d", m.name, m.Tags(), m.Fields(), m.tm.UnixNano())
|
|
}
|
|
|
|
func (m *metric) Name() string {
|
|
return m.name
|
|
}
|
|
|
|
func (m *metric) Tags() map[string]string {
|
|
tags := make(map[string]string, len(m.tags))
|
|
for _, tag := range m.tags {
|
|
tags[tag.Key] = tag.Value
|
|
}
|
|
return tags
|
|
}
|
|
|
|
func (m *metric) TagList() []*Tag {
|
|
return m.tags
|
|
}
|
|
|
|
func (m *metric) Fields() map[string]interface{} {
|
|
fields := make(map[string]interface{}, len(m.fields))
|
|
for _, field := range m.fields {
|
|
fields[field.Key] = field.Value
|
|
}
|
|
|
|
return fields
|
|
}
|
|
|
|
func (m *metric) FieldList() []*Field {
|
|
return m.fields
|
|
}
|
|
|
|
func (m *metric) Time() time.Time {
|
|
return m.tm
|
|
}
|
|
|
|
func (m *metric) SetName(name string) {
|
|
m.name = name
|
|
}
|
|
|
|
func (m *metric) AddPrefix(prefix string) {
|
|
m.name = prefix + m.name
|
|
}
|
|
|
|
func (m *metric) AddSuffix(suffix string) {
|
|
m.name = m.name + suffix
|
|
}
|
|
|
|
func (m *metric) AddTag(key, value string) {
|
|
for i, tag := range m.tags {
|
|
if key > tag.Key {
|
|
continue
|
|
}
|
|
|
|
if key == tag.Key {
|
|
tag.Value = value
|
|
return
|
|
}
|
|
|
|
m.tags = append(m.tags, nil)
|
|
copy(m.tags[i+1:], m.tags[i:])
|
|
m.tags[i] = &Tag{Key: key, Value: value}
|
|
return
|
|
}
|
|
|
|
m.tags = append(m.tags, &Tag{Key: key, Value: value})
|
|
}
|
|
|
|
func (m *metric) HasTag(key string) bool {
|
|
for _, tag := range m.tags {
|
|
if tag.Key == key {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func (m *metric) GetTag(key string) (string, bool) {
|
|
for _, tag := range m.tags {
|
|
if tag.Key == key {
|
|
return tag.Value, true
|
|
}
|
|
}
|
|
return "", false
|
|
}
|
|
|
|
func (m *metric) RemoveTag(key string) {
|
|
for i, tag := range m.tags {
|
|
if tag.Key == key {
|
|
copy(m.tags[i:], m.tags[i+1:])
|
|
m.tags[len(m.tags)-1] = nil
|
|
m.tags = m.tags[:len(m.tags)-1]
|
|
return
|
|
}
|
|
}
|
|
}
|
|
|
|
func (m *metric) AddField(key string, value interface{}) {
|
|
for i, field := range m.fields {
|
|
if key == field.Key {
|
|
m.fields[i] = &Field{Key: key, Value: convertField(value)}
|
|
return
|
|
}
|
|
}
|
|
m.fields = append(m.fields, &Field{Key: key, Value: convertField(value)})
|
|
}
|
|
|
|
func (m *metric) HasField(key string) bool {
|
|
for _, field := range m.fields {
|
|
if field.Key == key {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func (m *metric) GetField(key string) (interface{}, bool) {
|
|
for _, field := range m.fields {
|
|
if field.Key == key {
|
|
return field.Value, true
|
|
}
|
|
}
|
|
return nil, false
|
|
}
|
|
|
|
func (m *metric) RemoveField(key string) {
|
|
for i, field := range m.fields {
|
|
if field.Key == key {
|
|
copy(m.fields[i:], m.fields[i+1:])
|
|
m.fields[len(m.fields)-1] = nil
|
|
m.fields = m.fields[:len(m.fields)-1]
|
|
return
|
|
}
|
|
}
|
|
}
|
|
|
|
func (m *metric) SetTime(t time.Time) {
|
|
m.tm = t
|
|
}
|
|
|
|
func (m *metric) Copy() Metric {
|
|
m2 := &metric{
|
|
name: m.name,
|
|
tags: make([]*Tag, len(m.tags)),
|
|
fields: make([]*Field, len(m.fields)),
|
|
tm: m.tm,
|
|
}
|
|
|
|
for i, tag := range m.tags {
|
|
m2.tags[i] = &Tag{Key: tag.Key, Value: tag.Value}
|
|
}
|
|
|
|
for i, field := range m.fields {
|
|
m2.fields[i] = &Field{Key: field.Key, Value: field.Value}
|
|
}
|
|
return m2
|
|
}
|
|
|
|
func (m *metric) HashID() uint64 {
|
|
h := fnv.New64a()
|
|
h.Write([]byte(m.name))
|
|
h.Write([]byte("\n"))
|
|
for _, tag := range m.tags {
|
|
h.Write([]byte(tag.Key))
|
|
h.Write([]byte("\n"))
|
|
h.Write([]byte(tag.Value))
|
|
h.Write([]byte("\n"))
|
|
}
|
|
return h.Sum64()
|
|
}
|
|
|
|
func (m *metric) Accept() {
|
|
}
|
|
|
|
func (m *metric) Reject() {
|
|
}
|
|
|
|
func (m *metric) Drop() {
|
|
}
|
|
|
|
// Convert field to a supported type or nil if unconvertible
|
|
func convertField(v interface{}) interface{} {
|
|
switch v := v.(type) {
|
|
case float64:
|
|
return v
|
|
case int64:
|
|
return v
|
|
case string:
|
|
return v
|
|
case bool:
|
|
return v
|
|
case int:
|
|
return int64(v)
|
|
case uint:
|
|
return uint64(v)
|
|
case uint64:
|
|
return uint64(v)
|
|
case []byte:
|
|
return string(v)
|
|
case int32:
|
|
return int64(v)
|
|
case int16:
|
|
return int64(v)
|
|
case int8:
|
|
return int64(v)
|
|
case uint32:
|
|
return uint64(v)
|
|
case uint16:
|
|
return uint64(v)
|
|
case uint8:
|
|
return uint64(v)
|
|
case float32:
|
|
return float64(v)
|
|
case *float64:
|
|
if v != nil {
|
|
return *v
|
|
}
|
|
case *int64:
|
|
if v != nil {
|
|
return *v
|
|
}
|
|
case *string:
|
|
if v != nil {
|
|
return *v
|
|
}
|
|
case *bool:
|
|
if v != nil {
|
|
return *v
|
|
}
|
|
case *int:
|
|
if v != nil {
|
|
return int64(*v)
|
|
}
|
|
case *uint:
|
|
if v != nil {
|
|
return uint64(*v)
|
|
}
|
|
case *uint64:
|
|
if v != nil {
|
|
return uint64(*v)
|
|
}
|
|
case *[]byte:
|
|
if v != nil {
|
|
return string(*v)
|
|
}
|
|
case *int32:
|
|
if v != nil {
|
|
return int64(*v)
|
|
}
|
|
case *int16:
|
|
if v != nil {
|
|
return int64(*v)
|
|
}
|
|
case *int8:
|
|
if v != nil {
|
|
return int64(*v)
|
|
}
|
|
case *uint32:
|
|
if v != nil {
|
|
return uint64(*v)
|
|
}
|
|
case *uint16:
|
|
if v != nil {
|
|
return uint64(*v)
|
|
}
|
|
case *uint8:
|
|
if v != nil {
|
|
return uint64(*v)
|
|
}
|
|
case *float32:
|
|
if v != nil {
|
|
return float64(*v)
|
|
}
|
|
default:
|
|
return nil
|
|
}
|
|
return nil
|
|
}
|