Splunk Search

Why does time difference between two time stamps in a single event come out null?

kapoorsumit2020
Loves-to-Learn Everything

Team,

Time difference between end_task_date and start_task_date is coming null. Could you please take a look below and let me know what's wrong in my query.

SPL:

index=cloud sourcetype=lambda:Airflow2Splunk "\"logGroup\"" "\"airflow-OnePIAirflowEnvironment-DEV-Task\""
| rex field=_raw "Marking task as (?<status>[^\.]+)"
| where status IN("FAILED", "SUCCESS", "UP_FOR_RETRY")
| rex field=_raw "dag_id=(?<dag_id>\w+)"
| rex field=_raw "task_id=(?<task_id>\w+)"
| rex field=_raw "start_date=(?<task_start_date>\d{8}T\d{6})"
| rex field=_raw "end_date=(?<task_end_date>\d{8}T\d{6})"
| eval start_task_date=strptime(task_start_date,"%Y%m%dT%H%M%S")
| eval start_task_date=strftime(start_task_date,"%Y-%m-%d %H:%M:%S")
| eval end_task_date=strptime(task_end_date,"%Y%m%dT%H%M%S")
| eval end_task_date=strftime(end_task_date,"%Y-%m-%d %H:%M:%S")
| eval diff=end_task_date-start_task_date
| eval diff=strftime(diff, "%H:%M:%S")
| sort - _time
| table dag_id task_id status start_task_date end_task_date diff

the value for diff column is coming null. for other columns i'm getting the data correctly.

Here are sample values for date fields:

end_task_date:

2022-04-06 20:51:11 
2022-04-06 20:54:09

end_task_date:

2022-04-06 20:51:09
2022-04-06 20:52:07

end_date:

20220406T205111
20220406T205409

start_date:

20220406T205109
20220406T205207

Please let me know if you need additional information pertaining to this request.

Thanks,

Sumit

Labels (1)
0 Karma

PickleRick
SplunkTrust
SplunkTrust

I don't get it. Either I see something wrong or you're strptime'ing some string to get a timestamp only to strftime it back to a string? What's the point? Then you're trying to substract one string from another. It doesn't work that way.

You should do strptime on those fields to get timestamps, then do the substraction and finally maybe render the difference to a string, but not by strftime, but rather by tostring() with format "duration"

Get Updates on the Splunk Community!

Webinar Recap | Revolutionizing IT Operations: The Transformative Power of AI and ML ...

The Transformative Power of AI and ML in Enhancing Observability   In the realm of IT operations, the ...

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...