This is an automated email from the ASF dual-hosted git repository.
alexstocks pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/dubbo-go-pixiu.git
The following commit(s) were added to refs/heads/develop by this push:
new bd1426af Fix: fix meritc calc bug (#710)
bd1426af is described below
commit bd1426af83965ae808a3635cc205316fdeb457ce
Author: Xuetao Li <[email protected]>
AuthorDate: Tue Jul 29 07:47:36 2025 +0800
Fix: fix meritc calc bug (#710)
* Update metric.go
* Update prometheus.go
* refactor: change parameter type from interface{} to any in
computeApproximateResponseSize
* last bug
---
pkg/filter/metric/metric.go | 7 +++++--
pkg/prometheus/prometheus.go | 11 +++++++----
2 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/pkg/filter/metric/metric.go b/pkg/filter/metric/metric.go
index 72fdf484..27b76074 100644
--- a/pkg/filter/metric/metric.go
+++ b/pkg/filter/metric/metric.go
@@ -139,9 +139,12 @@ func (f *Filter) Encode(c *http.HttpContext)
filter.FilterStatus {
func computeApproximateResponseSize(res any) (int, error) {
if res == nil {
- return 0, errors.New("client.UnaryResponse is null pointer ")
+ return 0, errors.New("client response is nil")
}
- return len(res.(*client.UnaryResponse).Data), nil
+ if unaryResponse, ok := res.(*client.UnaryResponse); ok {
+ return len(unaryResponse.Data), nil
+ }
+ return 0, errors.New("response is not of type client.UnaryResponse")
}
func computeApproximateRequestSize(r *stdhttp.Request) (int, error) {
diff --git a/pkg/prometheus/prometheus.go b/pkg/prometheus/prometheus.go
index e7171b97..df9a34ad 100644
--- a/pkg/prometheus/prometheus.go
+++ b/pkg/prometheus/prometheus.go
@@ -347,7 +347,7 @@ func (p *Prometheus) HandlerFunc() ContextHandlerFunc {
if err1 == nil {
p.reqSz.WithLabelValues(statusStr, method,
url).Observe(float64(reqSz))
}
- resSz, err2 :=
computeApproximateResponseSize(c.TargetResp.(*client.UnaryResponse))
+ resSz, err2 := computeApproximateResponseSize(c.TargetResp)
if err2 == nil {
p.resSz.WithLabelValues(statusStr, method,
url).Observe(float64(resSz))
}
@@ -382,9 +382,12 @@ func computeApproximateRequestSize(r *http.Request) (int,
error) {
return s, nil
}
-func computeApproximateResponseSize(res *client.UnaryResponse) (int, error) {
+func computeApproximateResponseSize(res any) (int, error) {
if res == nil {
- return 0, errors.New("client.UnaryResponse is null pointer ")
+ return 0, errors.New("client response is nil")
}
- return len(res.Data), nil
+ if unaryResponse, ok := res.(*client.UnaryResponse); ok {
+ return len(unaryResponse.Data), nil
+ }
+ return 0, errors.New("response is not of type client.UnaryResponse")
}