Skip to content

Commit 4bad2e4

Browse files
committed
[juju] Fix juju agent introspect commands
By default the introspect commands are aliases in the bash login profile, so these won't be available via sos. This extraplotes the commands that are available and passes it to juju-introspect. Signed-off-by: Arif Ali <arif.ali@canonical.com>
1 parent 2b3346f commit 4bad2e4

1 file changed

Lines changed: 31 additions & 12 deletions

File tree

sos/report/plugins/juju.py

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import pwd
1212
import json
13+
import re
1314
from sos.report.plugins import Plugin, UbuntuPlugin, PluginOpt
1415

1516

@@ -76,25 +77,34 @@ class Juju(Plugin, UbuntuPlugin):
7677
),
7778
]
7879

80+
agent_name = ""
81+
7982
def setup(self):
8083
# Juju service names are not consistent through deployments,
8184
# so we need to use a wildcard to get the correct service names.
8285
for service in self.get_service_names("juju*"):
8386
self.add_journal(service)
8487
self.add_service_status(service)
8588

86-
self.add_cmd_output([
87-
'juju_engine_report',
88-
'juju_goroutines',
89-
'juju_heap_profile',
90-
'juju_leases',
91-
'juju_metrics',
92-
'juju_pubsub_report',
93-
'juju_presence_report',
94-
'juju_statepool_report',
95-
'juju_statetracker_report',
96-
'juju_unit_status',
97-
])
89+
juju_agent_cmds = {
90+
'juju_engine_report': 'depengine',
91+
'juju_goroutines': 'debug/pprof/goroutine?debug=1',
92+
'juju_heap_profile': 'debug/pprof/heap?debug=1',
93+
'juju_metrics': 'metrics',
94+
'juju_pubsub_report': 'pubsub',
95+
'juju_presence_report': 'presence',
96+
'juju_statepool_report': 'statepool',
97+
'juju_statetracker_report': ('debug/pprof/juju/state/tracker?'
98+
'debug=1'),
99+
'juju_unit_status': 'units?action=status',
100+
}
101+
102+
if self.path_exists("/var/lib/juju/agents"):
103+
for cmd, agent_cmd in juju_agent_cmds.items():
104+
self.add_cmd_output(
105+
self._juju_agent(agent_cmd),
106+
suggest_filename=cmd
107+
)
98108

99109
# Get agent configs for each agent.
100110
self.add_copy_spec("/var/lib/juju/agents/*/agent.conf")
@@ -186,6 +196,15 @@ def setup(self):
186196
)
187197
self.add_cmd_output(command, runas=juju_user)
188198

199+
def _juju_agent(self, command):
200+
if self.agent_name == "":
201+
for dir_name in self.listdir("/var/lib/juju/agents"):
202+
if re.search('machine-*|controller-*|application-*', dir_name):
203+
self.agent_name = dir_name
204+
break
205+
206+
return f"juju-introspect --agent={self.agent_name} {command}"
207+
189208
def postproc(self):
190209
agents_path = "/var/lib/juju/agents/*"
191210
protect_keys = [

0 commit comments

Comments
 (0)