forked from apache/spark
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Spark-5708] Add Slf4jSink to Spark Metrics
Add Slf4jSink to Spark Metrics using Coda Hale's SlfjReporter. This sends metrics to log4j, allowing spark users to reuse log4j pipeline for metrics collection. Reviewed existing unit tests and didn't see any sink-related tests. Please advise on if tests should be added. Author: Judy <judynash@microsoft.com> Author: judynash <judynash@microsoft.com> Closes apache#4644 from judynash/master and squashes the following commits: 57ef214 [judynash] doc clarification and indent fixes a751a66 [Judy] Spark-5708: Add Slf4jSink to Spark Metrics
- Loading branch information
Showing
3 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
core/src/main/scala/org/apache/spark/metrics/sink/Slf4jSink.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 org.apache.spark.metrics.sink | ||
|
||
import java.util.Properties | ||
import java.util.concurrent.TimeUnit | ||
|
||
import com.codahale.metrics.{Slf4jReporter, MetricRegistry} | ||
|
||
import org.apache.spark.SecurityManager | ||
import org.apache.spark.metrics.MetricsSystem | ||
|
||
private[spark] class Slf4jSink( | ||
val property: Properties, | ||
val registry: MetricRegistry, | ||
securityMgr: SecurityManager) | ||
extends Sink { | ||
val SLF4J_DEFAULT_PERIOD = 10 | ||
val SLF4J_DEFAULT_UNIT = "SECONDS" | ||
|
||
val SLF4J_KEY_PERIOD = "period" | ||
val SLF4J_KEY_UNIT = "unit" | ||
|
||
val pollPeriod = Option(property.getProperty(SLF4J_KEY_PERIOD)) match { | ||
case Some(s) => s.toInt | ||
case None => SLF4J_DEFAULT_PERIOD | ||
} | ||
|
||
val pollUnit: TimeUnit = Option(property.getProperty(SLF4J_KEY_UNIT)) match { | ||
case Some(s) => TimeUnit.valueOf(s.toUpperCase()) | ||
case None => TimeUnit.valueOf(SLF4J_DEFAULT_UNIT) | ||
} | ||
|
||
MetricsSystem.checkMinimalPollingPeriod(pollUnit, pollPeriod) | ||
|
||
val reporter: Slf4jReporter = Slf4jReporter.forRegistry(registry) | ||
.convertDurationsTo(TimeUnit.MILLISECONDS) | ||
.convertRatesTo(TimeUnit.SECONDS) | ||
.build() | ||
|
||
override def start() { | ||
reporter.start(pollPeriod, pollUnit) | ||
} | ||
|
||
override def stop() { | ||
reporter.stop() | ||
} | ||
|
||
override def report() { | ||
reporter.report() | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters