Skip to content

Commit

Permalink
Disable false positives for StoreGaugesAsMemberVariables lint rule
Browse files Browse the repository at this point in the history
Problem

We have a new scalafix lint rule, StoreGaugesAsMemberVariables, that
flags cases where Gauges are not stored in member variables.

However, because it is a syntactic rule, it sometimes flags some false
positives.

Solution

Disable the rule where appropriate.

JIRA Issues: CSL-6746

TBR=true

Differential Revision: https://phabricator.twitter.biz/D214652
  • Loading branch information
kevinoliver authored and jenkins committed Sep 17, 2018
1 parent f715113 commit 11b7905
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
Expand Up @@ -33,12 +33,14 @@ private[http2] object ServerCodec {
http2MultiplexCodec: Http2MultiplexCodec,
channel: Channel
): Unit = {
// scalafix:off StoreGaugesAsMemberVariables
val streams = statsReceiver.addGauge("streams") {
// Note that this isn't thread-safe because the session state is intended to be
// single-threaded and used only from within the channel, but addressing that
// would be very challenging.
http2MultiplexCodec.connection.numActiveStreams
}
// scalafix:on StoreGaugesAsMemberVariables

// We're attaching a gauge to the channel's attributes to make sure it stays referenced
// as long as channel is alive.
Expand Down
Expand Up @@ -54,6 +54,7 @@ private[serverset2] object HealthStabilizer {

val currentStatus = new AtomicReference[Status]()
val gaugeListener = stateChanges.dedup.register(Witness { currentStatus })
// scalafix:off StoreGaugesAsMemberVariables
val gauge = statsReceiver.addGauge("zkHealth") {
currentStatus.get() match {
case Unknown => 0
Expand All @@ -62,6 +63,7 @@ private[serverset2] object HealthStabilizer {
case Probation(_) => 3
}
}
// scalafix:on StoreGaugesAsMemberVariables

val notify = stateChanges
.collect {
Expand Down
Expand Up @@ -10,7 +10,7 @@ class MetricsStatsReceiverTest extends FunSuite {

private[this] def readGaugeInRoot(name: String) = readGauge(rootReceiver, name)
private[this] def readCounterInRoot(name: String) = rootReceiver.registry.counters.get(name)

// scalafix:off StoreGaugesAsMemberVariables
test("MetricsStatsReceiver should store and read gauge into the root StatsReceiver") {
val x = 1.5f
// gauges are weakly referenced by the registry so we need to keep a strong reference
Expand Down Expand Up @@ -134,4 +134,5 @@ class MetricsStatsReceiverTest extends FunSuite {
assert(metrics1.histograms.containsKey("baz"))
assert(metrics2.histograms.containsKey("baz"))
}
// scalafix:on StoreGaugesAsMemberVariables
}

0 comments on commit 11b7905

Please sign in to comment.