Skip to content

Commit

Permalink
util-stats: more support for creating a Stat expression
Browse files Browse the repository at this point in the history
**Problem/Solution**
Move `HistogramComponent` to its own class

**Problem/Solution**
Provide default percentiles in `HistogramComponent`

**Problem**
Percentile is not a component of `HistogramComponent`,  to create a
Stat expression, users need to pass either a `HistogramComponent`
or a percentile as `Double`.

**Solution**
Introduce `Percentile` as a new `HistogramComponent` and refactor
the API to create a Stat expression to take a `HistogramComponent`.
This makes it easier for us to introduce a new API to create a list of
Stat expressions with different `HistogramComponent` (will be done
in a separate phab).

JIRA Issues: CSL-11828

Differential Revision: https://phabricator.twitter.biz/D855103
  • Loading branch information
jyanJing authored and jenkins committed Mar 25, 2022
1 parent 9cd4550 commit 3554dff
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.twitter.finagle.stats.exp.Expression
import com.twitter.finagle.stats.exp.ExpressionSchema
import com.twitter.finagle.stats.exp.ExpressionSchemaKey
import com.twitter.finagle.stats.exp.GreaterThan
import com.twitter.finagle.stats.exp.HistogramComponent
import com.twitter.finagle.stats.exp.MonotoneThresholds
import com.twitter.finagle.stats.InMemoryStatsReceiver
import com.twitter.finagle.stats.MetricBuilder
Expand Down Expand Up @@ -47,7 +48,8 @@ class MetricExpressionHandlerTest extends AnyFunSuite {
.withNamespace("path", "to", "tenantName")

val latencyP99 =
ExpressionSchema("latency_p99", Expression(latencyMb, Right(0.99))).withNamespace("tenantName")
ExpressionSchema("latency_p99", Expression(latencyMb, HistogramComponent.Percentile(0.99)))
.withNamespace("tenantName")

val failureExpression =
ExpressionSchema("failures", Expression(failuresMb, true))
Expand Down Expand Up @@ -276,7 +278,7 @@ class MetricExpressionHandlerTest extends AnyFunSuite {

test("translate histogram expressions - components") {

val latencyMin = ExpressionSchema("min", Expression(latencyMb, Left(Expression.Min)))
val latencyMin = ExpressionSchema("min", Expression(latencyMb, HistogramComponent.Min))
val min = MetricExpressionHandler.translateToQuery(
latencyMin.expr,
shouldRate = false,
Expand Down

0 comments on commit 3554dff

Please sign in to comment.