-
Notifications
You must be signed in to change notification settings - Fork 307
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
core: fixes for sub-second step size (#1700)
Add some tests and put in some patches to address minor issues with using sub-second step sizes. There is a known issue with percentiles operator that will be addressed in a follow up PR after some updates to spectator utility classes.
- Loading branch information
1 parent
9558c35
commit 85bb3a0
Showing
5 changed files
with
187 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
atlas-core/src/test/scala/com/netflix/atlas/core/model/PerStepSuite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Copyright 2014-2024 Netflix, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.netflix.atlas.core.model | ||
|
||
import com.netflix.atlas.core.stacklang.Interpreter | ||
import munit.FunSuite | ||
|
||
import scala.language.postfixOps | ||
|
||
class PerStepSuite extends FunSuite { | ||
|
||
private val interpreter = Interpreter(MathVocabulary.allWords) | ||
|
||
def eval(str: String, step: Long, value: Double): List[TimeSeries] = { | ||
val expr = interpreter.execute(str).stack match { | ||
case (v: TimeSeriesExpr) :: _ => v | ||
case _ => throw new IllegalArgumentException("invalid expr") | ||
} | ||
val seq = new FunctionTimeSeq(DsType.Rate, step, _ => value) | ||
val input = List(LazyTimeSeries(Map("name" -> "test"), "test", seq)) | ||
val context = EvalContext(0L, step * 2, step) | ||
expr.eval(context, input).data | ||
} | ||
|
||
test("1ms step") { | ||
val step = 1L | ||
val data = eval("name,test,:eq,:sum,:per-step", step, 4.0) | ||
assertEquals(data.size, 1) | ||
assertEquals(data.head.data.apply(step), 0.004) | ||
} | ||
|
||
test("500ms step") { | ||
val step = 500L | ||
val data = eval("name,test,:eq,:sum,:per-step", step, 4.0) | ||
assertEquals(data.size, 1) | ||
assertEquals(data.head.data.apply(step), 2.0) | ||
} | ||
|
||
test("1s step") { | ||
val step = 1_000L | ||
val data = eval("name,test,:eq,:sum,:per-step", step, 4.0) | ||
assertEquals(data.size, 1) | ||
assertEquals(data.head.data.apply(step), 4.0) | ||
} | ||
|
||
test("5s step") { | ||
val step = 5_000L | ||
val data = eval("name,test,:eq,:sum,:per-step", step, 4.0) | ||
assertEquals(data.size, 1) | ||
assertEquals(data.head.data.apply(step), 20.0) | ||
} | ||
|
||
test("1m step") { | ||
val step = 60_000L | ||
val data = eval("name,test,:eq,:sum,:per-step", step, 4.0) | ||
assertEquals(data.size, 1) | ||
assertEquals(data.head.data.apply(step), 240.0) | ||
} | ||
|
||
test("10m step") { | ||
val step = 600_000L | ||
val data = eval("name,test,:eq,:sum,:per-step", step, 4.0) | ||
assertEquals(data.size, 1) | ||
assertEquals(data.head.data.apply(step), 2400.0) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters