Unit test couchbase input plugin
This commit is contained in:
parent
a48ab060a8
commit
056e52f539
|
@ -36,7 +36,7 @@ func (r *Couchbase) Description() string {
|
||||||
// Returns one of the errors encountered while gathering stats (if any).
|
// Returns one of the errors encountered while gathering stats (if any).
|
||||||
func (r *Couchbase) Gather(acc telegraf.Accumulator) error {
|
func (r *Couchbase) Gather(acc telegraf.Accumulator) error {
|
||||||
if len(r.Servers) == 0 {
|
if len(r.Servers) == 0 {
|
||||||
r.gatherServer("http://localhost:8091/", acc)
|
r.gatherServer("http://localhost:8091/", acc, nil)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ func (r *Couchbase) Gather(acc telegraf.Accumulator) error {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go func(serv string) {
|
go func(serv string) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
outerr = r.gatherServer(serv, acc)
|
outerr = r.gatherServer(serv, acc, nil)
|
||||||
}(serv)
|
}(serv)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,18 +57,22 @@ func (r *Couchbase) Gather(acc telegraf.Accumulator) error {
|
||||||
return outerr
|
return outerr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Couchbase) gatherServer(addr string, acc telegraf.Accumulator) error {
|
func (r *Couchbase) gatherServer(addr string, acc telegraf.Accumulator, pool *couchbase.Pool) error {
|
||||||
|
if pool == nil {
|
||||||
client, err := couchbase.Connect(addr)
|
client, err := couchbase.Connect(addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// `default` is the only possible pool name. It's a
|
// `default` is the only possible pool name. It's a
|
||||||
// placeholder for a possible future Couchbase feature. See
|
// placeholder for a possible future Couchbase feature. See
|
||||||
// http://stackoverflow.com/a/16990911/17498.
|
// http://stackoverflow.com/a/16990911/17498.
|
||||||
pool, err := client.GetPool("default")
|
p, err := client.GetPool("default")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
pool = &p
|
||||||
|
}
|
||||||
for i := 0; i < len(pool.Nodes); i++ {
|
for i := 0; i < len(pool.Nodes); i++ {
|
||||||
node := pool.Nodes[i]
|
node := pool.Nodes[i]
|
||||||
tags := map[string]string{"cluster": addr, "hostname": node.Hostname}
|
tags := map[string]string{"cluster": addr, "hostname": node.Hostname}
|
||||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue