Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature]: Ability to override/provide time_unix_nano whenm creating metric #2472

Open
REASY opened this issue Dec 26, 2024 · 0 comments
Open
Labels
enhancement New feature or request triage:todo Needs to be traiged.

Comments

@REASY
Copy link

REASY commented Dec 26, 2024

Related Problems?

No response

Describe the solution you'd like:

I would want to have a way to assing time/start_time of a metric so I have a better control over it, instead of using SystemTime::now

pub(crate) struct AggregateTimeInitiator(Mutex<SystemTime>);

impl AggregateTimeInitiator {
    pub(crate) fn delta(&self) -> AggregateTime {
        let current_time = SystemTime::now();
        let start_time = self
            .0
            .lock()
            .map(|mut start| replace(start.deref_mut(), current_time))
            .unwrap_or(current_time);
        AggregateTime {
            start: start_time,
            current: current_time,
        }
    }

    pub(crate) fn cumulative(&self) -> AggregateTime {
        let current_time = SystemTime::now();
        let start_time = self.0.lock().map(|start| *start).unwrap_or(current_time);
        AggregateTime {
            start: start_time,
            current: current_time,
        }
    }
}

Considered Alternatives

No response

Additional Context

No response

@REASY REASY added enhancement New feature or request triage:todo Needs to be traiged. labels Dec 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request triage:todo Needs to be traiged.
Projects
None yet
Development

No branches or pull requests

1 participant