-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
249 additions
and
10 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
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
45 changes: 45 additions & 0 deletions
45
rubix-common/src/main/java/com/qubole/rubix/common/metrics/CachingFileSystemMetrics.java
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,45 @@ | ||
/** | ||
* Copyright (c) 2019. Qubole Inc | ||
* 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. See accompanying LICENSE file. | ||
*/ | ||
package com.qubole.rubix.common.metrics; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public enum CachingFileSystemMetrics { | ||
LOCAL_FALLBACK_TO_DIRECT_READ("rubix_local_cache_fallback_direct_read"), | ||
NON_LOCAL_FALLBACK_TO_DIRECT_READ("rubix_non_local_cache_fallback_direct_read"), | ||
POSITIONAL_READ_FAILURE("rubix_positional_read_failure"); | ||
|
||
private final String metricName; | ||
//reverse lookup map for metric. | ||
private static final Map<String, CachingFileSystemMetrics> lookup = new HashMap<>(); | ||
|
||
CachingFileSystemMetrics(String metricName) | ||
{ | ||
this.metricName = metricName; | ||
} | ||
|
||
public String getMetricName() | ||
{ | ||
return metricName; | ||
} | ||
|
||
static { | ||
for(CachingFileSystemMetrics s : CachingFileSystemMetrics.values()) | ||
lookup.put(s.getMetricName(), s); | ||
} | ||
|
||
public static CachingFileSystemMetrics get(String enumString) { | ||
return lookup.get(enumString); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
rubix-common/src/main/java/com/qubole/rubix/common/metrics/CustomMetricsReporter.java
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,22 @@ | ||
/** | ||
* Copyright (c) 2019. Qubole Inc | ||
* 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. See accompanying LICENSE file. | ||
*/ | ||
package com.qubole.rubix.common.metrics; | ||
|
||
import java.io.Closeable; | ||
|
||
public interface CustomMetricsReporter extends Closeable { | ||
|
||
public void start(); | ||
|
||
public void addMetric(CachingFileSystemMetrics cachingFileSystemMetrics); | ||
} |
86 changes: 86 additions & 0 deletions
86
...x-common/src/main/java/com/qubole/rubix/common/metrics/CustomMetricsReporterProvider.java
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,86 @@ | ||
/** | ||
* Copyright (c) 2019. Qubole Inc | ||
* 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. See accompanying LICENSE file. | ||
*/ | ||
package com.qubole.rubix.common.metrics; | ||
|
||
import com.codahale.metrics.MetricRegistry; | ||
import com.qubole.rubix.spi.CacheConfig; | ||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
import org.apache.hadoop.conf.Configuration; | ||
|
||
import java.util.Optional; | ||
import java.util.concurrent.atomic.AtomicReference; | ||
|
||
import static com.qubole.rubix.common.utils.ClusterUtil.getMetricsReporters; | ||
|
||
public class CustomMetricsReporterProvider { | ||
private static final Log log = LogFactory.getLog(CustomMetricsReporterProvider.class); | ||
|
||
private static volatile AtomicReference<Boolean> reporterRunning = new AtomicReference<>(); | ||
|
||
private CustomMetricsReporter customMetricsReporter; | ||
private static volatile CustomMetricsReporterProvider customMetricsReporterProvider; | ||
|
||
private CustomMetricsReporterProvider(CustomMetricsReporter customMetricsReporter) { | ||
this.customMetricsReporter = customMetricsReporter; | ||
} | ||
|
||
public static void initialize(Configuration configuration) | ||
{ | ||
initialize(configuration, Optional.empty()); | ||
} | ||
|
||
public static void initialize(Configuration configuration, Optional<MetricRegistry> metricRegistry) { | ||
if (customMetricsReporterProvider == null) { | ||
synchronized (CustomMetricsReporterProvider.class) { | ||
if (customMetricsReporterProvider == null) { | ||
String className = CacheConfig.getRubixMetricCollectorImpl(configuration); | ||
// check if custom reporter is enabled: Check here for CFS metrics Reporter. | ||
boolean useCustomReporter = getMetricsReporters(configuration).contains(MetricsReporterType.CUSTOM); | ||
CustomMetricsReporter customMetricsReporter; | ||
if (useCustomReporter && !className.equals("com.qubole.rubix.common.metrics.NoOpReporter")) { | ||
try { | ||
Class collectorClass = Class.forName(className); | ||
log.info(String.format("Using class for metric reporting: %s", className)); | ||
customMetricsReporter = (CustomMetricsReporter) collectorClass.getDeclaredConstructor(Configuration.class, Optional.class) | ||
.newInstance(configuration, metricRegistry); | ||
} catch (Exception e) { | ||
log.warn("External Metric Reporter class: %s can not be initialized: ", e); | ||
customMetricsReporter = new NoOpReporter(); | ||
} | ||
} else { | ||
customMetricsReporter = new NoOpReporter(); | ||
} | ||
customMetricsReporterProvider = new CustomMetricsReporterProvider(customMetricsReporter); | ||
} | ||
} | ||
} | ||
} | ||
|
||
public static CustomMetricsReporter getCustomMetricsReporter() { | ||
if (reporterRunning.get() == null) { | ||
synchronized (reporterRunning) { | ||
if (reporterRunning.get() == null) { | ||
try { | ||
customMetricsReporterProvider.customMetricsReporter.start(); | ||
} catch (Exception e) { | ||
log.warn("Exception in starting Custom reporter: ", e); | ||
customMetricsReporterProvider.customMetricsReporter = new NoOpReporter(); | ||
} | ||
reporterRunning.set(true); | ||
} | ||
} | ||
} | ||
return customMetricsReporterProvider.customMetricsReporter; | ||
} | ||
} |
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 |
---|---|---|
|
@@ -17,5 +17,6 @@ public enum MetricsReporterType | |
{ | ||
STATSD, | ||
JMX, | ||
GANGLIA | ||
GANGLIA, | ||
CUSTOM | ||
} |
32 changes: 32 additions & 0 deletions
32
rubix-common/src/main/java/com/qubole/rubix/common/metrics/NoOpReporter.java
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,32 @@ | ||
/** | ||
* Copyright (c) 2019. Qubole Inc | ||
* 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. See accompanying LICENSE file. | ||
*/ | ||
package com.qubole.rubix.common.metrics; | ||
|
||
import java.io.IOException; | ||
|
||
public class NoOpReporter implements CustomMetricsReporter { | ||
public NoOpReporter() { | ||
} | ||
|
||
@Override | ||
public void start() { | ||
} | ||
|
||
@Override | ||
public void addMetric(CachingFileSystemMetrics cachingFileSystemMetrics) { | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
} | ||
} |
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
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
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
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
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
Oops, something went wrong.