<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Why do the earliest and latest timechart functions produce unexpected results? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Why-do-the-earliest-and-latest-timechart-functions-produce/m-p/177433#M51023</link>
    <description>&lt;P&gt;It should help to consider how &lt;CODE&gt;bucketing&lt;/CODE&gt; works for timechart (read the dox on &lt;CODE&gt;bucket&lt;/CODE&gt;, AKA &lt;CODE&gt;bin&lt;/CODE&gt;).  When you tell &lt;CODE&gt;timechart&lt;/CODE&gt; to &lt;CODE&gt;bucket&lt;/CODE&gt; with &lt;CODE&gt;span=1d&lt;/CODE&gt;, Splunk modifies every event's &lt;CODE&gt;_time&lt;/CODE&gt; value and changes it (for this search) from whatever it used to be to &lt;CODE&gt;0d@d&lt;/CODE&gt; which is exactly at midnight: 00:00:00.000.  Once this has happened, it may be unknown/undefined/unpredictable how any version of Splunk will select a single "winner" for "earliest" when all events for "today" now have exactly the same timestamp.  It &lt;EM&gt;should&lt;/EM&gt; be that  &lt;CODE&gt;timechart&lt;/CODE&gt; calculates &lt;CODE&gt;earliest&lt;/CODE&gt; and &lt;CODE&gt;latest&lt;/CODE&gt; &lt;EM&gt;before&lt;/EM&gt; it modifies &lt;CODE&gt;_time&lt;/CODE&gt; but perhaps there is a reason that it cannot.  IMHO, the situation is either a code bug or a documentation bug (not mentioning this aspect) so I would open a support ticket.&lt;/P&gt;

&lt;P&gt;But I have 1 caveat: if you are bucketing twice in a row (e.g. &lt;CODE&gt;... | bucket _time span=1h ... | timechart span=1h earlirlest(value) ...&lt;/CODE&gt;) then you absolutely cannot fault Splunk for being unable to get the right answer because the &lt;CODE&gt;bucket&lt;/CODE&gt; changes to &lt;CODE&gt;_time&lt;/CODE&gt; mean that the &lt;CODE&gt;timechart&lt;/CODE&gt; has no reliable reference point to break the ties correctly.  Are you doing 2 &lt;CODE&gt;bucketing&lt;/CODE&gt; commands like this?&lt;/P&gt;</description>
    <pubDate>Wed, 19 Aug 2015 01:37:50 GMT</pubDate>
    <dc:creator>woodcock</dc:creator>
    <dc:date>2015-08-19T01:37:50Z</dc:date>
    <item>
      <title>Why do the earliest and latest timechart functions produce unexpected results?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-do-the-earliest-and-latest-timechart-functions-produce/m-p/177431#M51021</link>
      <description>&lt;P&gt;In the process of trying to verify some summary index data I've noticed that &lt;CODE&gt;timechart&lt;/CODE&gt; does not seem to return expected results when using the &lt;CODE&gt;earliest&lt;/CODE&gt; and &lt;CODE&gt;latest&lt;/CODE&gt; functions.&lt;/P&gt;

&lt;P&gt;Example data:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;indextime    _time                Value
1438019839  2015-07-27 11:03:27 173755
1438019838  2015-07-27 11:03:10 173755
1438019838  2015-07-27 11:03:09 173755
1438019836  2015-07-27 11:03:05 173750
1438019838  2015-07-27 11:02:46 173750
1438019834  2015-07-27 11:02:29 173750
1438019833  2015-07-27 11:02:28 173750
1438019834  2015-07-27 11:02:24 173747
1438019834  2015-07-27 11:01:56 173747
1438019832  2015-07-27 11:01:39 173747
1438019834  2015-07-27 11:01:39 173747
1438019832  2015-07-27 11:01:33 173727
1438019832  2015-07-27 11:01:15 173727
1438019831  2015-07-27 11:00:58 173727
1438019832  2015-07-27 11:00:56 173727
1438019831  2015-07-27 11:00:52 173717
1438019831  2015-07-27 11:00:32 173717
1438019831  2015-07-27 11:00:14 173717
1438019831  2015-07-27 11:00:13 173717
1438019831  2015-07-27 11:00:09 173712
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I've included indextime as I thought it might be relevant. But note that sorting by indextime does not change the earliest and latest values.&lt;/P&gt;

