You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2020/04/03 06:30:29 UTC

[GitHub] [ignite] ivandasch commented on a change in pull request #7446: IGNITE-12464 : Service metrics

ivandasch commented on a change in pull request #7446: IGNITE-12464 : Service metrics
URL: https://github.com/apache/ignite/pull/7446#discussion_r402762503
 
 

 ##########
 File path: modules/core/src/main/java/org/apache/ignite/internal/processors/metric/impl/MetricUtils.java
 ##########
 @@ -163,4 +168,66 @@ private static boolean ensureAllNamesNotEmpty(String... names) {
 
         return names;
     }
+
+    /**
+     * Abbreviates package name for metric naming purposes.
+     *
+     * @param pkgNameDepth Exhibition level of java package name. The bigger, the wider.
+     *                     Max level is {@link #MAX_ABBREVIATE_NAME_LVL}. Values:
+     *                     <pre>
+     *                         0 or negative - wont add package name;
+     *                         1 - add first and last char of each name in java package;
+     *                         2 or bigger - add full name of java package.
+     *                     </pre>
+     * @return Abbreviated name of {@code cls}.
+     */
+    public static String abbreviateName(Class<?> cls, int pkgNameDepth) {
+        if (pkgNameDepth < 1)
+            return cls.getSimpleName();
+
+        if (pkgNameDepth >= MAX_ABBREVIATE_NAME_LVL)
+            return cls.getName();
+
+        String[] pkgNameParts = cls.getName().split("\\.");
+
+        // No package like 'void' or 'int'.
+        if (pkgNameParts.length == 1)
+            return pkgNameParts[0];
+
+        StringBuilder sb = new StringBuilder();
+
+        for (int i = 0; i < pkgNameParts.length - 1; ++i) {
+            sb.append(pkgNameParts[i].charAt(0));
+
+            if (pkgNameParts[i].length() > 1)
+                sb.append(pkgNameParts[i].charAt(pkgNameParts[i].length() - 1));
+
+            sb.append(".");
+        }
+
+        // Add name to the class.
+        sb.append(pkgNameParts[pkgNameParts.length - 1]);
+
+        return sb.toString();
+    }
+
+    /**
+     * Gives proper name for service metric registry.
+     *
+     * @param srvcName Name of the service.
+     * @return registry name for service {@code srvcName}.
+     */
+    public static String serviceMetricRegistryName(String srvcName) {
+        return metricName(SERVICE_METRIC_REGISTRY, srvcName);
+    }
+
+    /**
+     * Count total of histogram values.
+     *
+     * @param histogram Histogram to traverse.
+     * @return Sum of all entries of {@code histogram} buckets.
+     */
+    public static long sumHistogramEntries(HistogramMetric histogram) {
 
 Review comment:
   What if histogram is null? I suppose we should check this.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services