Skip to content
This repository has been archived by the owner on Jul 11, 2022. It is now read-only.

Commit

Permalink
Merge pull request #19 from lzoubek/bugs/1072543
Browse files Browse the repository at this point in the history
[BZ 1072543] Unable to collect metrics from EAP 6 datasources when a system properties is used in configuration
  • Loading branch information
metlos committed Apr 22, 2014
2 parents 769bb64 + e86ac44 commit 4edaa3b
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,79 +176,94 @@ public BaseServerComponent getServerComponent() {
public void getValues(MeasurementReport report, Set<MeasurementScheduleRequest> metrics) throws Exception {

for (MeasurementScheduleRequest req : metrics) {
getMetricValue(report, req, null);
}
}

if (req.getName().startsWith(INTERNAL))
processPluginStats(req, report);
else {
// Metrics from the application server
/**
* gets metric value for given request
* @param report
* @param req
* @param explicitExpressions set of metric names that could be represented by expression instead of value on AS7 (can be null)
* @return ReadMetricResult value that if different from 'Success' determines why we failed to read metric
*/
protected ReadMetricResult getMetricValue(MeasurementReport report, MeasurementScheduleRequest req, Set<String> explicitExpressions) {
if (req.getName().startsWith(INTERNAL))
processPluginStats(req, report);
else {
// Metrics from the application server

String reqName = req.getName();
boolean resolveExpression = false;
if (reqName.startsWith(EXPRESSION)) {
resolveExpression = true;
reqName = reqName.substring(EXPRESSION_SIZE);
} else if (explicitExpressions!=null && explicitExpressions.contains(reqName)) {
resolveExpression = true;
}

String reqName = req.getName();
boolean resolveExpression = false;
if (reqName.startsWith(EXPRESSION)) {
resolveExpression = true;
reqName = reqName.substring(EXPRESSION_SIZE);
}
ComplexRequest complexRequest = null;
Operation op;
if (reqName.contains(":")) {
complexRequest = ComplexRequest.create(reqName);
op = new ReadAttribute(address, complexRequest.getProp());
} else {
op = new ReadAttribute(address, reqName); // TODO batching
}

ComplexRequest complexRequest = null;
Operation op;
if (reqName.contains(":")) {
complexRequest = ComplexRequest.create(reqName);
op = new ReadAttribute(address, complexRequest.getProp());
} else {
op = new ReadAttribute(address, reqName); // TODO batching
}
Result res = getASConnection().execute(op);
if (!res.isSuccess()) {
getLog().warn("Getting metric [" + req.getName() + "] at [ " + address + "] failed: "
+ res.getFailureDescription());
return ReadMetricResult.RequestFailed;
}

Result res = getASConnection().execute(op);
if (!res.isSuccess()) {
getLog().warn("Getting metric [" + req.getName() + "] at [ " + address + "] failed: "
+ res.getFailureDescription());
continue;
}
Object val = res.getResult();
if (val == null) // One of the AS7 ways of telling "This is not implemented" See also AS7-1454
return ReadMetricResult.Null;

Object val = res.getResult();
if (val == null) // One of the AS7 ways of telling "This is not implemented" See also AS7-1454
continue;

if (req.getDataType() == DataType.MEASUREMENT) {
if (val instanceof String && ((String) val).startsWith("JBAS018003")) // AS7 way of saying "no value available"
continue;
try {
if (complexRequest != null) {
HashMap<String, Number> myValues = (HashMap<String, Number>) val;
for (String key : myValues.keySet()) {
String sub = complexRequest.getSub();
if (key.equals(sub)) {
addMetric2Report(report, req, myValues.get(key), resolveExpression);
}
if (req.getDataType() == DataType.MEASUREMENT) {
if (val instanceof String && ((String) val).startsWith("JBAS018003")) // AS7 way of saying "no value available"
return ReadMetricResult.Null;
try {
if (complexRequest != null) {
HashMap<String, Number> myValues = (HashMap<String, Number>) val;
for (String key : myValues.keySet()) {
String sub = complexRequest.getSub();
if (key.equals(sub)) {
addMetric2Report(report, req, myValues.get(key), resolveExpression);
}
} else {
addMetric2Report(report, req, val, resolveExpression);
}
} catch (NumberFormatException e) {
getLog().warn("Non numeric input for [" + req.getName() + "] : [" + val + "]");
} else {
addMetric2Report(report, req, val, resolveExpression);
}
} else if (req.getDataType() == DataType.TRAIT) {

if (resolveExpression && val instanceof Map && ((Map) val).containsKey(EXPRESSION_VALUE_KEY)) {
String expression = (String) ((Map) val).get(EXPRESSION_VALUE_KEY);
ResolveExpression resolveExpressionOperation = new ResolveExpression(expression);
Result result = getASConnection().execute(resolveExpressionOperation);
if (!result.isSuccess()) {
if (getLog().isWarnEnabled()) {
getLog().warn("Skipping trait [" + req.getName()
+ "] in measurement report. Could not resolve expression [" + expression
+ "], failureDescription:" + result.getFailureDescription());
continue;
}
} catch (NumberFormatException e) {
getLog().warn("Non numeric input for [" + req.getName() + "] : [" + val + "]");
return ReadMetricResult.ResolveFailed;
}
} else if (req.getDataType() == DataType.TRAIT) {

if (resolveExpression && val instanceof Map && ((Map) val).containsKey(EXPRESSION_VALUE_KEY)) {
String expression = (String) ((Map) val).get(EXPRESSION_VALUE_KEY);
ResolveExpression resolveExpressionOperation = new ResolveExpression(expression);
Result result = getASConnection().execute(resolveExpressionOperation);
if (!result.isSuccess()) {
if (getLog().isWarnEnabled()) {
getLog().warn("Skipping trait [" + req.getName()
+ "] in measurement report. Could not resolve expression [" + expression
+ "], failureDescription:" + result.getFailureDescription());
return ReadMetricResult.ResolveFailed;
}
val = result.getResult();
}

MeasurementDataTrait data = new MeasurementDataTrait(req, getStringValue(val));
report.addData(data);
val = result.getResult();
}

MeasurementDataTrait data = new MeasurementDataTrait(req, getStringValue(val));
report.addData(data);
}
}
return ReadMetricResult.Success;

}

private void addMetric2Report(MeasurementReport report, MeasurementScheduleRequest req, Object val,
Expand Down Expand Up @@ -913,6 +928,10 @@ protected void collectMulticastAddressTrait(MeasurementReport report, Measuremen
}
}

static enum ReadMetricResult {
Success, RequestFailed, Null, ResolveFailed
}

private static class ComplexRequest {
private String prop;
private String sub;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import static java.lang.Boolean.FALSE;
import static java.lang.Boolean.TRUE;

import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -75,6 +77,10 @@ public class DatasourceComponent extends BaseComponent<BaseComponent<?>> impleme
private static final String DISABLE_OPERATION = "disable";
private static final String ALLOW_MULTIPLE_USERS_ATTRIBUTE = "allow-multiple-users";
private static final String TRACK_STATEMENTS_ATTRIBUTE = "track-statements";
/**
* list of metrics where we can expect expresion value instead of just number (such expression has to be resolved)
*/
private static final Set<String> expressionMetrics = Collections.unmodifiableSet(new HashSet<String>(Arrays.asList("max-pool-size","min-pool-size")));

@Override
public OperationResult invokeOperation(String operationName, Configuration parameters) throws Exception { // TODO still needed ? Check with plugin descriptor
Expand Down Expand Up @@ -397,25 +403,17 @@ private void doUpdateAS7ResourceConfiguration(ConfigurationUpdateReport configur
}

private void getRCAsMetric(MeasurementReport report, MeasurementScheduleRequest request) {
Operation op = new ReadAttribute(getAddress(), request.getName());
Result res = getASConnection().execute(op);
ReadMetricResult result = getMetricValue(report, request, expressionMetrics);

if (result.equals(ReadMetricResult.Null)) { // server
Double val = Double.valueOf(-1);
if (request.getName().equals("max-pool-size"))
val = Double.valueOf(20); // The default value
else if (request.getName().equals("min-pool-size"))
val = Double.valueOf(0); // The default value

if (res.isSuccess()) {
Integer tmp = (Integer) res.getResult();
if (tmp == null) { // server
if (request.getName().equals("max-pool-size"))
tmp = 20; // The default value
else if (request.getName().equals("min-pool-size"))
tmp = 0; // The default value
else
tmp = -1; // Fallback for unknown requests
}
Double val = Double.valueOf(tmp);
MeasurementDataNumeric data = new MeasurementDataNumeric(request, val);
report.addData(data);
} else {
LOG.warn("Could not read [" + request.getName() + "] on " + getAddress() + ": "
+ res.getFailureDescription());
}
}

Expand Down

0 comments on commit 4edaa3b

Please sign in to comment.