Comments (7)
Wow, that's a pretty impressive finding. Thanks for that!
Also thanks for the 2 suggestions. I'll have to think about which one I prefer. @skullxbones, do you have a preference?
from metrics-scala.
I learned something today, thank you! I didn't realize that by value and implicit interacted this way.
Let me write up that failing test case. Probably making the signature Unit => A is the way to go since it's less magical and more explicit.
from metrics-scala.
This issue is related: https://issues.scala-lang.org/browse/SI-3237.
from metrics-scala.
FWIW, I think changing the signature of healthCheck
to specify by-name semantics is the obvious minimal change. Otherwise, you wouldn't expect this to work either:
@Test def explicit(): Unit = {
var count = 0
var checker = false
val res = healthCheck("bool test","nope") {
count += 1
new HealthCheckMagnet {
def apply(unhealthyMessage: String) = () => if (checker) "OK" else unhealthyMessage
}
}
assertEquals("nope", res())
checker = true
assertEquals("OK", res())
assertEquals(2, count)
}
Here is the minimization I was working with.
import language._
package object health {
type HealthCheck = () => String
def healthCheck(name: String, unhealthyMessage: String = "Health check failed")(checker: =>HealthCheckMagnet): HealthCheck = {
() => checker(unhealthyMessage)()
}
}
package health {
/*sealed*/ trait HealthCheckMagnet {
def apply(unhealthyMessage: String): HealthCheck
}
object HealthCheckMagnet {
/** Magnet for checkers returning a [[scala.Boolean]] (possibly implicitly converted). */
implicit def fromBooleanCheck[A <% Boolean](checker: => A) = new HealthCheckMagnet {
def apply(unhealthyMessage: String) = () => if (checker) "OK" else unhealthyMessage
}
}
}
with test
@Test def bools(): Unit = {
var count = 0
val res = healthCheck("bool test","nope") {
count += 1
false
}
assertEquals("nope", res())
assertEquals("nope", res())
assertEquals(2, count)
}
The other difference may be that healthCheck
is not invoking checker immediately.
Frankly, I'm confused by the checkers and checks, and I lost my scorecard. And am I the only one who keeps thinking "chick magnet"?
from metrics-scala.
I am rather to old to be a chick magnet, but it sound great nonetheless!
Thanks for the idea of making the parameter by-name also. Your prototype should be very easy to integrate. Am I right that this will break binary compatibility (but keep source compatibility)?
from metrics-scala.
There is an interesting twist you didn't consider. The (java) class HealthCheck comes from metrics-core and we can't just redefine that.
from metrics-scala.
Anyway, just declaring the checker as by name was sufficient. Thanks!
from metrics-scala.
Related Issues (20)
- Add support for Akka Streams HOT 3
- Version for Scala 2.13.0-RC1 HOT 2
- Scala 2.13.0-RC2 HOT 4
- Releasing with sbt fails due to double uploads HOT 1
- Version for Scala 2.13.0 HOT 1
- MetricName.append breaks in v4 HOT 6
- Spark: Exception in thread "main" java.lang.NoSuchMethodError: com.codahale.metrics.MetricRegistry.timer(Ljava/lang/String;Lcom/codahale/metrics/MetricRegistry$MetricSupplier;)Lcom/codahale/metrics/Timer; HOT 5
- Memory leak on re-registering gauges HOT 11
- Using cachedGauge with Futures HOT 1
- Improve compatibility checks HOT 1
- Scala 3 HOT 6
- Create github release HOT 1
- Make constructors of PushGauge and PushGaugeWithTimeout not private HOT 2
- PushGauge should not throw "A metric named foobar already exists " HOT 2
- Plans for "metrics4-pekko" HOT 1
- support for the new pekko open source akka HOT 1
- Scala/Akka/Dropwizard Metrics app hanging for 10s before shutting down HOT 1
- Version Request: 3.5.9_a2.3 (with akka 2.4.19), or 3.5.9_a2.4 (against Scala 2.11) HOT 1
- Wrong artifact name in Wiki HOT 1
- Upgrade to metrics 5 HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from metrics-scala.