From 0e425e26bcacb84b0c497222a67adfa5157e5fce Mon Sep 17 00:00:00 2001
From: vinodhabib <vinodhabib@gmail.com>
Date: Fri, 21 Feb 2025 15:44:58 +0000
Subject: [PATCH 1/7] core: added changes to make service config more explicit
 by logging required info

---
 .../io/grpc/internal/ManagedChannelImpl.java  |  6 ++++
 .../internal/ManagedChannelServiceConfig.java |  7 +++++
 .../grpc/internal/ManagedChannelImplTest.java | 28 +++++++++----------
 3 files changed, 27 insertions(+), 14 deletions(-)

diff --git a/core/src/main/java/io/grpc/internal/ManagedChannelImpl.java b/core/src/main/java/io/grpc/internal/ManagedChannelImpl.java
index 45819954473..aec23b0fa86 100644
--- a/core/src/main/java/io/grpc/internal/ManagedChannelImpl.java
+++ b/core/src/main/java/io/grpc/internal/ManagedChannelImpl.java
@@ -151,6 +151,10 @@ final class ManagedChannelImpl extends ManagedChannel implements
         public Result selectConfig(PickSubchannelArgs args) {
           throw new IllegalStateException("Resolution is pending");
         }
+        @Override
+        public String toString() {
+          return "Resolution is pending";
+        }
       };
   private static final LoadBalancer.PickDetailsConsumer NOOP_PICK_DETAILS_CONSUMER =
       new LoadBalancer.PickDetailsConsumer() {};
@@ -934,6 +938,8 @@ public void run() {
     void updateConfigSelector(@Nullable InternalConfigSelector config) {
       InternalConfigSelector prevConfig = configSelector.get();
       configSelector.set(config);
+      channelLogger.log(ChannelLogLevel.INFO,
+        "Current service config is replaced", prevConfig, config);
       if (prevConfig == INITIAL_PENDING_SELECTOR && pendingCalls != null) {
         for (RealChannel.PendingCall<?, ?> pendingCall : pendingCalls) {
           pendingCall.reprocess();
diff --git a/core/src/main/java/io/grpc/internal/ManagedChannelServiceConfig.java b/core/src/main/java/io/grpc/internal/ManagedChannelServiceConfig.java
index e5512dc8df4..0539e131062 100644
--- a/core/src/main/java/io/grpc/internal/ManagedChannelServiceConfig.java
+++ b/core/src/main/java/io/grpc/internal/ManagedChannelServiceConfig.java
@@ -412,5 +412,12 @@ public Result selectConfig(PickSubchannelArgs args) {
           .setConfig(config)
           .build();
     }
+
+    @Override
+    public String toString() {
+     return "ServiceConfigConvertedSelector{" +
+          "config=" + config +
+          '}';
+    }
   }
 }
diff --git a/core/src/test/java/io/grpc/internal/ManagedChannelImplTest.java b/core/src/test/java/io/grpc/internal/ManagedChannelImplTest.java
index 21ccf1095df..b8f2181d4fa 100644
--- a/core/src/test/java/io/grpc/internal/ManagedChannelImplTest.java
+++ b/core/src/test/java/io/grpc/internal/ManagedChannelImplTest.java
@@ -3273,7 +3273,7 @@ public void channelTracing_nameResolvedEvent_zeorAndNonzeroBackends() throws Exc
                 Arrays.asList(new SocketAddress() {}, new SocketAddress() {}))))
         .build();
     nameResolverFactory.resolvers.get(0).listener.onResult(resolutionResult1);
-    assertThat(getStats(channel).channelTrace.events).hasSize(prevSize);
+    assertThat(getStats(channel).channelTrace.events).hasSize(prevSize + 1);
 
     prevSize = getStats(channel).channelTrace.events.size();
     nameResolverFactory.resolvers.get(0).listener.onError(Status.INTERNAL);
