Alanxtl commented on code in PR #3189: URL: https://github.com/apache/dubbo-go/pull/3189#discussion_r2761806238
########## metrics/rpc/error_classifier.go: ########## @@ -0,0 +1,68 @@ +/* + * 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) + // TODO: Map appropriate internal/network error codes to this type when available. + ErrorTypeNetworkFailure + // ErrorTypeCodec is for codec errors (CodeInternal) + // TODO: Map appropriate internal/codec error codes to this type when available. Review Comment: todo再写清晰一些这两个字段目前不会被生产出来 ########## 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: 不要嵌套两个switch, 先用一个switch获取 ``` ms := c.metricSet.provider 或者 ms := c.metricSet.consumer ``` 然后对 ms 做 errType switch 这样以后维护方便一些 -- 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]
