From 614dbe5149f49eb6ca241b24712676093c4ed778 Mon Sep 17 00:00:00 2001 From: Rafael Vasquez Date: Wed, 8 Feb 2023 17:32:26 -0500 Subject: [PATCH] update Signed-off-by: Rafael Vasquez --- .../com/ibm/watson/modelmesh/Metrics.java | 6 ++-- .../com/ibm/watson/modelmesh/ModelMesh.java | 28 +++++++++---------- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/ibm/watson/modelmesh/Metrics.java b/src/main/java/com/ibm/watson/modelmesh/Metrics.java index a87e71523..a9895a958 100644 --- a/src/main/java/com/ibm/watson/modelmesh/Metrics.java +++ b/src/main/java/com/ibm/watson/modelmesh/Metrics.java @@ -159,7 +159,7 @@ public PrometheusMetrics(Map 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 ent : params.entrySet()) { switch (ent.getKey()) { @@ -185,7 +185,7 @@ public PrometheusMetrics(Map 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()); @@ -235,7 +235,7 @@ public PrometheusMetrics(Map params) throws Exception { } // Custom info metrics - if (custom){ + if (customMetrics){ @SuppressWarnings("rawtypes") SimpleCollector.Builder builder; builder = Gauge.build(); diff --git a/src/main/java/com/ibm/watson/modelmesh/ModelMesh.java b/src/main/java/com/ibm/watson/modelmesh/ModelMesh.java index 8a88c8ea2..aa720709c 100644 --- a/src/main/java/com/ibm/watson/modelmesh/ModelMesh.java +++ b/src/main/java/com/ibm/watson/modelmesh/ModelMesh.java @@ -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", @@ -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 params; if (paramString == null) { params = Collections.emptyMap(); @@ -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("=");