@@ -3290,7 +3290,7 @@ public void channelTracing_nameResolvedEvent_zeorAndNonzeroBackends() throws Exc
               Arrays.asList(new SocketAddress() {}, new SocketAddress() {}))))
         .build();
     nameResolverFactory.resolvers.get(0).listener.onResult(resolutionResult2);
-    assertThat(getStats(channel).channelTrace.events).hasSize(prevSize + 1);
+    assertThat(getStats(channel).channelTrace.events).hasSize(prevSize + 2);
   }
 
   @Test
@@ -3314,7 +3314,7 @@ public void channelTracing_nameResolvedEvent_zeorAndNonzeroBackends_usesListener
 
     channel.syncContext.execute(
         () -> nameResolverFactory.resolvers.get(0).listener.onResult2(resolutionResult1));
-    assertThat(getStats(channel).channelTrace.events).hasSize(prevSize);
+    assertThat(getStats(channel).channelTrace.events).hasSize(prevSize + 1);
 
     prevSize = getStats(channel).channelTrace.events.size();
     channel.syncContext.execute(() ->
@@ -3340,7 +3340,7 @@ public void channelTracing_nameResolvedEvent_zeorAndNonzeroBackends_usesListener
         .build();
     channel.syncContext.execute(
         () -> nameResolverFactory.resolvers.get(0).listener.onResult2(resolutionResult2));
-    assertThat(getStats(channel).channelTrace.events).hasSize(prevSize + 1);
+    assertThat(getStats(channel).channelTrace.events).hasSize(prevSize + 2);
   }
 
   @Test
