Skip to content

add parse capabilities for duration on event command#3214

Open
mdaffad wants to merge 9 commits intoyouki-dev:mainfrom
mdaffad:enhancing-runc-compatibility-for-interval-on-event
Open

add parse capabilities for duration on event command#3214
mdaffad wants to merge 9 commits intoyouki-dev:mainfrom
mdaffad:enhancing-runc-compatibility-for-interval-on-event

Conversation

@mdaffad
Copy link
Contributor

@mdaffad mdaffad commented Aug 3, 2025

Description

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • Performance improvement
  • Test updates
  • CI/CD related changes
  • Other (please describe):

Testing

  • Added new unit tests
  • Added new integration tests
  • Ran existing test suite
  • Tested manually (please provide steps)

Related Issues

Close #3206

Additional Context

@mdaffad mdaffad marked this pull request as draft August 3, 2025 16:15
@mdaffad mdaffad marked this pull request as ready for review August 3, 2025 16:22
@mdaffad mdaffad force-pushed the enhancing-runc-compatibility-for-interval-on-event branch from 9ec332e to b10c7aa Compare August 3, 2025 16:51
@YJDoc2
Copy link
Collaborator

YJDoc2 commented Aug 7, 2025

Hey, can you rebase and fix the clippy issues? Thanks :)

@mdaffad
Copy link
Contributor Author

mdaffad commented Aug 8, 2025

Updated

@utam0k
Copy link
Member

utam0k commented Aug 12, 2025

@mdaffad Please sign following the instructions in the link
https://github.com/youki-dev/youki/pull/3214/checks?check_run_id=47689260136


let num = num.parse::<u64>().map_err(|_| "Invalid number")?;

let dur = match unit.as_str() {
Copy link
Member

Choose a reason for hiding this comment

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

What if 1h30m?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

@mdaffad mdaffad force-pushed the enhancing-runc-compatibility-for-interval-on-event branch 2 times, most recently from b165eae to 2214ff1 Compare August 18, 2025 14:57
@mdaffad mdaffad requested a review from utam0k August 25, 2025 15:09
@utam0k
Copy link
Member

utam0k commented Aug 26, 2025

keywords = ["youki", "container", "oci"]

[dependencies]
parse_duration = "2.1.1"
Copy link
Member

Choose a reason for hiding this comment

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

Can't we implement it ourselves?

Signed-off-by: Muhammad Daffa Dinaya <muhammaddaffadinaya@gmail.com>
Signed-off-by: Muhammad Daffa Dinaya <muhammaddaffadinaya@gmail.com>
Signed-off-by: Muhammad Daffa Dinaya <muhammaddaffadinaya@gmail.com>
Signed-off-by: Muhammad Daffa Dinaya <muhammaddaffadinaya@gmail.com>
Signed-off-by: Muhammad Daffa Dinaya <muhammaddaffadinaya@gmail.com>
Signed-off-by: Muhammad Daffa Dinaya <muhammaddaffadinaya@gmail.com>
Signed-off-by: Muhammad Daffa Dinaya <muhammaddaffadinaya@gmail.com>
Signed-off-by: Muhammad Daffa Dinaya <muhammaddaffadinaya@gmail.com>
@mdaffad mdaffad force-pushed the enhancing-runc-compatibility-for-interval-on-event branch from 54974f2 to 5d7bffc Compare January 25, 2026 07:27
@mdaffad mdaffad requested a review from utam0k January 25, 2026 07:27
Signed-off-by: Muhammad Daffa Dinaya <muhammaddaffadinaya@gmail.com>
Copy link
Contributor

@nayuta723 nayuta723 left a comment

Choose a reason for hiding this comment

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

@mdaffad
Thank you for your contribution!
To confirm that this change resolves Issue #3206, could you please post the test results in this PR?

Comment on lines +67 to +70
let s = s.trim();
if let Ok(secs) = s.parse::<u64>() {
return Ok(Duration::from_secs(secs));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like runc is not supported.

$ sudo runc events --interval 1 tutorial_container
Incorrect Usage: invalid value "1" for flag -interval: parse error

NAME:
   runc events - display container events such as OOM notifications, cpu, memory, and IO usage statistics

USAGE:
   runc events [command options] <container-id>

Where "<container-id>" is the name for the instance of the container.

DESCRIPTION:
   The events command displays information about the container. By default the
information is displayed once every 5 seconds.

OPTIONS:
   --interval value  set the stats collection interval (default: 5s)
   --stats           display the container's stats then exit
   
ERRO[0000] invalid value "1" for flag -interval: parse error 

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see. I think we should drop the digit only then.

Ok(Duration::from_secs(total_seconds))
}

fn parse_interval(s: &str) -> Result<Duration, String> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please update the return value to use an Error type instead of a String, to stay consistent with the implementation in exec.rs.

Suggested change
fn parse_interval(s: &str) -> Result<Duration, String> {
fn parse_interval(s: &str) -> Result<Duration, Box<dyn Error + Send + Sync + 'static>> {

ref: https://github.com/youki-dev/youki/blob/main/crates/liboci-cli/src/exec.rs#L67-L92

fn parse_duration_string(s: &str) -> Result<Duration, String> {
let s = s.trim().to_lowercase();
let mut total_seconds = 0u64;
let mut current_number = String::new();
Copy link
Contributor

Choose a reason for hiding this comment

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

Using current_number.push(ch) in a loop allocates a String and can cause repeated reallocations. Prefer a slice-based approach: work on &[u8] (or &str), use split_at and a remainder slice so you don't need a digit buffer. That avoids extra allocations and is more efficient.


use clap::Parser;

fn parse_duration_string(s: &str) -> Result<Duration, String> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you also add some unit tests for this logic?

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Difference between the events command in runc and youki

4 participants

Comments