Skip to content

Commit

Permalink
Moved objectives to a separate package
Browse files Browse the repository at this point in the history
  • Loading branch information
kamil-da committed May 27, 2021
1 parent cac0eea commit 5054869
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package com.daml.ledger.api.benchtool.metrics

import com.daml.ledger.api.benchtool.metrics.Metric.rounded
import com.daml.ledger.api.benchtool.metrics.objectives.ServiceLevelObjective
import com.google.protobuf.timestamp.Timestamp

import java.time.Instant
Expand Down Expand Up @@ -116,15 +117,4 @@ object ConsumptionSpeedMetric {
}
}

// TODO: add warm-up parameter
final case class MinConsumptionSpeed(minSpeed: Double) extends ServiceLevelObjective[Value] {
override def isViolatedBy(metricValue: Value): Boolean =
Ordering[Value].lt(metricValue, v)

override def formatted: String =
s"min allowed speed: $minSpeed [-]"

private val v = Value(Some(minSpeed))
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

package com.daml.ledger.api.benchtool.metrics

import com.daml.ledger.api.benchtool.metrics.objectives.ServiceLevelObjective
import com.google.protobuf.timestamp.Timestamp

import java.time.{Clock, Duration, Instant}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

package com.daml.ledger.api.benchtool.metrics

import com.daml.ledger.api.benchtool.metrics.objectives.ServiceLevelObjective

trait Metric[Elem] {

type V <: MetricValue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package com.daml.ledger.api.benchtool.metrics
import akka.actor.typed.{ActorRef, ActorSystem, Props, SpawnProtocol}
import akka.util.Timeout
import com.daml.ledger.api.benchtool.Config.StreamConfig.Objectives
import com.daml.ledger.api.benchtool.metrics.objectives.{MaxDelay, MinConsumptionSpeed}
import com.daml.ledger.api.v1.transaction_service.{
GetTransactionTreesResponse,
GetTransactionsResponse,
Expand Down Expand Up @@ -101,7 +102,7 @@ object TransactionMetrics {
val delayObjectives =
objectives.maxDelaySeconds.map(MaxDelay).toList
val consumptionSpeedObjectives =
objectives.minConsumptionSpeed.map(ConsumptionSpeedMetric.MinConsumptionSpeed).toList
objectives.minConsumptionSpeed.map(MinConsumptionSpeed).toList
List[Metric[T]](
CountMetric.empty[T](reportingPeriodMillis, countingFunction),
SizeMetric.empty[T](reportingPeriodMillis, sizingFunction),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

package com.daml.ledger.api.benchtool.metrics
package com.daml.ledger.api.benchtool.metrics.objectives

import com.daml.ledger.api.benchtool.metrics.DelayMetric

final case class MaxDelay(maxDelaySeconds: Long) extends ServiceLevelObjective[DelayMetric.Value] {
override def isViolatedBy(metricValue: DelayMetric.Value): Boolean =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

package com.daml.ledger.api.benchtool.metrics.objectives

import com.daml.ledger.api.benchtool.metrics.ConsumptionSpeedMetric

// TODO: add warm-up parameter
final case class MinConsumptionSpeed(minSpeed: Double)
extends ServiceLevelObjective[ConsumptionSpeedMetric.Value] {
override def isViolatedBy(metricValue: ConsumptionSpeedMetric.Value): Boolean =
Ordering[ConsumptionSpeedMetric.Value].lt(metricValue, v)

override def formatted: String =
s"min allowed speed: $minSpeed [-]"

private val v = ConsumptionSpeedMetric.Value(Some(minSpeed))
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

package com.daml.ledger.api.benchtool.metrics
package com.daml.ledger.api.benchtool.metrics.objectives

import com.daml.ledger.api.benchtool.metrics.MetricValue

trait ServiceLevelObjective[MetricValueType <: MetricValue] {
def isViolatedBy(metricValue: MetricValueType): Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
package com.daml.ledger.api.benchtool

import com.daml.ledger.api.benchtool.metrics.ConsumptionSpeedMetric
import com.daml.ledger.api.benchtool.metrics.objectives.MinConsumptionSpeed
import com.google.protobuf.timestamp.Timestamp
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpec

import java.time.{Clock, Instant}

import scala.language.existentials

class ConsumptionSpeedMetricSpec extends AnyWordSpec with Matchers {
Expand Down Expand Up @@ -250,7 +250,7 @@ class ConsumptionSpeedMetricSpec extends AnyWordSpec with Matchers {
)
)

val objective = ConsumptionSpeedMetric.MinConsumptionSpeed(minAllowedSpeed)
val objective = MinConsumptionSpeed(minAllowedSpeed)
val metric: ConsumptionSpeedMetric[String] =
ConsumptionSpeedMetric.empty[String](
periodMillis = periodMillis,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

package com.daml.ledger.api.benchtool

import com.daml.ledger.api.benchtool.metrics.{DelayMetric, MaxDelay}
import com.daml.ledger.api.benchtool.metrics.DelayMetric
import com.daml.ledger.api.benchtool.metrics.objectives.MaxDelay
import com.google.protobuf.timestamp.Timestamp
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpec

import java.time.{Clock, Duration, Instant, ZoneId}

import scala.language.existentials

class DelayMetricSpec extends AnyWordSpec with Matchers {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,8 @@ import akka.actor.testkit.typed.scaladsl.{
}
import akka.actor.typed.{ActorRef, Behavior}
import com.daml.ledger.api.benchtool.metrics.MetricsManager.Message
import com.daml.ledger.api.benchtool.metrics.{
Metric,
MetricValue,
MetricsManager,
ServiceLevelObjective,
}
import com.daml.ledger.api.benchtool.metrics.objectives.ServiceLevelObjective
import com.daml.ledger.api.benchtool.metrics.{Metric, MetricValue, MetricsManager}
import org.scalatest.wordspec.AnyWordSpecLike

import scala.concurrent.duration._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

package com.daml.ledger.api.benchtool

import com.daml.ledger.api.benchtool.metrics.{ConsumptionSpeedMetric, DelayMetric, MaxDelay}
import com.daml.ledger.api.benchtool.metrics.objectives.{MaxDelay, MinConsumptionSpeed}
import com.daml.ledger.api.benchtool.metrics.{ConsumptionSpeedMetric, DelayMetric}
import org.scalatest.matchers.should.Matchers
import org.scalatest.prop.TableDrivenPropertyChecks
import org.scalatest.wordspec.AnyWordSpec
Expand Down Expand Up @@ -54,7 +55,7 @@ class ServiceLevelObjectiveSpec extends AnyWordSpec with Matchers with TableDriv
"correctly report violation" in {
import ConsumptionSpeedMetric.Value
val objectiveSpeed = Random.nextDouble()
val objective = ConsumptionSpeedMetric.MinConsumptionSpeed(objectiveSpeed)
val objective = MinConsumptionSpeed(objectiveSpeed)
val lowerSpeed = objectiveSpeed - 1.0
val higherSpeed = objectiveSpeed + 1.0
val cases = Table(
Expand Down

0 comments on commit 5054869

Please sign in to comment.