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

Duration reported incorrectly using ara CLI #523

Open
hovisms opened this issue Oct 23, 2023 · 3 comments
Open

Duration reported incorrectly using ara CLI #523

hovisms opened this issue Oct 23, 2023 · 3 comments

Comments

@hovisms
Copy link

hovisms commented Oct 23, 2023

What is the issue ?

Using the ara (version 1.6.1) command to pull task information, the duration field is sometimes incorrect. The value output by this method is significantly different than the value observed and shown in the web UI. Note, this only happens for some tasks in the report, not all.

Here is an example task that completed in under a second reported correctly by the WebUI but incorrectly by the ara command (both are queries for playbook 211, task 228664):
image

image

What should be happening ?

The duration should be reported correctly/consistently. It would also be helpful if there were an option to output duration in seconds vs. hh:mm:ss.000000 format (which isn't easily processed in excel).

@dmsimard
Copy link
Contributor

Hey @hovisms and thanks for the issue.

Formatting dates and durations is hard :)
I will need to think a bit about whether we should have a field for a duration in seconds and how we might do it.

In the meantime, from a database perspective, the duration is stored as a timedelta computed automatically when an end is known:

ara/ara/api/models.py

Lines 23 to 39 in dde7674

class Duration(Base):
"""
Abstract model for models with a concept of duration
"""
class Meta:
abstract = True
started = models.DateTimeField(default=timezone.now)
ended = models.DateTimeField(blank=True, null=True)
duration = models.DurationField(blank=True, null=True)
def save(self, *args, **kwargs):
# Compute duration based on available timestamps
if self.ended is not None:
self.duration = self.ended - self.started
return super().save(*args, **kwargs)

The API returns the timedelta with the full precision (for example, 00:06:12.756051") while in the UI we shave a few numbers off (00:06:12.75):

@register.filter(name="format_duration")
def format_duration(duration):
if duration is not None:
return duration[:-4]
return duration

I don't have bandwidth to look at this right now but for the CLI, it tries to parse the timedelta string and this might be a good place to start troubleshooting:

ara/ara/cli/utils.py

Lines 33 to 43 in dde7674

def parse_timedelta(duration: str, pattern: str = "%H:%M:%S.%f"):
"""Parses a timedelta string back into a timedelta object"""
parsed = datetime.strptime(duration, pattern)
# fmt: off
return timedelta(
hours=parsed.hour,
minutes=parsed.minute,
seconds=parsed.second,
microseconds=parsed.microsecond
).total_seconds()
# fmt: on

I am not sure what your automation around excel looks like but you could compute a number of seconds by substracting the end date and start date like the database model does and then format it according to your needs.

@dmsimard
Copy link
Contributor

@hovisms unrelated to the original issue but I wanted to point out that it is recommended to run the same version of ara for both the server and the clients in order to avoid running into issues. If the server is 1.7.0 the clients should also have 1.7.0.

@hovisms
Copy link
Author

hovisms commented Oct 25, 2023

Thanks for the quick feedback. I was able to re-calculate duration based on subsequent starting time. I also pulled latest container images to get everything up to 1.7.0.

Thanks again!

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

No branches or pull requests

2 participants