From 1d299be3ea537c1597ef8f6df5557f5588d67a8d Mon Sep 17 00:00:00 2001 From: Holger Obermaier <40787752+ho-ob@users.noreply.github.com> Date: Wed, 9 Feb 2022 11:08:50 +0100 Subject: [PATCH] Add comments --- sinks/influxAsyncSink.go | 19 +++++++++++++------ sinks/influxSink.go | 17 +++++++++-------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/sinks/influxAsyncSink.go b/sinks/influxAsyncSink.go index 3315456..ba60799 100644 --- a/sinks/influxAsyncSink.go +++ b/sinks/influxAsyncSink.go @@ -1,8 +1,6 @@ package sinks import ( - // "context" - "crypto/tls" "encoding/json" "errors" @@ -54,10 +52,14 @@ func (s *InfluxAsyncSink) connect() error { if batch == 0 { batch = 100 } - s.client = influxdb2.NewClientWithOptions(uri, auth, - influxdb2.DefaultOptions().SetBatchSize(batch).SetTLSConfig(&tls.Config{ + clientOptions := influxdb2.DefaultOptions() + clientOptions.SetBatchSize(batch) + clientOptions.SetTLSConfig( + &tls.Config{ InsecureSkipVerify: true, - })) + }, + ) + s.client = influxdb2.NewClientWithOptions(uri, auth, clientOptions) s.writeApi = s.client.WriteAPI(s.config.Organization, s.config.Database) return nil } @@ -78,7 +80,11 @@ func (s *InfluxAsyncSink) Init(config json.RawMessage) error { len(s.config.Password) == 0 { return errors.New("not all configuration variables set required by InfluxAsyncSink") } + + // Connect to InfluxDB server err := s.connect() + + // Start background: Read from error channel s.errors = s.writeApi.Errors() go func() { for err := range s.errors { @@ -90,7 +96,8 @@ func (s *InfluxAsyncSink) Init(config json.RawMessage) error { func (s *InfluxAsyncSink) Write(m lp.CCMetric) error { s.writeApi.WritePoint( - m.ToPoint(s.config.MetaAsTags)) + m.ToPoint(s.config.MetaAsTags), + ) return nil } diff --git a/sinks/influxSink.go b/sinks/influxSink.go index 156f6eb..99304c0 100644 --- a/sinks/influxSink.go +++ b/sinks/influxSink.go @@ -46,14 +46,13 @@ func (s *InfluxSink) connect() error { auth = fmt.Sprintf("%s:%s", s.config.User, s.config.Password) } cclog.ComponentDebug(s.name, "Using URI", uri, "Org", s.config.Organization, "Bucket", s.config.Database) - s.client = - influxdb2.NewClientWithOptions( - uri, - auth, - influxdb2.DefaultOptions().SetTLSConfig( - &tls.Config{InsecureSkipVerify: true}, - ), - ) + clientOptions := influxdb2.DefaultOptions() + clientOptions.SetTLSConfig( + &tls.Config{ + InsecureSkipVerify: true, + }, + ) + s.client = influxdb2.NewClientWithOptions(uri, auth, clientOptions) s.writeApi = s.client.WriteAPIBlocking(s.config.Organization, s.config.Database) return nil } @@ -73,6 +72,8 @@ func (s *InfluxSink) Init(config json.RawMessage) error { len(s.config.Password) == 0 { return errors.New("not all configuration variables set required by InfluxSink") } + + // Connect to InfluxDB server return s.connect() }