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

core: support sub-second step sizes #1692

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,19 @@ package com.netflix.atlas.core.util
*/
object Step {

private final val oneMilli = 1L
private final val oneSecond = 1000L
private final val oneMinute = 60000L
private final val oneHour = 60 * oneMinute
private final val oneDay = 24 * oneHour

private final val allowedStepSizes = {
val subSecond = List(1L, 5L, 10L, 50L, 100L, 500L)
val div60 = List(1, 2, 3, 4, 5, 6, 10, 12, 15, 20, 30)
val subMinute = div60.map(_ * oneSecond)
val subHour = div60.map(_ * oneMinute)
val subDay = List(1, 2, 3, 4, 6, 8, 12).map(_ * oneHour)
subMinute ::: subHour ::: subDay
subSecond ::: subMinute ::: subHour ::: subDay
}

private def datapointsPerPixel(datapoints: Long, width: Int): Long = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ class StepSuite extends FunSuite {

private def days(n: Long): Long = n * 24 * 60 * 60 * 1000

test("round: sub-second step sizes") {
val primaryStep = 1L
assertEquals(1L, Step.round(primaryStep, 1))
assertEquals(5L, Step.round(primaryStep, 2))
assertEquals(10L, Step.round(primaryStep, 6))
assertEquals(50L, Step.round(primaryStep, 20))
assertEquals(100L, Step.round(primaryStep, 60))
assertEquals(500L, Step.round(primaryStep, 200))
assertEquals(1000L, Step.round(primaryStep, 600))
}

test("round: allow arbitrary number of days") {
(1 until 500).foreach { i =>
assertEquals(days(i), Step.round(60000, days(i)))
Expand Down
Loading