Skip to content

Commit

Permalink
style: spotless corrections
Browse files Browse the repository at this point in the history
SXT-904

Signed-off-by: Kevin O'Donnell <kevin@blockchaintp.com>
  • Loading branch information
scealiontach committed Aug 16, 2022
1 parent 4add59a commit fc7c2b6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 19 deletions.
4 changes: 2 additions & 2 deletions qldb/src/main/scala/com/blockchaintp/daml/qldb/Main.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 Blockchain Technology Partners
* Copyright 2021-2022 Blockchain Technology Partners
*
* 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
Expand Down Expand Up @@ -307,7 +307,7 @@ class LedgerFactory(

Metrics.metricsReporterParse(parser)(
(f, c) => c.copy(metricsReporter = f(c.metricsReporter)),
(f, c) => c.copy(metricsReportingInterval = (Duration.ofNanos(c.metricsReportingInterval.toNanos))),
(f, c) => c.copy(metricsReportingInterval = (Duration.ofNanos(c.metricsReportingInterval.toNanos)))
)

()
Expand Down
47 changes: 30 additions & 17 deletions qldb/src/main/scala/com/blockchaintp/daml/qldb/Metrics.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
/*
* Copyright 2022 Blockchain Technology Partners
*
* 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.blockchaintp.daml.qldb

import com.daml.platform.configuration.MetricsReporter

import scala.concurrent.duration.{Duration, NANOSECONDS}
import scala.concurrent.duration.Duration
import scala.concurrent.duration.NANOSECONDS
import scala.util.Try

object Metrics {
Expand All @@ -11,26 +25,25 @@ object Metrics {

// We're trying to parse the java duration first for backwards compatibility as
// removing it and only supporting the scala duration variant would be a breaking change.
private implicit val scoptDurationFormat: scopt.Read[DurationFormat] = scopt.Read.reads {
duration =>
implicit private val scoptDurationFormat: scopt.Read[DurationFormat] = scopt.Read.reads { duration =>
Try {
Duration.fromNanos(
java.time.Duration.parse(duration).toNanos
)
}.orElse(Try {
Duration(duration)
}).flatMap(duration =>
Try {
Duration.fromNanos(
java.time.Duration.parse(duration).toNanos
)
}.orElse(Try {
Duration(duration)
}).flatMap(duration =>
Try {
if (!duration.isFinite)
throw new IllegalArgumentException(s"Input duration $duration is not finite")
else DurationFormat(Duration(duration.toNanos, NANOSECONDS))
}
).get
if (!duration.isFinite)
throw new IllegalArgumentException(s"Input duration $duration is not finite")
else DurationFormat(Duration(duration.toNanos, NANOSECONDS))
}
).get
}

def metricsReporterParse[C](parser: scopt.OptionParser[C])(
metricsReporter: Setter[C, Option[MetricsReporter]],
metricsReportingInterval: Setter[C, Duration],
metricsReporter: Setter[C, Option[MetricsReporter]],
metricsReportingInterval: Setter[C, Duration]
): Unit = {
import parser.opt

Expand Down

0 comments on commit fc7c2b6

Please sign in to comment.