This repository has been archived by the owner on Sep 23, 2019. It is now read-only.
forked from apache/samza
-
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.
SAMZA-850 : Yarn Job Validation Tool
- Loading branch information
1 parent
9d6831b
commit baf9faa
Showing
13 changed files
with
797 additions
and
25 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
54 changes: 54 additions & 0 deletions
54
samza-api/src/main/java/org/apache/samza/metrics/MetricsAccessor.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,54 @@ | ||
/* | ||
* 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.samza.metrics; | ||
|
||
import java.util.Map; | ||
|
||
|
||
/** | ||
* A MetricsAccessor allows users to retrieve metric values, based on group name and metric name, | ||
* though specific metrics system, such as JMX. | ||
*/ | ||
public interface MetricsAccessor { | ||
/** | ||
* Get the values of a counter | ||
* @param group Group for the counter, e.g. org.apache.samza.container.SamzaContainerMetrics | ||
* @param counter Name of the counter, e.g. commit-calls | ||
* @return A map of counter values, keyed by type, e.g. {"samza-container-0": 100L} | ||
*/ | ||
Map<String, Long> getCounterValues(String group, String counter); | ||
|
||
/** | ||
* Get the values of a gauge | ||
* @param group Group for the gauge, e.g. org.apache.samza.container.SamzaContainerMetrics | ||
* @param gauge Name of the gauge, e.g. event-loop-utilization | ||
* @param <T> Type of the gauge value, e.g. Double | ||
* @return A map of gauge values, keyed by type, e.g. {"samza-container-0": 0.8} | ||
*/ | ||
<T> Map<String, T> getGaugeValues(String group, String gauge); | ||
|
||
/** | ||
* Get the values of a timer | ||
* @param group Group for the timer, e.g. org.apache.samza.container.SamzaContainerMetrics | ||
* @param timer Name of the timer, e.g. choose-ns | ||
* @return A map of timer values, keyed by type, e.g. {"samza-container-0": 10.5} | ||
*/ | ||
Map<String, Double> getTimerValues(String group, String timer); | ||
} |
32 changes: 32 additions & 0 deletions
32
samza-api/src/main/java/org/apache/samza/metrics/MetricsValidationFailureException.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 @@ | ||
/* | ||
* 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.samza.metrics; | ||
|
||
/** | ||
* Thrown when the metrics validation fails. See {@link org.apache.samza.metrics.MetricsValidator}. | ||
*/ | ||
public class MetricsValidationFailureException extends Exception { | ||
public MetricsValidationFailureException(String message) { | ||
super(message); | ||
} | ||
public MetricsValidationFailureException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
samza-api/src/main/java/org/apache/samza/metrics/MetricsValidator.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,48 @@ | ||
/* | ||
* 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.samza.metrics; | ||
|
||
import org.apache.samza.config.Config; | ||
|
||
|
||
/** | ||
* A MetricsValidator reads the job's metrics values by using the {@link org.apache.samza.metrics.MetricsAccessor}, | ||
* and validate them. | ||
*/ | ||
public interface MetricsValidator { | ||
/** | ||
* Initialize with config. | ||
* @param config Job config | ||
*/ | ||
void init(Config config); | ||
|
||
/** | ||
* Validate the metrics values of a job | ||
* @param accessor Accessor to get the metrics values through specific metrics system, e.g. JMX. | ||
* @throws MetricsValidationFailureException Exception when the validation fails. | ||
*/ | ||
void validate(MetricsAccessor accessor) throws MetricsValidationFailureException; | ||
|
||
/** | ||
* Complete validation. Final checks can be performed here. | ||
* @throws MetricsValidationFailureException Exception when the validation fails. | ||
*/ | ||
void complete() throws MetricsValidationFailureException; | ||
} |
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
93 changes: 93 additions & 0 deletions
93
samza-core/src/main/java/org/apache/samza/metrics/JmxMetricsAccessor.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,93 @@ | ||
/* | ||
* 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.samza.metrics; | ||
|
||
import java.io.IOException; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import javax.management.MBeanServerConnection; | ||
import javax.management.ObjectName; | ||
import javax.management.remote.JMXConnector; | ||
import javax.management.remote.JMXConnectorFactory; | ||
import javax.management.remote.JMXServiceURL; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
|
||
/** | ||
* JMX metrics accessor. | ||
* It connects to a container JMX url,and get metrics values by querying the MBeans. | ||
*/ | ||
public class JmxMetricsAccessor implements MetricsAccessor { | ||
private static final Logger log = LoggerFactory.getLogger(JmxMetricsAccessor.class); | ||
|
||
private final String url; | ||
private JMXConnector jmxc; | ||
|
||
public JmxMetricsAccessor(String url) { | ||
this.url = url; | ||
} | ||
|
||
public void connect() throws IOException { | ||
JMXServiceURL jmxUrl = new JMXServiceURL(url); | ||
jmxc = JMXConnectorFactory.connect(jmxUrl, null); | ||
} | ||
|
||
public void close() throws IOException { | ||
jmxc.close(); | ||
} | ||
|
||
private <T> Map<String, T> getMetricValues(String group, String metric, String attribute) { | ||
try { | ||
StringBuilder nameBuilder = new StringBuilder(); | ||
nameBuilder.append(JmxUtil.makeNameJmxSafe(group)); | ||
nameBuilder.append(":type=*,name="); | ||
nameBuilder.append(JmxUtil.makeNameJmxSafe(metric)); | ||
ObjectName query = new ObjectName(nameBuilder.toString()); | ||
Map<String, T> values = new HashMap<>(); | ||
MBeanServerConnection conn = jmxc.getMBeanServerConnection(); | ||
for (ObjectName objName : conn.queryNames(query, null)) { | ||
String type = objName.getKeyProperty("type"); | ||
T val = (T) conn.getAttribute(objName, attribute); | ||
values.put(type, val); | ||
} | ||
return values; | ||
} catch (Exception e) { | ||
log.error(e.getMessage(), e); | ||
return Collections.EMPTY_MAP; | ||
} | ||
} | ||
|
||
@Override | ||
public Map<String, Long> getCounterValues(String group, String counter) { | ||
return getMetricValues(group, counter, "Count"); | ||
} | ||
|
||
@Override | ||
public <T> Map<String, T> getGaugeValues(String group, String gauge) { | ||
return getMetricValues(group, gauge, "Value"); | ||
} | ||
|
||
@Override | ||
public Map<String, Double> getTimerValues(String group, String timer) { | ||
return getMetricValues(group, timer, "AverageTime"); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
samza-core/src/main/java/org/apache/samza/metrics/JmxUtil.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,59 @@ | ||
/* | ||
* 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.samza.metrics; | ||
|
||
import javax.management.MalformedObjectNameException; | ||
import javax.management.ObjectName; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* Utility class to create JMX related objects | ||
*/ | ||
public class JmxUtil { | ||
private static final Logger log = LoggerFactory.getLogger(JmxUtil.class); | ||
|
||
public static ObjectName getObjectName(String group, String name, String t) throws MalformedObjectNameException { | ||
StringBuilder nameBuilder = new StringBuilder(); | ||
nameBuilder.append(makeNameJmxSafe(group)); | ||
nameBuilder.append(":type="); | ||
nameBuilder.append(makeNameJmxSafe(t)); | ||
nameBuilder.append(",name="); | ||
nameBuilder.append(makeNameJmxSafe(name)); | ||
ObjectName objName = new ObjectName(nameBuilder.toString()); | ||
log.debug("Resolved name for " + group + ", " + name + ", " + t + " to: " + objName); | ||
return objName; | ||
} | ||
|
||
/* | ||
* JMX only has ObjectName.quote, which is pretty nasty looking. This | ||
* function escapes without quoting, using the rules outlined in: | ||
* http://docs.oracle.com/javase/1.5.0/docs/api/javax/management/ObjectName.html | ||
*/ | ||
public static String makeNameJmxSafe(String str) { | ||
return str | ||
.replace(",", "_") | ||
.replace("=", "_") | ||
.replace(":", "_") | ||
.replace("\"", "_") | ||
.replace("*", "_") | ||
.replace("?", "_"); | ||
} | ||
} |
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.