summaryrefslogtreecommitdiffstats
path: root/src/go/collectors/go.d.plugin/modules/pika/init.go
blob: 8cb62aa520709e1983078d1bf3e2626d2aab631c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// SPDX-License-Identifier: GPL-3.0-or-later

package pika

import (
	"errors"

	"github.com/netdata/netdata/go/go.d.plugin/agent/module"
	"github.com/netdata/netdata/go/go.d.plugin/pkg/tlscfg"

	"github.com/go-redis/redis/v8"
)

func (p *Pika) validateConfig() error {
	if p.Address == "" {
		return errors.New("'address' not set")
	}
	return nil
}

func (p *Pika) initRedisClient() (*redis.Client, error) {
	opts, err := redis.ParseURL(p.Address)
	if err != nil {
		return nil, err
	}

	tlsConfig, err := tlscfg.NewTLSConfig(p.TLSConfig)
	if err != nil {
		return nil, err
	}

	if opts.TLSConfig != nil && tlsConfig != nil {
		tlsConfig.ServerName = opts.TLSConfig.ServerName
	}

	opts.PoolSize = 1
	opts.TLSConfig = tlsConfig
	opts.DialTimeout = p.Timeout.Duration()
	opts.ReadTimeout = p.Timeout.Duration()
	opts.WriteTimeout = p.Timeout.Duration()

	return redis.NewClient(opts), nil
}

func (p *Pika) initCharts() (*module.Charts, error) {
	return pikaCharts.Copy(), nil
}