Skip to content

feat(ASB-4540): centralise CLI API endpoints and report cluster health in info#127

Open
marioaxonops wants to merge 6 commits into
mainfrom
feat/ASB-4540-cli-urls-and-info-health
Open

feat(ASB-4540): centralise CLI API endpoints and report cluster health in info#127
marioaxonops wants to merge 6 commits into
mainfrom
feat/ASB-4540-cli-urls-and-info-health

Conversation

@marioaxonops

Copy link
Copy Markdown
Collaborator

Summary

  • Centralise API endpoints — every component declared its own endpoint as a class attribute and axonops.py repeated three paths inline. All of them now live in a single axonopscli/urls.py, so changing an endpoint is a one-line edit in one file.
  • Report cluster health in info — a new Orgs component queries /api/v1/orgs, flattens the returned org → type → cluster tree, and reports each cluster as healthy or not (0/1/2OK/Warning/Error, anything else Unknown). Non-OK clusters are repeated in a summary at the end.
  • Add cli/CLAUDE.md — guidance for the axonopscli subproject: how to run the CLI and its tests, the component read-modify-write convention, and base-URL/auth resolution.

Jira: ASB-4540

Incidental fix

AxonOps.find_nodes_ids built its path as api/v1/nodes/... with no leading slash, which concatenated onto the host with no separator (https://host + api/v1/...). Adopting the shared NODES_URL constant corrects it. That function is unreachable as written anyway — it unpacks do_request as a (result, error) tuple while do_request returns a bare dict — so nothing depended on the broken form.

Test plan

No molecule scenarios apply: this branch touches only cli/axonopscli Python and documentation — no roles, templates, or workflows. The six-platform molecule matrix is therefore not exercised.

  • pre-commit run --all-files — passed (trailing whitespace, end-of-files, check-yaml, yamllint).
  • Existing unit suite: python3 -m unittest discover -s tests from cli/ — 9 tests, 3 errors, all pre-existing on main (verified by stashing and re-running). They fail on AttributeError: 'AxonOps' object has no attribute 'do_login' in do_request, unrelated to these changes.
  • Verified manually with a mocked do_request that every component builds a byte-identical full_url to before the refactor, and that Orgs renders correctly for mixed-status, all-healthy, and empty responses.

No new tests were added for the Orgs component. The existing suite is already partly broken, and adding tests to it is better done alongside fixing do_login / the do_request return-type mismatch. Flagging rather than hiding it.

Checklist

  • pre-commit run --all-files passes
  • ansible-lint (production profile) — N/A, no Ansible files changed
  • Molecule tests on all six platforms — N/A, no role behaviour changed
  • CHANGELOG.md updated
  • README updated
  • secrets-auditor: SAFE TO COMMIT
  • docs-quality-reviewer: blocking findings fixed in f98871f

Known issues not addressed here

  • cli/README.md has no AxonOps logo header or contact footer, against the branding standard. Pre-existing on main; deliberately left for a separate docs-only PR rather than bundling a rewrite into a refactor.
  • -v prints request headers including the Authorization: Bearer <token> line (do_request). Pre-existing, but this PR documents -v in the README and so makes it more discoverable. Worth a follow-up to mask it.

Assisted-by: Claude Code

Documents how to run the CLI and its unittest suite from cli/, the
component read-modify-write convention, base-URL/auth resolution, and the
stale dependency instructions in the CLI README.

Signed-off-by: Mario Nugnes <mario.nugnes@digitalis.io>
Every component declared its own endpoint constant as a class attribute,
and axonops.py repeated three paths inline. Move them all into a single
axonopscli/urls.py module and import from there, so an endpoint change is
a one-line edit in one file.

The nodes path in find_nodes_ids was missing its leading slash, which
would have concatenated it onto the host with no separator. Using the
shared NODES_URL constant corrects it.

Signed-off-by: Mario Nugnes <mario.nugnes@digitalis.io>
Add an Orgs component for /api/v1/orgs and call it from info. The
endpoint returns an org -> type -> cluster tree; flatten it and report
each cluster as healthy or not, mapping status 0/1/2 to OK/Warning/Error
and anything else to Unknown.

Clusters that are not OK are repeated in a summary at the end so
problems are visible without reading the whole list.

Signed-off-by: Mario Nugnes <mario.nugnes@digitalis.io>
Signed-off-by: Mario Nugnes <mario.nugnes@digitalis.io>
The info command prints cluster health before nodes; the README
described and showed the reverse order.

Signed-off-by: Mario Nugnes <mario.nugnes@digitalis.io>
@marioaxonops marioaxonops self-assigned this Jul 20, 2026

@rgooding rgooding left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not convinced that the cluster list really fits in the "info" output here. The "info" command shows you some information about the cluster you specify on the command line, and showing a list of all clusters in the output doesn't feel like it's in the right place.
This also does not achieve the original goal of having a simple command which you can run to see if any of your clusters are unhealthy.

I think we should have the cluster list as its own subcommand, maybe cluster-health, which just prints out the list of unhealthy clusters and exits with return code 0 if all clusters are healthy, or 1 if any clusters are not healthy. I think it would also be nice to include a couple of command-line arguments:

  • --show-healthy: displays all clusters in the output, including healthy clusters
  • --cluster-type: allow filtering the output and health check to a specific cluster type (e.g. for if you only want to check the status of your kafka clusters)

@digiserg

Copy link
Copy Markdown
Collaborator

Fair comments from @rgooding I overlooked. Perhaps change the output to json so that you can parse it. That way, if you script it or use the output from another action you can filter for healthy, unhealthy, etc??

Thoughts?

@digiserg
digiserg self-requested a review July 21, 2026 08:46
The info command mixed connection diagnostics with cluster health. Rename
it to health and make the health report the default output: either
"All clusters are healthy" or the list of clusters that are not OK.

--show-healthy adds the healthy clusters and the node inventory,
--show-orgs adds the visible organisations, and the settings/auth summary
is now printed only with -v. The command exits 1 when any cluster is not
OK so it can be used as a gate in a script or CI job.

Signed-off-by: Mario Nugnes <mario.nugnes@digitalis.io>
@marioaxonops

Copy link
Copy Markdown
Collaborator Author

Addressed the review suggestion: info is now health.

  • Default output is the health verdict only — All clusters are healthy, or the list of clusters that are not OK (type/name: status).
  • --show-healthy additionally lists the healthy clusters and the node inventory for --cluster.
  • --show-orgs additionally lists the visible organisations.
  • The connection/auth summary the old info always printed is now behind -v.
  • Exits 1 when any cluster is not OK, so it works as a gate in a script or CI job.

Added cli/tests/test_health_unittest.py (8 tests) covering default output, unrecognised statuses, all-healthy, empty response, both flags, and the verbose settings block. README and CHANGELOG updated.

Note: the AxonOps API reports status per cluster, not per node, so the node list under --show-healthy is the registered inventory rather than a per-node health verdict. Called out in the README.

@marioaxonops

Copy link
Copy Markdown
Collaborator Author

Fair comments from @rgooding I overlooked. Perhaps change the output to json so that you can parse it. That way, if you script it or use the output from another action you can filter for healthy, unhealthy, etc??

Thoughts?

This is a very good point; we should add a --json option globally. Added to the to-do list and will do in a different PR

@marioaxonops

Copy link
Copy Markdown
Collaborator Author

I'm not convinced that the cluster list really fits in the "info" output here. The "info" command shows you some information about the cluster you specify on the command line, and showing a list of all clusters in the output doesn't feel like it's in the right place. This also does not achieve the original goal of having a simple command which you can run to see if any of your clusters are unhealthy.

I think we should have the cluster list as its own subcommand, maybe cluster-health, which just prints out the list of unhealthy clusters and exits with return code 0 if all clusters are healthy, or 1 if any clusters are not healthy. I think it would also be nice to include a couple of command-line arguments:

* `--show-healthy`: displays all clusters in the output, including healthy clusters

* `--cluster-type`: allow filtering the output and health check to a specific cluster type (e.g. for if you only want to check the status of your kafka clusters)

Added a health command what does only the health. Added an option to show healthy node --show-healthy and to show orgs --show-orgs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants