Splunk Search

Inconsistent behavior with eval after stats

randeepbydesign
Engager

I have this query that matches two types of events, sending a request and receiving an answer. My goal is to take the time both of these happens to see how long the question/answer process takes:

 

index = "application" ("request sent" OR "answer received") 
| rex field=_raw ".*\s+:\s+(?<label>\w+).+\s+(?<guid>[a-z\d-]+)$" 
| eval status=if(label="answer","complete","start") 
| eval start_time=if(status="complete",null,_time), end_time=if(status="complete",_time,null) 
| stats min(start_time) as startT, min(end_time) as endT by guid 
| eval exportTimeInMinutes=abs(end_time-start_time)/60

 

 This query works fine and I use it as a template for others. But the problem I am having is that I want to see a screen stats table which includes the exportTimeInMinutes column. When I first write this query I got back a table with 4 columns: guid, startT, endT and exportTimeInMinutes

However, when I come back into the page in a future session I no longer see the last column. Sometimes refreshing the page allows it to show up, other times it does not. Is this a bug (or even worse... a feature)?

Labels (2)
0 Karma
1 Solution

anilchaithu
Builder

@randeepbydesign 

The output fields from line 5 of your SPL are startT, endT and guid.

The required inputs for eval is end_time & start_time which are not inline.

change eval statement as shown below.

| eval exportTimeInMinutes=abs(endT-startT)/60

 

 Hope this helps

View solution in original post

anilchaithu
Builder

@randeepbydesign 

The output fields from line 5 of your SPL are startT, endT and guid.

The required inputs for eval is end_time & start_time which are not inline.

change eval statement as shown below.

| eval exportTimeInMinutes=abs(endT-startT)/60

 

 Hope this helps

randeepbydesign
Engager

It definitely helped. Thank you so much!

0 Karma
Get Updates on the Splunk Community!

Splunk Observability for AI

Don’t miss out on an exciting Tech Talk on Splunk Observability for AI!Discover how Splunk’s agentic AI ...

🔐 Trust at Every Hop: How mTLS in Splunk Enterprise 10.0 Makes Security Simpler

From Idea to Implementation: Why Splunk Built mTLS into Splunk Enterprise 10.0  mTLS wasn’t just a checkbox ...

Observe and Secure All Apps with Splunk

  Join Us for Our Next Tech Talk: Observe and Secure All Apps with SplunkAs organizations continue to innovate ...