New show-unit command available for testing

We’ve wanted to have a way to inspect Juju units, and a new show-unit command now available in the 2.8.1 edge snap is designed to solve that problem.

Specifically, when debugging Juju deployments, it’s often useful to look at what’s in the relation data. There’s a way to do this using juju exec and hook commands, but it’s not very intuitive.

Hopefully this is useful.

Consider a simple example

$ juju deploy mariadb -n 3
$ juju deploy mediawiki
$ juju relate mediawiki:db mariadb

To look at the relation data bag for the db endpoint for a mediawiki unit, you’d need to do:

$ juju exec --unit mediawiki/0 -- 'relation-ids db'
db:1
$ juju exec --unit mediawiki/0 -- 'relation-list -r 1'
mariadb/0
mariadb/1
mariadb/2
$ juju exec --unit mediawiki/0 -- 'relation-get -r 1 - mariadb/2'
database: mediawiki
egress-subnets: 172.31.15.176/32
host: 172.31.15.176
ingress-address: 172.31.15.176
password: ahjuefumohxeich
private-address: 172.31.15.176
slave: "False"
user: avathuvoovienay

The relation-list command is not strictly needed if the model has reached steady state and units are all in scope.

The show-unit command does this and more - it surfaces what’s already displayed in status (–format yaml) as well as relation data for all related units, plus application data for the relation. You can filter on endpoint or related unit to see one thing at a time if desired.

$ juju show-unit mediawiki/0
mediawiki/0:
  workload-version: 1.19.14
  machine: "3"
  opened-ports:
  - 80/tcp
  public-address: 13.210.206.157
  charm: cs:mediawiki-19
  leader: true
  relation-info:
  - endpoint: db
    related-endpoint: db
    application-data: {}
    related-units:
      mariadb/0:
        in-scope: true
        data:
          database: mediawiki
          egress-subnets: 172.31.9.118/32
          host: 172.31.9.118
          ingress-address: 172.31.9.118
          password: ukacheovaiyahgo
          private-address: 172.31.9.118
          slave: "False"
          user: querohpaepeipiu
      mariadb/1:
        in-scope: true
        data:
          database: mediawiki
          egress-subnets: 172.31.31.116/32
          host: 172.31.31.116
          ingress-address: 172.31.31.116
          password: eipuishaghahluu
          private-address: 172.31.31.116
          slave: "False"
          user: fiebiudaiyeisho
      mariadb/2:
        in-scope: true
        data:
          database: mediawiki
          egress-subnets: 172.31.15.176/32
          host: 172.31.15.176
          ingress-address: 172.31.15.176
          password: ahjuefumohxeich
          private-address: 172.31.15.176
          slave: "False"
          user: avathuvoovienay

Selecting just a single related unit to look at:

$ juju show-unit mediawiki/0 --related-unit mariadb/1
mediawiki/0:
  workload-version: 1.19.14
  machine: "3"
  opened-ports:
  - 80/tcp
  public-address: 13.210.206.157
  charm: cs:mediawiki-19
  leader: true
  relation-info:
  - endpoint: db
    related-endpoint: db
    application-data: {}
    related-units:
      mariadb/1:
        in-scope: true
        data:
          database: mediawiki
          egress-subnets: 172.31.31.116/32
          host: 172.31.31.116
          ingress-address: 172.31.31.116
          password: eipuishaghahluu
          private-address: 172.31.31.116
          slave: "False"
          user: fiebiudaiyeisho

Units will peer relations are handled:

$ juju show-unit mariadb/0 --endpoint cluster
mariadb/0:
  workload-version: 10.1.40
  machine: "0"
  opened-ports: []
  public-address: 13.210.96.137
  charm: cs:trusty/mariadb-7
  leader: true
  relation-info:
  - endpoint: cluster
    related-endpoint: cluster
    application-data: {}
    local-unit:
      in-scope: true
      data:
        egress-subnets: 172.31.9.118/32
        ingress-address: 172.31.9.118
        private-address: 172.31.9.118
    related-units:
      mariadb/1:
        in-scope: true
        data:
          egress-subnets: 172.31.31.116/32
          ingress-address: 172.31.31.116
          private-address: 172.31.31.116
      mariadb/2:
        in-scope: true
        data:
          egress-subnets: 172.31.15.176/32
          ingress-address: 172.31.15.176
          private-address: 172.31.15.176
8 Likes

This is a huge improvement to juju. Easy introspection of relations and units is something that has been a huge pain for me in the past. Also this is valueable to charmers.

This information should be incorporated into basic tutorials on the topic of understanding “relations” awell. Today, almost everyone I know of, has had major issues understanding relations and what goes on there.

This feature could help that. Alot.

@timClicks @emcp

3 Likes

Yeah, this is a big deal. My partner was just having big trouble with this because the commands to get the relation data so hard to remember. This helps a lot. :+1:

This should definitely go into the documentation as soon as it is ready.

2 Likes