Skip to content

feat(plugin): add get events command with Loki source#929

Open
rohan2794 wants to merge 1 commit into
openebs:developfrom
rohan2794:get-events-loki
Open

feat(plugin): add get events command with Loki source#929
rohan2794 wants to merge 1 commit into
openebs:developfrom
rohan2794:get-events-loki

Conversation

@rohan2794

@rohan2794 rohan2794 commented Jul 9, 2026

Copy link
Copy Markdown

Add kubectl mayastor get events subcommand that queries the
eventing-aggregator's structured event logs from Loki.

  • New EventsArgs clap struct with --loki-endpoint, --category,
    --action, --node, --target, --since (default 24h), --limit flags
  • EventRecord type: display fields (#[serde(skip)]) for table output,
    #[serde(flatten)] EventMessage for full JSON/YAML output
  • parse_line() strips tracing prefix and deserialises the mbus_event
    JSON envelope into a typed EventMessage (events-api)
  • Filters applied in-memory after fetch; results sorted newest-first
  • LogQL filter |= "mbus_event" pre-filters Loki lines server-side
  • Diagnostic hint when Loki returns no lines (suggests --since widening)
    vs when lines were fetched but no events matched the applied filters
  • Wired into GetResourcesK8s enum in resources/mod.rs
  • Added events-api and prettytable-rs dependencies to k8s/plugin
kubectl-mayastor get events --category pool --node node-1-478889
 TIMESTAMP                                CATEGORY  ACTION  TARGET                                 NODE                  COMPONENT 
 2026-07-09T07:25:51.260430340Z           Pool    Create    pool-1-on-node-1-478889           node-1-478889         IoEngine
kubectl-mayastor get events --category pool --node node-1-478889 -oyaml
- category: Pool
  action: Create
  target: pool-1-on-node-1-478889
  metadata:
    id: e61c9fec-6bd1-43fa-9f6d-e32386f023bb
    source:
      component: IoEngine
      node: node-1-478889
    timestamp: 2026-07-09T07:25:51.260430340Z
    version: V1

kubectl-mayastor get events --category pool --node node-1-478889 -ojson
[{"category":"Pool","action":"Create","target":"pool-1-on-node-1-478889","metadata":{"id":"e61c9fec-6bd1-43fa-9f6d-e32386f023bb","source":{"component":"IoEngine","node":"node-1-478889"},"timestamp":"2026-07-09T07:25:51.260430340Z","version":"V1"}}]

@rohan2794 rohan2794 requested a review from a team as a code owner July 9, 2026 09:50
@mergify

mergify Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

@rohan2794 rohan2794 changed the title eat(plugin): add get events command with Loki source feat(plugin): add get events command with Loki source Jul 9, 2026
Comment thread k8s/plugin/Cargo.toml
Comment on lines +27 to +28
events-api = { path = "../../dependencies/control-plane/utils/dependencies/apis/events" }
prettytable-rs = "0.10.0"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This needs to be pinned on the repo's root level Cargo.toml?
And this needs to use the workspace version

Comment on lines +18 to +43
#[clap(long)]
loki_endpoint: Option<String>,

/// Filter by event category (repeatable or comma-separated), e.g. volume, pool.
#[clap(long = "category", value_delimiter = ',')]
categories: Vec<String>,

/// Filter by event action (repeatable or comma-separated), e.g. create, delete.
#[clap(long = "action", value_delimiter = ',')]
actions: Vec<String>,

/// Filter by node name.
#[clap(long)]
node: Option<String>,

/// Filter by target resource ID.
#[clap(long)]
target: Option<String>,

/// Events from last duration (e.g. 1h, 30m).
#[clap(long, default_value = "24h")]
since: humantime::Duration,

/// Maximum number of events to return (0 = unlimited).
#[clap(long, default_value_t = DEFAULT_LIMIT)]
limit: usize,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: we shouldn't use clap() for new codebases, should be arg. clap() is older, and although clap v4 has backwards compatibility for it, we should use the newer API.

Comment on lines +243 to +251
let mut label_filters: String = label_selector
.split(',')
.map(|key_value_pair| {
let pairs = key_value_pair.split('=').collect::<Vec<&str>>();
format!("{}=\"{}\",", pairs[0], pairs[1])
.replace('.', "_")
.replace('/', "_")
})
.collect::<String>();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why is this required?

Add kubectl mayastor get events subcommand that queries the
eventing-aggregator's structured event logs from Loki.

- New EventsArgs clap struct with --loki-endpoint, --category,
  --action, --node, --target, --since (default 24h), --limit flags
- EventRecord type: display fields (#[serde(skip)]) for table output,
  #[serde(flatten)] EventMessage for full JSON/YAML output
- parse_line() strips tracing prefix and deserialises the mbus_event
  JSON envelope into a typed EventMessage (events-api)
- Filters applied in-memory after fetch; results sorted newest-first
- LogQL filter mbus_event pre-filters Loki lines server-side
- Diagnostic hint when Loki returns no lines (suggests --since widening)
  vs when lines were fetched but no events matched the applied filters
- Wired into GetResourcesK8s enum in resources/mod.rs
- Added events-api and prettytable-rs dependencies to k8s/plugin

Signed-off-by: rohan2794 <rohan2794@gmial.com>
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.

2 participants