From dce6bf851ffcb61c12322d0a1f3b5e02f7541b99 Mon Sep 17 00:00:00 2001 From: Thomas Roehl Date: Fri, 11 Mar 2022 13:55:04 +0100 Subject: [PATCH] Add meta as tag logic to sampleSink --- sinks/sampleSink.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/sinks/sampleSink.go b/sinks/sampleSink.go index 3913a29..2a823e6 100644 --- a/sinks/sampleSink.go +++ b/sinks/sampleSink.go @@ -10,14 +10,14 @@ import ( ) type SampleSinkConfig struct { - // defines JSON tags for 'type' and 'meta_as_tags' + // defines JSON tags for 'type' and 'meta_as_tags' (string list) // See: metricSink.go defaultSinkConfig // Additional config options, for SampleSink } type SampleSink struct { - // declares elements 'name' and 'meta_as_tags' + // declares elements 'name' and 'meta_as_tags' (string to bool map!) sink config SampleSinkConfig // entry point to the SampleSinkConfig } @@ -28,6 +28,7 @@ type SampleSink struct { // Code to submit a single CCMetric to the sink func (s *SampleSink) Write(point lp.CCMetric) error { + // based on s.meta_as_tags use meta infos as tags log.Print(point) return nil } @@ -62,6 +63,12 @@ func NewSampleSink(name string, config json.RawMessage) (Sink, error) { } } + // 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 + } + // Check if all required fields in the config are set // E.g. use 'len(s.config.Option) > 0' for string settings