From 9c9298feef32476646185a5c68462a377ad5071f Mon Sep 17 00:00:00 2001 From: Paul Moineau Date: Wed, 11 Sep 2024 16:16:39 -0400 Subject: [PATCH] W-16656937: add graphite.prefix.withHostname --- .../main/java/com/demandware/core/config/cfgMetric.java | 5 ++++- .../src/main/java/com/demandware/core/metric/Util.java | 8 ++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/carbonj.service/src/main/java/com/demandware/core/config/cfgMetric.java b/carbonj.service/src/main/java/com/demandware/core/config/cfgMetric.java index 75485601..9b11582f 100644 --- a/carbonj.service/src/main/java/com/demandware/core/config/cfgMetric.java +++ b/carbonj.service/src/main/java/com/demandware/core/config/cfgMetric.java @@ -58,6 +58,8 @@ NameUtils nameUtils() @Value( "${graphite.prefix:}" ) private String graphitePrefix; + @Value( "${graphite.prefix.withHostname:}" ) private String graphitePrefixWithHostname; + @Value( "${dw.podId:-1}" ) private int podId; @Value( "${dw.groupId:}" ) private String groupId; @@ -82,7 +84,8 @@ NameUtils nameUtils() { GraphiteReporter graphiteReporter = Util.getGraphiteReporter( metricRegistry, graphiteHost, graphitePort, graphiteTransport, - Util.getGraphiteMetricPrefix( graphitePrefix, podId, groupId, svcVersion ) ); + Util.getGraphiteMetricPrefix( graphitePrefixWithHostname, graphitePrefix, + podId, groupId, svcVersion ) ); if ( graphiteReporter != null ) { graphiteReporter.start( 60, TimeUnit.SECONDS ); diff --git a/carbonj.service/src/main/java/com/demandware/core/metric/Util.java b/carbonj.service/src/main/java/com/demandware/core/metric/Util.java index 4c0df9cf..94ff73d6 100644 --- a/carbonj.service/src/main/java/com/demandware/core/metric/Util.java +++ b/carbonj.service/src/main/java/com/demandware/core/metric/Util.java @@ -24,8 +24,8 @@ public class Util private static GraphiteReporter graphiteReporter = null; - public static String getGraphiteMetricPrefix( String graphiteMetricsPrefix, int podId, String groupId, - String version ) + public static String getGraphiteMetricPrefix( String graphiteMetricsPrefixWithHostname, String graphiteMetricsPrefix, + int podId, String groupId, String version ) throws UnknownHostException { String fqdn = InetAddress.getLocalHost().getHostName(); @@ -36,6 +36,10 @@ public static String getGraphiteMetricPrefix( String graphiteMetricsPrefix, int graphiteMetricsPrefix = String.format( "pod%s.%s.%s.%s.%s", podId, groupId, "carbonj", hostname, version.replaceAll( "\\.", "_" )); } + else if ( !StringUtils.isEmpty(graphiteMetricsPrefixWithHostname) ) + { + graphiteMetricsPrefix = graphiteMetricsPrefixWithHostname + hostname; + } else if ( StringUtils.isEmpty( graphiteMetricsPrefix ) ) { graphiteMetricsPrefix = "um.dev.carbonj." + hostname;