AlbumenJ commented on code in PR #11021:
URL: https://github.com/apache/dubbo/pull/11021#discussion_r1084013190


##########
dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/filter/observation/DefaultDubboClientObservationConvention.java:
##########
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.dubbo.metrics.filter.observation;
+
+import io.micrometer.common.KeyValues;
+import org.apache.dubbo.common.URL;
+import org.apache.dubbo.rpc.RpcContextAttachment;
+
+import static 
org.apache.dubbo.metrics.filter.observation.DubboObservation.LowCardinalityKeyNames.NET_PEER_NAME;
+import static 
org.apache.dubbo.metrics.filter.observation.DubboObservation.LowCardinalityKeyNames.NET_PEER_PORT;
+
+/**
+ * Default implementation of the {@link DubboClientObservationConvention}.
+ */
+public class DefaultDubboClientObservationConvention extends 
AbstractDefaultDubboObservationConvention implements 
DubboClientObservationConvention {
+    /**
+     * Singleton instance of {@link DefaultDubboClientObservationConvention}.
+     */
+    public static final DubboClientObservationConvention INSTANCE = new 
DefaultDubboClientObservationConvention();
+
+    @Override
+    public String getName() {
+        return "rpc.client.duration";
+    }
+
+    @Override
+    public KeyValues getLowCardinalityKeyValues(DubboClientContext context) {
+        KeyValues keyValues = 
super.getLowCardinalityKeyValues(context.getInvocation());
+        RpcContextAttachment rpcContextAttachment = 
context.getRpcContextAttachment();
+        URL url = context.getInvoker().getUrl();

Review Comment:
   ```suggestion
          List<Invoker<?>> invokedInvokers = 
context.getInvocation().getInvokedInvokers();
         for (Invoker<?> invokedInvoker : invokedInvokers) {
             URL url = invokedInvoker.getUrl();
             // do something you want to
         }
   ```
   Be notice that there may more than one invoker being invoked in one time. 
E.g. Dubbo support retry for several times when invoke failed.



##########
dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/filter/observation/DubboClientContext.java:
##########
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.dubbo.metrics.filter.observation;
+
+import java.util.Objects;
+
+import io.micrometer.observation.transport.SenderContext;
+import org.apache.dubbo.rpc.Invocation;
+import org.apache.dubbo.rpc.Invoker;
+import org.apache.dubbo.rpc.RpcContextAttachment;
+
+/**
+ * Provider context for RPC.
+ */
+public class DubboClientContext extends SenderContext<Invocation> {
+
+    private final Invoker<?> invoker;
+
+    private final Invocation invocation;
+
+    private final RpcContextAttachment rpcContextAttachment;
+
+    public DubboClientContext(RpcContextAttachment rpcContextAttachment, 
Invoker<?> invoker, Invocation invocation) {
+        super((map, key, value) -> 
Objects.requireNonNull(map).setAttachment(key, value));
+        this.invoker = invoker;
+        this.invocation = invocation;
+        this.rpcContextAttachment = rpcContextAttachment;
+        setCarrier(invocation);
+    }
+
+    public RpcContextAttachment getRpcContextAttachment() {
+        return rpcContextAttachment;
+    }

Review Comment:
   Remove this field. You can get RpcContext anywhere you need by TL.



-- 
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.

To unsubscribe, e-mail: notifications-unsubscr...@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@dubbo.apache.org
For additional commands, e-mail: notifications-h...@dubbo.apache.org

Reply via email to