&lt;P&gt;Running a &lt;CODE&gt;timechart&lt;/CODE&gt; using &lt;CODE&gt;earliest&lt;/CODE&gt; and &lt;CODE&gt;latest&lt;/CODE&gt; against this data yields results which are clearly incorrect.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| timechart span=1d earliest(Value) as earliestValue, latest(Value) as latestValue, max(Value) as maxValue, min(Value) as minValue

_time        earliestValue  latestValue maxValue    minValue
2015-07-27  173755         173755        173755   173712
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;While stats produces the correct output...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats earliest(Value) as earliestValue, latest(Value) as latestValue, max(Value) as maxValue, min(Value) as minValue

earliestValue   latestValue maxValue    minValue
173712         173755        173755   173712
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Interestingly, using &lt;CODE&gt;first&lt;/CODE&gt; and &lt;CODE&gt;last&lt;/CODE&gt; inplace of &lt;CODE&gt;latest&lt;/CODE&gt; and &lt;CODE&gt;earliest&lt;/CODE&gt; with &lt;CODE&gt;timechart&lt;/CODE&gt; does produce the correct output.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| timechart span=1d last(Value) as earliestValue, first(Value) as latestValue, max(Value) as maxValue, min(Value) as minValue

_time        earliestValue  latestValue maxValue    minValue
2015-07-27  173712         173755        173755   173712
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I've searched through the docs and can't find any mention of why this could be occurring. I presume there is some internal reason why &lt;CODE&gt;timechart&lt;/CODE&gt; functions this way, but it's very counter-intuative and not at all clear. Does anyone know why the &lt;CODE&gt;earliest&lt;/CODE&gt; and &lt;CODE&gt;latest&lt;/CODE&gt; functions work this way with &lt;CODE&gt;timechart&lt;/CODE&gt;?&lt;/P&gt;

&lt;P&gt;Running Splunk 6.2.4 on Oracle Enterprise Linux 6.5.&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Update:&lt;/STRONG&gt;&lt;BR /&gt;
Results of &lt;CODE&gt;| table _time Value&lt;/CODE&gt; per @somesoni2's request.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;_time               Value
2015-07-27 11:03:27 173755
2015-07-27 11:03:10 173755
2015-07-27 11:03:09 173755
2015-07-27 11:02:46 173750
2015-07-27 11:03:05 173750
2015-07-27 11:01:39 173747
2015-07-27 11:02:24 173747
2015-07-27 11:02:29 173750
2015-07-27 11:01:56 173747
2015-07-27 11:02:28 173750
2015-07-27 11:01:33 173727
2015-07-27 11:01:39 173747
2015-07-27 11:01:15 173727
2015-07-27 11:00:56 173727
2015-07-27 11:00:58 173727
2015-07-27 11:00:14 173717
2015-07-27 11:00:13 173717
2015-07-27 11:00:52 173717
2015-07-27 11:00:32 173717
2015-07-27 11:00:09 173712
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 18 Aug 2015 19:37:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-do-the-earliest-and-latest-timechart-functions-produce/m-p/177431#M51021</guid>
      <dc:creator>curtisb1024</dc:creator>
      <dc:date>2015-08-18T19:37:17Z</dc:date>
    </item>
    <item>
      <title>Re: Why do the earliest and latest timechart functions produce unexpected results?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-do-the-earliest-and-latest-timechart-functions-produce/m-p/177432#M51022</link>
      <description>&lt;P&gt;Can you try putting a " | table _time Value" before the timechart and see the result?&lt;/P&gt;</description>
      <pubDate>Tue, 18 Aug 2015 21:59:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-do-the-earliest-and-latest-timechart-functions-produce/m-p/177432#M51022</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2015-08-18T21:59:56Z</dc:date>
    </item>
    <item>
      <title>Re: Why do the earliest and latest timechart functions produce unexpected results?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-do-the-earliest-and-latest-timechart-functions-produce/m-p/177433#M51023</link>
      <description>&lt;P&gt;It should help to consider how &lt;CODE&gt;bucketing&lt;/CODE&gt; works for timechart (read the dox on &lt;CODE&gt;bucket&lt;/CODE&gt;, AKA &lt;CODE&gt;bin&lt;/CODE&gt;).  When you tell &lt;CODE&gt;timechart&lt;/CODE&gt; to &lt;CODE&gt;bucket&lt;/CODE&gt; with &lt;CODE&gt;span=1d&lt;/CODE&gt;, Splunk modifies every event's &lt;CODE&gt;_time&lt;/CODE&gt; value and changes it (for this search) from whatever it used to be to &lt;CODE&gt;0d@d&lt;/CODE&gt; which is exactly at midnight: 00:00:00.000.  Once this has happened, it may be unknown/undefined/unpredictable how any version of Splunk will select a single "winner" for "earliest" when all events for "today" now have exactly the same timestamp.  It &lt;EM&gt;should&lt;/EM&gt; be that  &lt;CODE&gt;timechart&lt;/CODE&gt; calculates &lt;CODE&gt;earliest&lt;/CODE&gt; and &lt;CODE&gt;latest&lt;/CODE&gt; &lt;EM&gt;before&lt;/EM&gt; it modifies &lt;CODE&gt;_time&lt;/CODE&gt; but perhaps there is a reason that it cannot.  IMHO, the situation is either a code bug or a documentation bug (not mentioning this aspect) so I would open a support ticket.&lt;/P&gt;

&lt;P&gt;But I have 1 caveat: if you are bucketing twice in a row (e.g. &lt;CODE&gt;... | bucket _time span=1h ... | timechart span=1h earlirlest(value) ...&lt;/CODE&gt;) then you absolutely cannot fault Splunk for being unable to get the right answer because the &lt;CODE&gt;bucket&lt;/CODE&gt; changes to &lt;CODE&gt;_time&lt;/CODE&gt; mean that the &lt;CODE&gt;timechart&lt;/CODE&gt; has no reliable reference point to break the ties correctly.  Are you doing 2 &lt;CODE&gt;bucketing&lt;/CODE&gt; commands like this?&lt;/P&gt;</description>
      <pubDate>Wed, 19 Aug 2015 01:37:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-do-the-earliest-and-latest-timechart-functions-produce/m-p/177433#M51023</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-08-19T01:37:50Z</dc:date>
    </item>
    <item>
      <title>Re: Why do the earliest and latest timechart functions produce unexpected results?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-do-the-earliest-and-latest-timechart-functions-produce/m-p/177434#M51024</link>
      <description>&lt;P&gt;I've added results per your request. I assume you wanted to see the table output as it's returned from Splunk (rather than being sorted by time). I also tested adding the table before the timechart, but this had no effect on the timechart output.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Aug 2015 13:02:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-do-the-earliest-and-latest-timechart-functions-produce/m-p/177434#M51024</guid>
      <dc:creator>curtisb1024</dc:creator>
      <dc:date>2015-08-19T13:02:16Z</dc:date>
    </item>
    <item>
      <title>Re: Why do the earliest and latest timechart functions produce unexpected results?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-do-the-earliest-and-latest-timechart-functions-produce/m-p/177435#M51025</link>
      <description>&lt;P&gt;The bucketing is an excellent thought and this seems likely to be the cause of the issue. In further testing, if I add a "| sort + Value" before the timechart the output changes...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;_time       earliestValue   latestValue maxValue    minValue
2015-07-27  173712          173712      173755      173712
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If bucketing were not the issue (e.g. timestamps has not been modified before the earliest and latest functions run), then the sort would have no effect on the timechart output.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Aug 2015 13:17:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-do-the-earliest-and-latest-timechart-functions-produce/m-p/177435#M51025</guid>
      <dc:creator>curtisb1024</dc:creator>
      <dc:date>2015-08-19T13:17:01Z</dc:date>
    </item>
  </channel>
</rss>

