Similarityoung commented on code in PR #876:
URL: https://github.com/apache/dubbo-go-pixiu/pull/876#discussion_r2770108973


##########
pkg/filter/sentinel/circuitbreaker/circuit_breaker.go:
##########
@@ -101,7 +107,40 @@ func (f *Filter) Decode(ctx *http.HttpContext) 
filter.FilterStatus {
                ctx.SendLocalReply(errResp.Status, errResp.ToJSON())
                return filter.Stop
        }
+
+       // Store entry in context for later use in Encode phase
+       if ctx.Params == nil {
+               ctx.Params = make(map[string]any)
+       }
+       ctx.Params[ContextKeySentinelEntry] = entry
+
+       return filter.Continue
+}
+
+// Encode processes the response and reports statistics to Sentinel
+func (f *Filter) Encode(ctx *http.HttpContext) filter.FilterStatus {
+       entryVal, ok := ctx.Params[ContextKeySentinelEntry]
+       if !ok {
+               // No entry in context, skip
+               return filter.Continue
+       }
+
+       entry, ok := entryVal.(*base.SentinelEntry)
+       if !ok || entry == nil {
+               logger.Warnf("Invalid sentinel entry type in context")
+               return filter.Continue
+       }
+
+       // Ensure entry.Exit() is called
        defer entry.Exit()
+
+       // Report error to Sentinel if response indicates failure
+       // Consider 5xx status codes as errors for circuit breaker
+       statusCode := ctx.GetStatusCode()
+       if statusCode >= 500 && statusCode < 600 {
+               entry.SetError(errors.New("backend service error"))

Review Comment:
   这里的错误信息是否可以多一点,比如包含实际状态码、错误上下文这种



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