Skip to content

feat(cli): rhc collector CLI#425

Merged
pkoprda merged 4 commits into
mainfrom
pkoprda/collector-cli
May 5, 2026
Merged

feat(cli): rhc collector CLI#425
pkoprda merged 4 commits into
mainfrom
pkoprda/collector-cli

Conversation

@pkoprda
Copy link
Copy Markdown
Contributor

@pkoprda pkoprda commented Apr 29, 2026

Add comprehensive collector CLI interface with commands:

  • rhc collector info - Display collector information
  • rhc collector list - List available collectors
  • rhc collector timers - List collector timers
  • rhc collector enable [--now] - Enable timer-based collection
  • rhc collector disable [--now] - Disable timer-based collection

An example of how to test this PR:

# systemctl enable rhc-server.socket rhc-server.service
# systemctl start rhc-server.socket rhc-server.service
# mkdir -p /usr/lib/rhc/collectors/
# cat /usr/lib/rhc/collectors/com.redhat.advisor.toml
[meta]
name = "Red Hat Lightspeed Advisor"
feature = "analytics"
type = "ingress"

[ingress]
user = "root"
group = "root"
content_type = "application/vnd.redhat.advisor.collection"
# mkdir -p /var/cache/rhc/collectors/
# cat /var/cache/rhc/collectors/com.redhat.advisor.json
{
  "last_started": {"timestamp": 1777461050},
  "last_finished": {"timestamp": 1777461150, "exit_code": 0}
}

# rhc collector
NAME:
   rhc collector - Collect data for analysis

USAGE:
   rhc collector COMMAND [command options]

COMMANDS:
   info     Display collector information
   list     List available collectors
   timers   List collector timers
   enable   Enable timer-based collection
   disable  Disable timer-based collection
   help, h  Shows a list of commands or help for one command

OPTIONS:
   --help, -h  show help
# rhc collector list
ID                  NAME
com.redhat.advisor  Red Hat Lightspeed Advisor
# rhc collector info com.redhat.advisor
Name:      Red Hat Lightspeed Advisor
Feature:   analytics

Last run:  Wed 2026-04-29 07:12 EDT (2h 48m ago)
Next run:  -

Config:   /usr/lib/rhc/collectors/com.redhat.advisor.toml
Service:  rhc-collector-com.redhat.advisor.service
Timer:    rhc-collector-com.redhat.advisor.timer
# rhc collector timers
ID                  LAST    NEXT
com.redhat.advisor  2h 48m  -

Hint: Run 'rhc collector info COLLECTOR' to show more details.

@pkoprda pkoprda force-pushed the pkoprda/collector-cli branch 2 times, most recently from 918292f to 4ed2eee Compare April 29, 2026 13:20
@pkoprda pkoprda requested review from m-horky and mjcr99 April 29, 2026 14:03
Copy link
Copy Markdown
Collaborator

@m-horky m-horky left a comment

Choose a reason for hiding this comment

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

I have not discovered any significant issues, overall the code feels solid and considering the state of the codebase well structured.

UX notes:

  • With no data collector, list outputs failed to list collectors: EOF. Could we display some better message, like "Error: No data collectors are available"?
  • rhc collector timers does not display the value of NEXT, even when the timer is enabled. It may be because we aren't passing --all flag to systemctl list-timers.

More inline.

Comment thread internal/ui/collector.go Outdated
Comment thread internal/ui/collector.go
Comment thread internal/ui/collector.go
Comment thread internal/collector/collector.go Outdated
Comment thread cmd/rhc/collector_cmd.go Outdated
@pkoprda pkoprda force-pushed the pkoprda/collector-cli branch from 4ed2eee to 1d79ba0 Compare May 4, 2026 10:16
m-horky
m-horky previously approved these changes May 4, 2026
Copy link
Copy Markdown
Collaborator

@m-horky m-horky left a comment

Choose a reason for hiding this comment

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

Nothing stands out, you have my ACK. I'm leaving the resolution of the rest of my comments up to you.

Comment thread internal/ui/collector.go
Copy link
Copy Markdown
Contributor

@mjcr99 mjcr99 left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @pkoprda! LGTM, I have a nit suggestion.

Comment thread cmd/rhc/collector_cmd.go
pkoprda added 4 commits May 4, 2026 15:29
* Card ID: CCT-1845

Add functions for formatting collector information and timers:
- FormatCollectorInfo() for detailed collector display
- PrintCollectorTimers() for tabular timer information
- PrintTable() utility for formatted table output

Supports both human-readable and JSON output formats.

Assisted-By: Claude Code <noreply@anthropic.com>
* Card ID: CCT-1845

Add IsSystemdAvailable() function to detect if systemd is present in the
current environment. Returns false in containers or environments where
systemd is not running.

- Add ValidateCollectorAndConnect() function for collector
enable/disable operations
- Includes systemd detection, collector validation, and connection setup

Assisted-By: Claude Code <noreply@anthropic.com>
The systemctl list-timers command without --all flag only show active
timers. For enabled but inactive timers, the --all flag is needed to
display next run times.
* Card ID: CCT-1845

Add comprehensive collector CLI interface with commands:
- rhc collector info <ID> - Display collector information
- rhc collector list - List available collectors
- rhc collector timers - List collector timers
- rhc collector enable [--now] <ID> - Enable timer-based collection
- rhc collector disable [--now] <ID> - Disable timer-based collection

Assisted-By: Claude Code <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@mjcr99 mjcr99 left a comment

Choose a reason for hiding this comment

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

LGTM

@pkoprda pkoprda merged commit cb6d8d1 into main May 5, 2026
21 checks passed
@pkoprda pkoprda deleted the pkoprda/collector-cli branch May 5, 2026 11:01
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