Github user jsoltren commented on a diff in the pull request:

    https://github.com/apache/spark/pull/14617#discussion_r106468328
  
    --- Diff: 
core/src/main/scala/org/apache/spark/storage/BlockManagerSource.scala ---
    @@ -26,35 +26,39 @@ private[spark] class BlockManagerSource(val 
blockManager: BlockManager)
       override val metricRegistry = new MetricRegistry()
       override val sourceName = "BlockManager"
     
    -  metricRegistry.register(MetricRegistry.name("memory", "maxMem_MB"), new 
Gauge[Long] {
    -    override def getValue: Long = {
    -      val storageStatusList = blockManager.master.getStorageStatus
    -      val maxMem = storageStatusList.map(_.maxMem).sum
    -      maxMem / 1024 / 1024
    -    }
    -  })
    -
    -  metricRegistry.register(MetricRegistry.name("memory", 
"remainingMem_MB"), new Gauge[Long] {
    -    override def getValue: Long = {
    -      val storageStatusList = blockManager.master.getStorageStatus
    -      val remainingMem = storageStatusList.map(_.memRemaining).sum
    -      remainingMem / 1024 / 1024
    -    }
    -  })
    -
    -  metricRegistry.register(MetricRegistry.name("memory", "memUsed_MB"), new 
Gauge[Long] {
    -    override def getValue: Long = {
    -      val storageStatusList = blockManager.master.getStorageStatus
    -      val memUsed = storageStatusList.map(_.memUsed).sum
    -      memUsed / 1024 / 1024
    -    }
    -  })
    -
    -  metricRegistry.register(MetricRegistry.name("disk", "diskSpaceUsed_MB"), 
new Gauge[Long] {
    -    override def getValue: Long = {
    -      val storageStatusList = blockManager.master.getStorageStatus
    -      val diskSpaceUsed = storageStatusList.map(_.diskUsed).sum
    -      diskSpaceUsed / 1024 / 1024
    -    }
    -  })
    +  private def registerGauge[T](name: String, f: BlockManagerMaster => T): 
Unit = {
    +    metricRegistry.register(name, new Gauge[T] {
    +      override def getValue: T = f(blockManager.master)
    +    })
    +  }
    +
    +  registerGauge(MetricRegistry.name("memory", "maxMem_MB"),
    +    _.getStorageStatus.map(_.maxMem).sum / 1024 / 1024)
    --- End diff --
    
    Not related, but this change is the right time to get rid of "/1024/1024" 
magic number arithmetic. Ideally you could just do something like 
sum.toMegabytes, which pulls the arithmetic definition somewhere else. This is 
sprinkled through enough times that I'd like to see it encapsulated in one 
place.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to