@@ -3366,10 +3366,10 @@ public void channelTracing_serviceConfigChange() throws Exception {
         .setServiceConfig(ConfigOrError.fromConfig(mcsc1))
         .build();
     nameResolverFactory.resolvers.get(0).listener.onResult(resolutionResult1);
-    assertThat(getStats(channel).channelTrace.events).hasSize(prevSize + 1);
+    assertThat(getStats(channel).channelTrace.events).hasSize(prevSize + 2);
     assertThat(getStats(channel).channelTrace.events.get(prevSize))
         .isEqualTo(new ChannelTrace.Event.Builder()
-            .setDescription("Service config changed")
+            .setDescription("Current service config is replaced")
             .setSeverity(ChannelTrace.Event.Severity.CT_INFO)
             .setTimestampNanos(timer.getTicker().read())
             .build());
@@ -3382,7 +3382,7 @@ public void channelTracing_serviceConfigChange() throws Exception {
         .setServiceConfig(ConfigOrError.fromConfig(mcsc1))
         .build();
     nameResolverFactory.resolvers.get(0).listener.onResult(resolutionResult2);
-    assertThat(getStats(channel).channelTrace.events).hasSize(prevSize);
+    assertThat(getStats(channel).channelTrace.events).hasSize(prevSize + 1);
 
     prevSize = getStats(channel).channelTrace.events.size();
     timer.forwardNanos(1234);
@@ -3393,10 +3393,10 @@ public void channelTracing_serviceConfigChange() throws Exception {
         .setServiceConfig(ConfigOrError.fromConfig(ManagedChannelServiceConfig.empty()))
         .build();
     nameResolverFactory.resolvers.get(0).listener.onResult(resolutionResult3);
-    assertThat(getStats(channel).channelTrace.events).hasSize(prevSize + 1);
+    assertThat(getStats(channel).channelTrace.events).hasSize(prevSize + 2);
     assertThat(getStats(channel).channelTrace.events.get(prevSize))
         .isEqualTo(new ChannelTrace.Event.Builder()
-            .setDescription("Service config changed")
+            .setDescription("Current service config is replaced")
             .setSeverity(ChannelTrace.Event.Severity.CT_INFO)
             .setTimestampNanos(timer.getTicker().read())
             .build());
@@ -3427,10 +3427,10 @@ public void channelTracing_serviceConfigChange_usesListener2OnResult2() throws E
 
     channel.syncContext.execute(() ->
         nameResolverFactory.resolvers.get(0).listener.onResult2(resolutionResult1));
-    assertThat(getStats(channel).channelTrace.events).hasSize(prevSize + 1);
+    assertThat(getStats(channel).channelTrace.events).hasSize(prevSize + 2);
     assertThat(getStats(channel).channelTrace.events.get(prevSize))
         .isEqualTo(new ChannelTrace.Event.Builder()
-            .setDescription("Service config changed")
+            .setDescription("Current service config is replaced")
             .setSeverity(ChannelTrace.Event.Severity.CT_INFO)
             .setTimestampNanos(timer.getTicker().read())
             .build());
@@ -3444,7 +3444,7 @@ public void channelTracing_serviceConfigChange_usesListener2OnResult2() throws E
         .build();
     channel.syncContext.execute(() ->
         nameResolverFactory.resolvers.get(0).listener.onResult(resolutionResult2));
-    assertThat(getStats(channel).channelTrace.events).hasSize(prevSize);
+    assertThat(getStats(channel).channelTrace.events).hasSize(prevSize + 1);
 
     prevSize = getStats(channel).channelTrace.events.size();
     timer.forwardNanos(1234);
@@ -3456,10 +3456,10 @@ public void channelTracing_serviceConfigChange_usesListener2OnResult2() throws E
         .build();
     channel.syncContext.execute(() ->
         nameResolverFactory.resolvers.get(0).listener.onResult(resolutionResult3));
-    assertThat(getStats(channel).channelTrace.events).hasSize(prevSize + 1);
+    assertThat(getStats(channel).channelTrace.events).hasSize(prevSize + 2);
     assertThat(getStats(channel).channelTrace.events.get(prevSize))
         .isEqualTo(new ChannelTrace.Event.Builder()
-            .setDescription("Service config changed")
+            .setDescription("Current service config is replaced")
             .setSeverity(ChannelTrace.Event.Severity.CT_INFO)
             .setTimestampNanos(timer.getTicker().read())
             .build());

From c9764964791c875b4d41fd592098be862584cee4 Mon Sep 17 00:00:00 2001
From: vinodhabib <vinodhabib@gmail.com>
Date: Fri, 21 Feb 2025 16:21:34 +0000
Subject: [PATCH 2/7] core: Fixed checkstyle violations not found in local
 build

---
 .../src/main/java/io/grpc/internal/ManagedChannelImpl.java | 3 ++-
 .../java/io/grpc/internal/ManagedChannelServiceConfig.java | 7 ++++---
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/core/src/main/java/io/grpc/internal/ManagedChannelImpl.java b/core/src/main/java/io/grpc/internal/ManagedChannelImpl.java
index aec23b0fa86..55d1d3c0a85 100644
--- a/core/src/main/java/io/grpc/internal/ManagedChannelImpl.java
+++ b/core/src/main/java/io/grpc/internal/ManagedChannelImpl.java
@@ -151,6 +151,7 @@ final class ManagedChannelImpl extends ManagedChannel implements
         public Result selectConfig(PickSubchannelArgs args) {
           throw new IllegalStateException("Resolution is pending");
         }
+
         @Override
         public String toString() {
           return "Resolution is pending";
@@ -939,7 +940,7 @@ void updateConfigSelector(@Nullable InternalConfigSelector config) {
       InternalConfigSelector prevConfig = configSelector.get();
       configSelector.set(config);
       channelLogger.log(ChannelLogLevel.INFO,
-        "Current service config is replaced", prevConfig, config);
+          "Current service config is replaced", prevConfig, config);
       if (prevConfig == INITIAL_PENDING_SELECTOR && pendingCalls != null) {
         for (RealChannel.PendingCall<?, ?> pendingCall : pendingCalls) {
           pendingCall.reprocess();
diff --git a/core/src/main/java/io/grpc/internal/ManagedChannelServiceConfig.java b/core/src/main/java/io/grpc/internal/ManagedChannelServiceConfig.java
index 0539e131062..9c001d590e5 100644
--- a/core/src/main/java/io/grpc/internal/ManagedChannelServiceConfig.java
+++ b/core/src/main/java/io/grpc/internal/ManagedChannelServiceConfig.java
@@ -415,9 +415,10 @@ public Result selectConfig(PickSubchannelArgs args) {
 
     @Override
     public String toString() {
-     return "ServiceConfigConvertedSelector{" +
-          "config=" + config +
-          '}';
+      return "ServiceConfigConvertedSelector{"
+          + "config="
+          + config
+          + '}';
     }
   }
 }

From a44c350e7a5025fc0613a6fcad06559cb3b54dcd Mon Sep 17 00:00:00 2001
From: vinodhabib <vinodhabib@gmail.com>
Date: Mon, 24 Feb 2025 14:03:24 +0000
Subject: [PATCH 3/7] core: added UT for toString of InternalConfigSelector

---
 .../main/java/io/grpc/internal/ManagedChannelImpl.java    | 3 ++-
 .../java/io/grpc/internal/ManagedChannelImplTest.java     | 8 ++++++++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/core/src/main/java/io/grpc/internal/ManagedChannelImpl.java b/core/src/main/java/io/grpc/internal/ManagedChannelImpl.java
index 55d1d3c0a85..6dab75acf7c 100644
--- a/core/src/main/java/io/grpc/internal/ManagedChannelImpl.java
+++ b/core/src/main/java/io/grpc/internal/ManagedChannelImpl.java
@@ -145,7 +145,7 @@ final class ManagedChannelImpl extends ManagedChannel implements
 
   private static final ManagedChannelServiceConfig EMPTY_SERVICE_CONFIG =
       ManagedChannelServiceConfig.empty();
-  private static final InternalConfigSelector INITIAL_PENDING_SELECTOR =
+  static final InternalConfigSelector INITIAL_PENDING_SELECTOR =
       new InternalConfigSelector() {
         @Override
         public Result selectConfig(PickSubchannelArgs args) {
@@ -941,6 +941,7 @@ void updateConfigSelector(@Nullable InternalConfigSelector config) {
       configSelector.set(config);
       channelLogger.log(ChannelLogLevel.INFO,
           "Current service config is replaced", prevConfig, config);
+      //System.out.println("prevConfig="+ prevConfig + " config=" + config);
       if (prevConfig == INITIAL_PENDING_SELECTOR && pendingCalls != null) {
         for (RealChannel.PendingCall<?, ?> pendingCall : pendingCalls) {
           pendingCall.reprocess();
diff --git a/core/src/test/java/io/grpc/internal/ManagedChannelImplTest.java b/core/src/test/java/io/grpc/internal/ManagedChannelImplTest.java
index b8f2181d4fa..45ee2ae2fbd 100644
--- a/core/src/test/java/io/grpc/internal/ManagedChannelImplTest.java
+++ b/core/src/test/java/io/grpc/internal/ManagedChannelImplTest.java
@@ -1208,6 +1208,14 @@ public void addressResolutionError_noPriorNameResolution_usesDefaultServiceConfi
         .isEmpty();
   }
 
+  @Test
+  public void testToStringForInternalConfigSelector() {
+    String expected = "Resolution is pending";
+    String actual = ManagedChannelImpl.INITIAL_PENDING_SELECTOR.toString();
+    // Assert that the actual string equals the expected string
+    assertEquals("toString() should return 'Resolution is pending'", expected, actual);
+  }
+
   @Test
   public void interceptor() throws Exception {
     final AtomicLong atomic = new AtomicLong();

From 18a69d59547d28a5e6efbd5a0ea4273525b55c4e Mon Sep 17 00:00:00 2001
From: vinodhabib <vinodhabib@gmail.com>
Date: Mon, 24 Feb 2025 14:06:34 +0000
Subject: [PATCH 4/7] core: added UT for toString of InternalConfigSelector

---
 core/src/main/java/io/grpc/internal/ManagedChannelImpl.java | 1 -
 1 file changed, 1 deletion(-)

diff --git a/core/src/main/java/io/grpc/internal/ManagedChannelImpl.java b/core/src/main/java/io/grpc/internal/ManagedChannelImpl.java
index 6dab75acf7c..c19a1f05c0e 100644
--- a/core/src/main/java/io/grpc/internal/ManagedChannelImpl.java
+++ b/core/src/main/java/io/grpc/internal/ManagedChannelImpl.java
@@ -941,7 +941,6 @@ void updateConfigSelector(@Nullable InternalConfigSelector config) {
       configSelector.set(config);
       channelLogger.log(ChannelLogLevel.INFO,
           "Current service config is replaced", prevConfig, config);
-      //System.out.println("prevConfig="+ prevConfig + " config=" + config);
       if (prevConfig == INITIAL_PENDING_SELECTOR && pendingCalls != null) {
         for (RealChannel.PendingCall<?, ?> pendingCall : pendingCalls) {
           pendingCall.reprocess();

From 140e2f17b3fcbd0f3467d94ad5d1a45f7ae8438b Mon Sep 17 00:00:00 2001
From: vinodhabib <vinodhabib@gmail.com>
Date: Mon, 24 Feb 2025 15:29:56 +0000
Subject: [PATCH 5/7] core: added UT for toString of
 ServiceConfigConvertedSelector

---
 .../internal/ManagedChannelServiceConfig.java |  2 +-
 .../ManagedChannelServiceConfigTest.java      | 22 +++++++++++++++++++
 2 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/core/src/main/java/io/grpc/internal/ManagedChannelServiceConfig.java b/core/src/main/java/io/grpc/internal/ManagedChannelServiceConfig.java
index 9c001d590e5..7b5a7d884f8 100644
--- a/core/src/main/java/io/grpc/internal/ManagedChannelServiceConfig.java
+++ b/core/src/main/java/io/grpc/internal/ManagedChannelServiceConfig.java
@@ -402,7 +402,7 @@ static final class ServiceConfigConvertedSelector extends InternalConfigSelector
     final ManagedChannelServiceConfig config;
 
     /** Converts the service config to config selector. */
-    private ServiceConfigConvertedSelector(ManagedChannelServiceConfig config) {
+    ServiceConfigConvertedSelector(ManagedChannelServiceConfig config) {
       this.config = config;
     }
 
diff --git a/core/src/test/java/io/grpc/internal/ManagedChannelServiceConfigTest.java b/core/src/test/java/io/grpc/internal/ManagedChannelServiceConfigTest.java
index 493714dfd41..393f04ad25b 100644
--- a/core/src/test/java/io/grpc/internal/ManagedChannelServiceConfigTest.java
+++ b/core/src/test/java/io/grpc/internal/ManagedChannelServiceConfigTest.java
@@ -20,6 +20,7 @@
 import static io.grpc.MethodDescriptor.MethodType.UNARY;
 import static io.grpc.Status.Code.UNAVAILABLE;
 import static java.util.concurrent.TimeUnit.MILLISECONDS;
+import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
 import com.google.common.collect.ImmutableList;
@@ -31,6 +32,7 @@
 import io.grpc.Metadata;
 import io.grpc.MethodDescriptor;
 import io.grpc.internal.ManagedChannelServiceConfig.MethodInfo;
+import io.grpc.internal.ManagedChannelServiceConfig.ServiceConfigConvertedSelector;
 import io.grpc.testing.TestMethodDescriptors;
 import java.util.Collections;
 import java.util.Map;
@@ -296,6 +298,26 @@ public void retryConfig_AllowPerAttemptRecvTimeoutZero() {
         .isNotNull();
   }
 
+  @Test
+  public void testToStringForServiceConfigConvertedSelector() {
+    Map<String, ?> name = ImmutableMap.of("service", "service1", "method", "method1");
+    Map<String, ?> methodConfig = ImmutableMap.of(
+        "name", ImmutableList.of(name), "timeout", "1.234s");
+    Map<String, ?> rawServiceConfig =
+        ImmutableMap.of("methodConfig", ImmutableList.of(methodConfig));
+    ManagedChannelServiceConfig serviceConfig =
+        ManagedChannelServiceConfig.fromServiceConfig(rawServiceConfig, false, 0, 0, null);
+    ServiceConfigConvertedSelector selector = new ServiceConfigConvertedSelector(serviceConfig);
+    // Assert the toString method contains the config/structure and other details with data
+    assertTrue(selector.toString().contains("ServiceConfigConvertedSelector{"));
+    assertTrue(selector.toString().contains("config"));
+    assertTrue(selector.toString().contains("ManagedChannelServiceConfig{"));
+    assertTrue(selector.toString().contains("defaultMethodConfig"));
+    assertTrue(selector.toString().contains("serviceMethodMap"));
+    assertTrue(selector.toString().contains("service1/method1"));
+    assertTrue(selector.toString().contains("serviceMap"));
+  }
+
   private static MethodDescriptor<?, ?> methodForName(String service, String method) {
     return MethodDescriptor.<Void, Void>newBuilder()
         .setFullMethodName(service + "/" + method)

From c9ee995a380052614c7e15b2c7f59b8cbb620c86 Mon Sep 17 00:00:00 2001
From: vinodhabib <vinodhabib@gmail.com>
Date: Tue, 25 Feb 2025 06:21:24 +0000
Subject: [PATCH 6/7] core: updated the variable name and logger message

---
 .../main/java/io/grpc/internal/ManagedChannelImpl.java    | 6 +++---
 .../java/io/grpc/internal/ManagedChannelImplTest.java     | 8 ++++----
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/core/src/main/java/io/grpc/internal/ManagedChannelImpl.java b/core/src/main/java/io/grpc/internal/ManagedChannelImpl.java
index c19a1f05c0e..ff959d4da22 100644
--- a/core/src/main/java/io/grpc/internal/ManagedChannelImpl.java
+++ b/core/src/main/java/io/grpc/internal/ManagedChannelImpl.java
@@ -936,11 +936,11 @@ public void run() {
     }
 
     // Must run in SynchronizationContext.
-    void updateConfigSelector(@Nullable InternalConfigSelector config) {
+    void updateConfigSelector(@Nullable InternalConfigSelector currentConfig) {
       InternalConfigSelector prevConfig = configSelector.get();
-      configSelector.set(config);
+      configSelector.set(currentConfig);
       channelLogger.log(ChannelLogLevel.INFO,
-          "Current service config is replaced", prevConfig, config);
+          "Previous service config updated to current", prevConfig, currentConfig);
       if (prevConfig == INITIAL_PENDING_SELECTOR && pendingCalls != null) {
         for (RealChannel.PendingCall<?, ?> pendingCall : pendingCalls) {
           pendingCall.reprocess();
diff --git a/core/src/test/java/io/grpc/internal/ManagedChannelImplTest.java b/core/src/test/java/io/grpc/internal/ManagedChannelImplTest.java
index 45ee2ae2fbd..f4964b4dde4 100644
--- a/core/src/test/java/io/grpc/internal/ManagedChannelImplTest.java
+++ b/core/src/test/java/io/grpc/internal/ManagedChannelImplTest.java
@@ -3377,7 +3377,7 @@ public void channelTracing_serviceConfigChange() throws Exception {
     assertThat(getStats(channel).channelTrace.events).hasSize(prevSize + 2);
     assertThat(getStats(channel).channelTrace.events.get(prevSize))
         .isEqualTo(new ChannelTrace.Event.Builder()
-            .setDescription("Current service config is replaced")
+            .setDescription("Previous service config updated to current")
             .setSeverity(ChannelTrace.Event.Severity.CT_INFO)
             .setTimestampNanos(timer.getTicker().read())
             .build());
@@ -3404,7 +3404,7 @@ public void channelTracing_serviceConfigChange() throws Exception {
     assertThat(getStats(channel).channelTrace.events).hasSize(prevSize + 2);
     assertThat(getStats(channel).channelTrace.events.get(prevSize))
         .isEqualTo(new ChannelTrace.Event.Builder()
-            .setDescription("Current service config is replaced")
+            .setDescription("Previous service config updated to current")
             .setSeverity(ChannelTrace.Event.Severity.CT_INFO)
             .setTimestampNanos(timer.getTicker().read())
             .build());
@@ -3438,7 +3438,7 @@ public void channelTracing_serviceConfigChange_usesListener2OnResult2() throws E
     assertThat(getStats(channel).channelTrace.events).hasSize(prevSize + 2);
     assertThat(getStats(channel).channelTrace.events.get(prevSize))
         .isEqualTo(new ChannelTrace.Event.Builder()
-            .setDescription("Current service config is replaced")
+            .setDescription("Previous service config updated to current")
             .setSeverity(ChannelTrace.Event.Severity.CT_INFO)
             .setTimestampNanos(timer.getTicker().read())
             .build());
@@ -3467,7 +3467,7 @@ public void channelTracing_serviceConfigChange_usesListener2OnResult2() throws E
     assertThat(getStats(channel).channelTrace.events).hasSize(prevSize + 2);
     assertThat(getStats(channel).channelTrace.events.get(prevSize))
         .isEqualTo(new ChannelTrace.Event.Builder()
-            .setDescription("Current service config is replaced")
+            .setDescription("Previous service config updated to current")
             .setSeverity(ChannelTrace.Event.Severity.CT_INFO)
             .setTimestampNanos(timer.getTicker().read())
             .build());

From e2b489a080d68f7aabebadd701d0f5fda4855a09 Mon Sep 17 00:00:00 2001
From: vinodhabib <vinodhabib@gmail.com>
Date: Tue, 25 Feb 2025 13:26:58 +0000
Subject: [PATCH 7/7] core: modified  the logger message along with UT changes.

---
 .../io/grpc/internal/ManagedChannelImpl.java  |  7 +++---
 .../grpc/internal/ManagedChannelImplTest.java | 22 ++++++++++++-------
 2 files changed, 18 insertions(+), 11 deletions(-)

diff --git a/core/src/main/java/io/grpc/internal/ManagedChannelImpl.java b/core/src/main/java/io/grpc/internal/ManagedChannelImpl.java
index ff959d4da22..9dff90855cd 100644
--- a/core/src/main/java/io/grpc/internal/ManagedChannelImpl.java
+++ b/core/src/main/java/io/grpc/internal/ManagedChannelImpl.java
@@ -936,11 +936,12 @@ public void run() {
     }
 
     // Must run in SynchronizationContext.
-    void updateConfigSelector(@Nullable InternalConfigSelector currentConfig) {
+    void updateConfigSelector(@Nullable InternalConfigSelector newConfig) {
       InternalConfigSelector prevConfig = configSelector.get();
-      configSelector.set(currentConfig);
+      configSelector.set(newConfig);
       channelLogger.log(ChannelLogLevel.INFO,
-          "Previous service config updated to current", prevConfig, currentConfig);
+          "Current config is replaced with new config. prevConfig={0}, newConfig={1}",
+          prevConfig, newConfig);
       if (prevConfig == INITIAL_PENDING_SELECTOR && pendingCalls != null) {
         for (RealChannel.PendingCall<?, ?> pendingCall : pendingCalls) {
           pendingCall.reprocess();
diff --git a/core/src/test/java/io/grpc/internal/ManagedChannelImplTest.java b/core/src/test/java/io/grpc/internal/ManagedChannelImplTest.java
index f4964b4dde4..47ac7470ff1 100644
--- a/core/src/test/java/io/grpc/internal/ManagedChannelImplTest.java
+++ b/core/src/test/java/io/grpc/internal/ManagedChannelImplTest.java
@@ -85,6 +85,7 @@
 import io.grpc.InternalChannelz;
 import io.grpc.InternalChannelz.ChannelStats;
 import io.grpc.InternalChannelz.ChannelTrace;
+import io.grpc.InternalChannelz.ChannelTrace.Event;
 import io.grpc.InternalChannelz.ChannelTrace.Event.Severity;
 import io.grpc.InternalConfigSelector;
 import io.grpc.InternalInstrumented;
@@ -3375,9 +3376,14 @@ public void channelTracing_serviceConfigChange() throws Exception {
         .build();
     nameResolverFactory.resolvers.get(0).listener.onResult(resolutionResult1);
     assertThat(getStats(channel).channelTrace.events).hasSize(prevSize + 2);
-    assertThat(getStats(channel).channelTrace.events.get(prevSize))
+
+    Event configEvent = getStats(channel).channelTrace.events.get(prevSize);
+
+    assertThat(configEvent.description)
+        .contains("Current config is replaced with new config. prevConfig=");
+    assertThat(getStats(channel).channelTrace.events.get(prevSize + 1))
         .isEqualTo(new ChannelTrace.Event.Builder()
-            .setDescription("Previous service config updated to current")
+            .setDescription("Service config changed")
             .setSeverity(ChannelTrace.Event.Severity.CT_INFO)
             .setTimestampNanos(timer.getTicker().read())
             .build());
@@ -3402,9 +3408,9 @@ public void channelTracing_serviceConfigChange() throws Exception {
         .build();
     nameResolverFactory.resolvers.get(0).listener.onResult(resolutionResult3);
     assertThat(getStats(channel).channelTrace.events).hasSize(prevSize + 2);
-    assertThat(getStats(channel).channelTrace.events.get(prevSize))
+    assertThat(getStats(channel).channelTrace.events.get(prevSize + 1))
         .isEqualTo(new ChannelTrace.Event.Builder()
-            .setDescription("Previous service config updated to current")
+            .setDescription("Service config changed")
             .setSeverity(ChannelTrace.Event.Severity.CT_INFO)
             .setTimestampNanos(timer.getTicker().read())
             .build());
@@ -3436,9 +3442,9 @@ public void channelTracing_serviceConfigChange_usesListener2OnResult2() throws E
     channel.syncContext.execute(() ->
         nameResolverFactory.resolvers.get(0).listener.onResult2(resolutionResult1));
     assertThat(getStats(channel).channelTrace.events).hasSize(prevSize + 2);
-    assertThat(getStats(channel).channelTrace.events.get(prevSize))
+    assertThat(getStats(channel).channelTrace.events.get(prevSize + 1))
         .isEqualTo(new ChannelTrace.Event.Builder()
-            .setDescription("Previous service config updated to current")
+            .setDescription("Service config changed")
             .setSeverity(ChannelTrace.Event.Severity.CT_INFO)
             .setTimestampNanos(timer.getTicker().read())
             .build());
@@ -3465,9 +3471,9 @@ public void channelTracing_serviceConfigChange_usesListener2OnResult2() throws E
     channel.syncContext.execute(() ->
         nameResolverFactory.resolvers.get(0).listener.onResult(resolutionResult3));
     assertThat(getStats(channel).channelTrace.events).hasSize(prevSize + 2);
-    assertThat(getStats(channel).channelTrace.events.get(prevSize))
+    assertThat(getStats(channel).channelTrace.events.get(prevSize + 1))
         .isEqualTo(new ChannelTrace.Event.Builder()
-            .setDescription("Previous service config updated to current")
+            .setDescription("Service config changed")
             .setSeverity(ChannelTrace.Event.Severity.CT_INFO)
             .setTimestampNanos(timer.getTicker().read())
             .build());