This is an automated email from the ASF dual-hosted git repository.

yihaochen pushed a commit to branch fix-endpoint-grouping
in repository https://gitbox.apache.org/repos/asf/skywalking.git


The following commit(s) were added to refs/heads/fix-endpoint-grouping by this 
push:
     new 034b0ed2dc Fix NPE and IllegalArgument in AI-based formatting
034b0ed2dc is described below

commit 034b0ed2dc11b118a05c2b477c480329b6e2e576
Author: Superskyyy <supersk...@outlook.com>
AuthorDate: Tue Jun 20 17:59:12 2023 -0400

    Fix NPE and IllegalArgument in AI-based formatting
---
 .../core/config/group/EndpointNameGrouping.java      | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git 
a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/config/group/EndpointNameGrouping.java
 
b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/config/group/EndpointNameGrouping.java
index a2c1bc8e0d..158551364e 100644
--- 
a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/config/group/EndpointNameGrouping.java
+++ 
b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/config/group/EndpointNameGrouping.java
@@ -90,26 +90,24 @@ public class EndpointNameGrouping {
         if (!formattedName._2() && quickUriGroupingRule != null) {
             formattedName = formatByQuickUriPattern(serviceName, endpointName);
 
-            ConcurrentHashMap<String, ArrayBlockingQueue<String>> svrHttpUris 
= cachedHttpUris.get(serviceName);
-            if (svrHttpUris == null) {
-                cachedHttpUris.putIfAbsent(serviceName, new 
ConcurrentHashMap<>());
-                svrHttpUris = cachedHttpUris.get(serviceName);
-            }
-            // Only cache first N(determined by maxHttpUrisNumberPerService) 
URIs per 30 mins.
+            ConcurrentHashMap<String, ArrayBlockingQueue<String>> svrHttpUris =
+                    cachedHttpUris.computeIfAbsent(serviceName, _ -> new 
ConcurrentHashMap<>());
+
+            // Only cache first N (determined by maxHttpUrisNumberPerService) 
URIs per 30 mins.
             if (svrHttpUris.size() < maxHttpUrisNumberPerService) {
                 if (formattedName._2()) {
+                    // Algorithm side should not return a pattern that has no 
{var} in it else this
+                    // code may accidentally retreive the size 1 queue created 
by unformatted endpoint
                     // The queue size is 10, which means only cache the first 
10 formatted names.
-                    final ArrayBlockingQueue<String> formattedURIs = 
svrHttpUris.putIfAbsent(
-                        formattedName._1(), new ArrayBlockingQueue<>(10));
+                    ArrayBlockingQueue<String> formattedURIs = 
svrHttpUris.computeIfAbsent(
+                            formattedName._1(), _ -> new 
ArrayBlockingQueue<>(10));
                     if (formattedURIs.size() < 10) {
                         // Try to push the raw URI as a candidate of formatted 
name.
                         formattedURIs.offer(endpointName);
                     }
                 } else {
-                    svrHttpUris.putIfAbsent(
-                        formattedName._1(), new ArrayBlockingQueue<>(0));
+                    svrHttpUris.computeIfAbsent(endpointName, _ -> new 
ArrayBlockingQueue<>(1));
                 }
-
             }
         }
 

Reply via email to