Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
Signed-off-by: Rafael Vasquez <raf.vasquez@ibm.com>
  • Loading branch information
rafvasq committed Feb 8, 2023
1 parent ff0d30e commit 614dbe5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
6 changes: 3 additions & 3 deletions src/main/java/com/ibm/watson/modelmesh/Metrics.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public PrometheusMetrics(Map<String, String> params) throws Exception {
int port = 2112;
boolean shortNames = true;
boolean https = true;
boolean custom = false;
boolean customMetrics = false;
String memMetrics = "all"; // default to all
for (Entry<String, String> ent : params.entrySet()) {
switch (ent.getKey()) {
Expand All @@ -185,7 +185,7 @@ public PrometheusMetrics(Map<String, String> params) throws Exception {
memMetrics = ent.getValue();
break;
case "metric_name":
custom = true;
customMetrics = true;
break;
default:
throw new Exception("Unrecognized metrics config parameter: " + ent.getKey());
Expand Down Expand Up @@ -235,7 +235,7 @@ public PrometheusMetrics(Map<String, String> params) throws Exception {
}

// Custom info metrics
if (custom){
if (customMetrics){
@SuppressWarnings("rawtypes")
SimpleCollector.Builder builder;
builder = Gauge.build();
Expand Down
28 changes: 13 additions & 15 deletions src/main/java/com/ibm/watson/modelmesh/ModelMesh.java
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,6 @@ private static Metrics setUpMetrics() throws Exception {
logger.warn("MM_METRICS_STATSD_PORT and MM_METRICS_PROMETHEUS_PORT env variables are deprecated"
+ " and have no effect, use " + MMESH_METRICS_ENV_VAR + " instead");
}

String metricsConfig = getStringParameter(MMESH_METRICS_ENV_VAR, null);
if (metricsConfig == null) {
logger.info("{} env var not set, defaulting to emit Sysdig StatsD metrics to port 8126",
Expand All @@ -901,27 +900,14 @@ private static Metrics setUpMetrics() throws Exception {
} else {
logger.info("{} set to \"{}\"", MMESH_METRICS_ENV_VAR, metricsConfig);
}
String customMetricConfig = getStringParameter(MMESH_CUSTOM_ENV_VAR, null);
if (customMetricConfig == null) {
logger.info("{} returned null", MMESH_CUSTOM_ENV_VAR);
} else {
logger.info("{} set to \"{}\"", MMESH_CUSTOM_ENV_VAR, customMetricConfig);
}

Matcher matcher = METRICS_CONFIG_PATT.matcher(metricsConfig);
if (!matcher.matches()) {
throw new Exception("Invalid metrics configuration provided in env var " + MMESH_METRICS_ENV_VAR + ": \""
+ metricsConfig + "\"");
}
Matcher customMetricMatcher = CUSTOM_METRIC_CONFIG_PATT.matcher(customMetricConfig);
if (!customMetricMatcher.matches()) {
throw new Exception("Invalid metrics configuration provided in env var " + MMESH_CUSTOM_ENV_VAR + ": \""
+ customMetricConfig + "\"");
}
String type = matcher.group(1);
String paramString = matcher.group(2);
String name = customMetricMatcher.group(1);
String customParamString = customMetricMatcher.group(2);
Map<String, String> params;
if (paramString == null) {
params = Collections.emptyMap();
Expand All @@ -931,7 +917,19 @@ private static Metrics setUpMetrics() throws Exception {
String[] kv = parm.split("=");
params.put(kv[0], kv[1]);
}

}
String customMetricConfig = getStringParameter(MMESH_CUSTOM_ENV_VAR, null);
if (customMetricConfig == null) {
logger.info("{} returned null", MMESH_CUSTOM_ENV_VAR);
} else {
logger.info("{} set to \"{}\"", MMESH_CUSTOM_ENV_VAR, customMetricConfig);
Matcher customMetricMatcher = CUSTOM_METRIC_CONFIG_PATT.matcher(customMetricConfig);
if (!customMetricMatcher.matches()) {
throw new Exception("Invalid metrics configuration provided in env var " + MMESH_CUSTOM_ENV_VAR + ": \""
+ customMetricConfig + "\"");
}
String name = customMetricMatcher.group(1);
String customParamString = customMetricMatcher.group(2);
params.put("metric_name", name);
for (String customParm : customParamString.substring(1).split(",")) {
String[] kv = customParm.split("=");
Expand Down

0 comments on commit 614dbe5

Please sign in to comment.