Skip to content

Commit

Permalink
fix: Avoid string concat and regex inefficiency (#117)
Browse files Browse the repository at this point in the history
- Execute external commands using an array of strings
  rather than a single string
- Make the regular expression pattern a bit more efficient

---------

Signed-off-by: Rafael Vasquez <[email protected]>
  • Loading branch information
rafvasq authored Nov 14, 2023
1 parent c3f018f commit 8b36883
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/ibm/watson/modelmesh/ModelMesh.java
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,7 @@ protected final TProcessor initialize() throws Exception {
// "type" or "type:p1=v1;p2=v2;...;pn=vn"
private static final Pattern METRICS_CONFIG_PATT = Pattern.compile("([a-z;]+)(:\\w+=[^;]+(?:;\\w+=[^;]+)*)?");
// "metric_name" or "metric:name;l1=v1,l2=v2,...,ln=vn,"
private static final Pattern CUSTOM_METRIC_CONFIG_PATT = Pattern.compile("([a-z_:]+);(\\w+=[^;]+(?:;\\w+=[^,]+)*)?");
private static final Pattern CUSTOM_METRIC_CONFIG_PATT = Pattern.compile("([a-z_:]+);(\\w+=[^;]+(?:;\\w+=[^,]++)*)?");

private static Metrics setUpMetrics() throws Exception {
if (System.getenv("MM_METRICS_STATSD_PORT") != null || System.getenv("MM_METRICS_PROMETHEUS_PORT") != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ public static int getPID(Process process) throws Exception {
}

public static int killProcess(Process process) throws Exception {
int pid = getPID(process);
return Runtime.getRuntime().exec("kill -9 " + pid).waitFor();
String pid = Integer.toString(getPID(process));
return Runtime.getRuntime().exec(new String[] {"kill", "-9", pid}).waitFor();
}
}

0 comments on commit 8b36883

Please sign in to comment.