Copilot commented on code in PR #3189:
URL: https://github.com/apache/dubbo-go/pull/3189#discussion_r2752649452


##########
metrics/rpc/collector.go:
##########
@@ -163,6 +166,47 @@ func (c *rpcCollector) incRequestsFailedTotal(role string, 
labels map[string]str
        }
 }
 
+func (c *rpcCollector) incRequestsFailedByType(role string, labels 
map[string]string, errType ErrorType) {
+       switch role {
+       case constant.SideProvider:
+               switch errType {
+               case ErrorTypeTimeout:
+                       c.metricSet.provider.requestsTimeoutTotal.Inc(labels)
+                       
c.metricSet.provider.requestsTimeoutTotalAggregate.Inc(labels)
+               case ErrorTypeLimit:
+                       c.metricSet.provider.requestsLimitTotal.Inc(labels)
+                       
c.metricSet.provider.requestsLimitTotalAggregate.Inc(labels)
+               case ErrorTypeServiceUnavailable:
+                       
c.metricSet.provider.requestsServiceUnavailableTotal.Inc(labels)
+                       
c.metricSet.provider.requestsServiceUnavailableTotalAggregate.Inc(labels)
+               case ErrorTypeBusinessFailed:
+                       
c.metricSet.provider.requestsBusinessFailedTotal.Inc(labels)
+                       
c.metricSet.provider.requestsBusinessFailedTotalAggregate.Inc(labels)
+               default:
+                       
c.metricSet.provider.requestsUnknownFailedTotal.Inc(labels)
+                       
c.metricSet.provider.requestsUnknownFailedTotalAggregate.Inc(labels)
+               }
+       case constant.SideConsumer:
+               switch errType {
+               case ErrorTypeTimeout:
+                       c.metricSet.consumer.requestsTimeoutTotal.Inc(labels)
+                       
c.metricSet.consumer.requestsTimeoutTotalAggregate.Inc(labels)
+               case ErrorTypeLimit:
+                       c.metricSet.consumer.requestsLimitTotal.Inc(labels)
+                       
c.metricSet.consumer.requestsLimitTotalAggregate.Inc(labels)
+               case ErrorTypeServiceUnavailable:
+                       
c.metricSet.consumer.requestsServiceUnavailableTotal.Inc(labels)
+                       
c.metricSet.consumer.requestsServiceUnavailableTotalAggregate.Inc(labels)
+               case ErrorTypeBusinessFailed:
+                       
c.metricSet.consumer.requestsBusinessFailedTotal.Inc(labels)
+                       
c.metricSet.consumer.requestsBusinessFailedTotalAggregate.Inc(labels)
+               default:
+                       
c.metricSet.consumer.requestsUnknownFailedTotal.Inc(labels)
+                       
c.metricSet.consumer.requestsUnknownFailedTotalAggregate.Inc(labels)
+               }
+       }

Review Comment:
   The new error classification path (`classifyError` plus 
`incRequestsFailedByType`) is not covered by tests, even though other RPC 
metrics helpers (e.g. `event.go` / `event_test.go`, `util.go` / `util_test.go`) 
have dedicated unit tests. Please add tests that exercise each relevant 
`triple_protocol` code (timeout, limit, unavailable/permission-denied, biz 
error and an unknown default) and verify the corresponding granular counters 
are incremented correctly for both provider and consumer roles.



##########
metrics/rpc/error_classifier.go:
##########
@@ -0,0 +1,66 @@
+/*
+ * 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 rpc
+
+import (
+       "dubbo.apache.org/dubbo-go/v3/protocol/triple/triple_protocol"
+)
+
+// ErrorType represents the classification of RPC errors
+type ErrorType uint8
+
+const (
+       // ErrorTypeUnknown is for unknown or unclassified errors
+       ErrorTypeUnknown ErrorType = iota
+       // ErrorTypeTimeout is for timeout exceptions (CodeDeadlineExceeded)
+       ErrorTypeTimeout
+       // ErrorTypeLimit is for rate limit exceeded exceptions 
(CodeResourceExhausted)
+       ErrorTypeLimit
+       // ErrorTypeServiceUnavailable is for service unavailable exceptions 
(CodeUnavailable, CodePermissionDenied)
+       ErrorTypeServiceUnavailable
+       // ErrorTypeBusinessFailed is for business logic exceptions 
(CodeBizError)
+       ErrorTypeBusinessFailed
+       // ErrorTypeNetworkFailure is for network failure exceptions 
(CodeInternal)
+       ErrorTypeNetworkFailure
+       // ErrorTypeCodec is for codec errors (CodeInternal)

Review Comment:
   `ErrorTypeNetworkFailure` and `ErrorTypeCodec` are defined with comments 
that reference `CodeInternal`, but `classifyError` never returns these values 
and does not handle `CodeInternal`, so these constants are currently unused and 
the comments are misleading. Consider either wiring these error types into the 
switch (mapping the appropriate codes) or removing/marking them as reserved 
with a TODO so future readers are not confused about unimplemented 
classifications.
   ```suggestion
        // ErrorTypeNetworkFailure is reserved for future classification of 
network failures.
        // TODO: Map appropriate internal/network error codes to this type when 
available.
        ErrorTypeNetworkFailure
        // ErrorTypeCodec is reserved for future classification of codec errors.
        // TODO: Map appropriate internal/codec error codes to this type when 
available.
   ```



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to