diff --git a/sinks/httpSink.go b/sinks/httpSink.go index c2dd2ea..398eaf3 100644 --- a/sinks/httpSink.go +++ b/sinks/httpSink.go @@ -53,7 +53,7 @@ func (s *HttpSink) Write(m lp.CCMetric) error { }) } - p := m.ToPoint(s.config.MetaAsTags) + p := m.ToPoint(s.meta_as_tags) s.lock.Lock() _, err := s.encoder.Encode(p) @@ -159,6 +159,11 @@ func NewHttpSink(name string, config json.RawMessage) (Sink, error) { s.flushDelay = t } } + // Create lookup map to use meta infos as tags in the output metric + s.meta_as_tags = make(map[string]bool) + for _, k := range s.config.MetaAsTags { + s.meta_as_tags[k] = true + } tr := &http.Transport{ MaxIdleConns: s.maxIdleConns, IdleConnTimeout: s.idleConnTimeout, diff --git a/sinks/influxAsyncSink.go b/sinks/influxAsyncSink.go index 7b38873..88f516a 100644 --- a/sinks/influxAsyncSink.go +++ b/sinks/influxAsyncSink.go @@ -77,7 +77,7 @@ func (s *InfluxAsyncSink) connect() error { func (s *InfluxAsyncSink) Write(m lp.CCMetric) error { s.writeApi.WritePoint( - m.ToPoint(s.config.MetaAsTags), + m.ToPoint(s.meta_as_tags), ) return nil } @@ -113,6 +113,11 @@ func NewInfluxAsyncSink(name string, config json.RawMessage) (Sink, error) { len(s.config.Password) == 0 { return nil, errors.New("not all configuration variables set required by InfluxAsyncSink") } + // Create lookup map to use meta infos as tags in the output metric + s.meta_as_tags = make(map[string]bool) + for _, k := range s.config.MetaAsTags { + s.meta_as_tags[k] = true + } // Connect to InfluxDB server if err := s.connect(); err != nil { diff --git a/sinks/influxSink.go b/sinks/influxSink.go index 11859b2..c8f07fb 100644 --- a/sinks/influxSink.go +++ b/sinks/influxSink.go @@ -68,7 +68,7 @@ func (s *InfluxSink) Write(m lp.CCMetric) error { err := s.writeApi.WritePoint( context.Background(), - m.ToPoint(s.config.MetaAsTags), + m.ToPoint(s.meta_as_tags), ) return err } @@ -98,6 +98,11 @@ func NewInfluxSink(name string, config json.RawMessage) (Sink, error) { len(s.config.Password) == 0 { return nil, errors.New("not all configuration variables set required by InfluxSink") } + // Create lookup map to use meta infos as tags in the output metric + s.meta_as_tags = make(map[string]bool) + for _, k := range s.config.MetaAsTags { + s.meta_as_tags[k] = true + } // Connect to InfluxDB server if err := s.connect(); err != nil { diff --git a/sinks/metricSink.go b/sinks/metricSink.go index d5356d0..c6c6860 100644 --- a/sinks/metricSink.go +++ b/sinks/metricSink.go @@ -5,13 +5,13 @@ import ( ) type defaultSinkConfig struct { - MetaAsTags bool `json:"meta_as_tags,omitempty"` - Type string `json:"type"` + MetaAsTags []string `json:"meta_as_tags,omitempty"` + Type string `json:"type"` } type sink struct { - meta_as_tags bool // Use meta data tags as tags - name string // Name of the sink + meta_as_tags map[string]bool // Use meta data tags as tags + name string // Name of the sink } type Sink interface { diff --git a/sinks/natsSink.go b/sinks/natsSink.go index 0d7987e..0597e9b 100644 --- a/sinks/natsSink.go +++ b/sinks/natsSink.go @@ -55,7 +55,7 @@ func (s *NatsSink) connect() error { func (s *NatsSink) Write(m lp.CCMetric) error { if s.client != nil { - _, err := s.encoder.Encode(m.ToPoint(s.config.MetaAsTags)) + _, err := s.encoder.Encode(m.ToPoint(s.meta_as_tags)) if err != nil { cclog.ComponentError(s.name, "Write:", err.Error()) return err @@ -97,6 +97,11 @@ func NewNatsSink(name string, config json.RawMessage) (Sink, error) { len(s.config.Database) == 0 { return nil, errors.New("not all configuration variables set required by NatsSink") } + // Create lookup map to use meta infos as tags in the output metric + s.meta_as_tags = make(map[string]bool) + for _, k := range s.config.MetaAsTags { + s.meta_as_tags[k] = true + } // Setup Influx line protocol s.buffer = &bytes.Buffer{} s.buffer.Grow(1025) @@ -105,7 +110,7 @@ func NewNatsSink(name string, config json.RawMessage) (Sink, error) { s.encoder.SetMaxLineBytes(1024) // Setup infos for connection if err := s.connect(); err != nil { - return nil, fmt.Errorf("Unable to connect: %v", err) + return nil, fmt.Errorf("unable to connect: %v", err) } return s, nil } diff --git a/sinks/stdoutSink.go b/sinks/stdoutSink.go index acf2621..e091af3 100644 --- a/sinks/stdoutSink.go +++ b/sinks/stdoutSink.go @@ -63,7 +63,11 @@ func NewStdoutSink(name string, config json.RawMessage) (Sink, error) { s.output = f } } - s.meta_as_tags = s.config.MetaAsTags + // Create lookup map to use meta infos as tags in the output metric + s.meta_as_tags = make(map[string]bool) + for _, k := range s.config.MetaAsTags { + s.meta_as_tags[k] = true + } return s, nil }