dbadmin interface sets incorrect hostname on all telegraf subordinates

Bug #1775062 reported by Shane Peters on 2018-06-04
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Telegraf Charm
Alvaro Uria

Bug Description

When using the mysql:dbadmin interface to have telegraf poll mysql-specific metrics, the hostname across other telegraf subordinates changes to 'mysql/x'.

The issue lies in get_remote_unit_name which returns the unit_name for the first relation found, without confirming it's for that specific unit.

This is due to the removal of a test which used the IP address determine the correct unit.

From a debug session, we can see that the 'mysql' relation will be tested before the juju-info relation and will the return the mysql unit name:

(Pdb) hookenv.metadata()['requires'].keys()
dict_keys(['exec', 'haproxy', 'apache', 'mysql', 'postgresql', 'influxdb-api', 'juju-info', 'mongodb', 'elasticsearch', 'memcached'])

The workaround here is to remove the mysql:dbadmin relation.

Tags: sts Edit Tag help

Related branches

Shane Peters (shaner) on 2018-06-04
description: updated
Alvaro Uria (aluria) wrote :

Shane, my bad

It looks I didn't understand correctly the following:
rels = hookenv.relations_of_type(rel_type)

However, my quick test works as I expected:
juju deploy ubuntu --to lxd:0
juju deploy mysql --to lxd:1
juju deploy telegraf

juju add-relation ubuntu telegraf:juju-info
juju add-relation mysql:db-admin telegraf:mysql
juju add-relation mysql:juju-info telegraf:juju-info

"juju status --format yaml" shows

And the "host" label in the /metrics page is:
$ juju machines | egrep -o '([0-9]+\.){3}[0-9]+' | xargs -I@ bash -xc 'curl -s @:9103/metrics | egrep -o "host=\"[^\"]+\"" | sort -u'
+ curl -s
+ egrep -o 'host="[^"]+"'
+ sort -u
+ curl -s
+ egrep -o 'host="[^"]+"'
+ sort -u

Note: "tgraf" is the model name

Alvaro Uria (aluria) wrote :

From the above, I understand:
* ubuntu unit has rel['unit-name'] = 'ubuntu-0'
* mysql unit, not matter the type of relation, has rel['unit-name'] = 'mysql-0'

Could you please provide a way to reproduce the issue? Thank you!

Alvaro Uria (aluria) wrote :

I see now:

juju debug-hooks telegraf/2 # in another terminal, run juju run --unit telegraf/2 hoosk/update-status
>>> from charmhelpers.core import hookenv
>>> hookenv.metadata()['requires'].keys()
dict_keys(['elasticsearch', 'juju-info', 'haproxy', 'memcached', 'apache', 'influxdb-api', 'postgresql', 'exec', 'mysql', 'mongodb'])
>>> hookenv.relations_of_type('juju-info')
[{'egress-subnets': '', 'private-address': '', 'ingress-address': '', '__relid__': 'juju-info:4', '__unit__': 'ubuntu-lxd/0'}]
>>> hookenv.relations_of_type('mysql')
[{'egress-subnets': '', 'private-address': '', 'ingress-address': '', '__relid__': 'mysql:3', 'database': 'telegraf', 'password': 'lai7Uo6uKahquai', 'slave': 'False', 'user': 'quoh3JiG8ahchuu', 'host': '', '__unit__': 'mysql/0'}]

I didn't expect hookenv.relations_of_type(...) to return units which the current telegraf unit is not subordinate of.

I'll work on a patch

Changed in telegraf-charm:
importance: Undecided → Medium
assignee: nobody → Alvaro Uría (aluria)
Shane Peters (shaner) wrote :

Thanks Alvaro!

Alvaro Uria (aluria) wrote :

Fix has been reviewed and released to the charm store. cs:telegraf-14.

Changed in telegraf-charm:
status: New → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers