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

Bucket aggregation appears not to be rolling over time #173

Open
lyrixx opened this issue Aug 1, 2019 · 2 comments

Comments

@lyrixx
Copy link

commented Aug 1, 2019

Hello,

I noticed something a bit strange with bucket aggregation.

I have create a small reproducer in PHP. If you are not confortable with this language, I can translate it to another language.

$redis->del('failed');

// Feed
$startedAtTimestamp = (time() - 25) * 1000; // time() is in second, redis prefer millisecond
$endedAtTimestamp = time() * 1000;
for ($i = $startedAtTimestamp, $j = 0; $i <= $endedAtTimestamp; $i = $i + 100, ++$j) {
    $redis->rawCommand('TS.ADD', 'failed', $i, $j);
}

// Query
$toTimestamp = time() * 1000;
$fromTimestamp = $toTimestamp - 4 * 1000;
$timeBucket = 4 * 1000;

$failedCount = $redis->rawCommand('TS.RANGE', 'failed', $fromTimestamp, $toTimestamp, 'AGGREGATION', 'sum', $timeBucket);
dump($failedCount);

So When I Execute it multiple time, It go the following results:

array:2 [
  0 => array:2 [
    0 => 1564649976000
    1 => "9180"
  ]
  1 => array:2 [
    0 => 1564649980000
    1 => "250"
  ]
]
array:2 [
  0 => array:2 [
    0 => 1564649976000
    1 => "6735"
  ]
  1 => array:2 [
    0 => 1564649980000
    1 => "2695"
  ]
]
array:2 [
  0 => array:2 [
    0 => 1564649976000
    1 => "4390"
  ]
  1 => array:2 [
    0 => 1564649980000
    1 => "5040"
  ]
]
array:2 [
  0 => array:2 [
    0 => 1564649976000
    1 => "2145"
  ]
  1 => array:2 [
    0 => 1564649980000
    1 => "7285"
  ]
]
array:2 [
  0 => array:2 [
    0 => 1564649976000
    1 => "2145"
  ]
  1 => array:2 [
    0 => 1564649980000
    1 => "7285"
  ]
]
array:2 [
  0 => array:2 [
    0 => 1564649980000
    1 => "9180"
  ]
  1 => array:2 [
    0 => 1564649984000
    1 => "250"
  ]
]

Is this intended ?

@danni-m

This comment has been minimized.

Copy link
Collaborator

commented Aug 5, 2019

@lyrixx in your query you are asking for the last 4 seconds with the aggregation, your start time is changed everytime you run it.
Since we are aggregating by bucketing the time into 4 seconds buckets sometimes the end of your data might fall into 1 or more buckets (the shift depends on the start time).

What are you expecting the output would be?

@lyrixx

This comment has been minimized.

Copy link
Author

commented Aug 5, 2019

As the range is 4 seconds, and the aggregation time is also 4 seconds, I'm expecting to get only one value and not two

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.