Alanxtl commented on code in PR #1: URL: https://github.com/apache/dubbo-go-extensions/pull/1#discussion_r2917618476
########## filter/hystrix/filter.go: ########## @@ -0,0 +1,169 @@ +/* + * 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 hystrix provides hystrix filter. +// To use hystrix, you need to configure commands using hystrix-go API: +// +// import "github.com/afex/hystrix-go/hystrix" +// +// // Resource name format: dubbo:consumer:InterfaceName:group:version:Method(param1,param2) +// // Example: dubbo:consumer:com.example.GreetService:::Greet(string,string) +// hystrix.ConfigureCommand("dubbo:consumer:com.example.GreetService:::Greet(string,string)", hystrix.CommandConfig{ +// Timeout: 1000, +// MaxConcurrentRequests: 20, +// RequestVolumeThreshold: 20, +// SleepWindow: 5000, +// ErrorPercentThreshold: 50, +// }) + +package hystrix + +import ( + "context" + "fmt" + "strings" +) + +import ( + "dubbo.apache.org/dubbo-go/v3/common" + "dubbo.apache.org/dubbo-go/v3/common/constant" + "dubbo.apache.org/dubbo-go/v3/common/extension" + "dubbo.apache.org/dubbo-go/v3/filter" + "dubbo.apache.org/dubbo-go/v3/protocol/base" + "dubbo.apache.org/dubbo-go/v3/protocol/result" + + "github.com/afex/hystrix-go/hystrix" + + "github.com/dubbogo/gost/log/logger" +) + +const ( + // Filter keys + HystrixConsumerFilterKey = "hystrix_consumer" + HystrixProviderFilterKey = "hystrix_provider" + + // Prefixes for resource naming + DefaultProviderPrefix = "dubbo:provider:" + DefaultConsumerPrefix = "dubbo:consumer:" +) + +func init() { + extension.SetFilter(HystrixConsumerFilterKey, newFilterConsumer) + extension.SetFilter(HystrixProviderFilterKey, newFilterProvider) +} + +// FilterError implements error interface +type FilterError struct { + err error + failByHystrix bool +} + +func (hfError *FilterError) Error() string { + return hfError.err.Error() +} + +// FailByHystrix returns whether the fails causing by Hystrix +func (hfError *FilterError) FailByHystrix() bool { + return hfError.failByHystrix Review Comment: `failByHystrix` currently does not match the actual behavior. In the fallback, `failByHystrix` is set to `true` only when `err` is a `hystrix.CircuitError`, but the fallback can also be triggered by other hystrix-originated failures such as timeout or rejection. So the current implementation is closer to "is circuit open" rather than "failed by hystrix". Also, the log message always says `Circuit opened`, which can be misleading for non-circuit-open failures. Could we either: 1. set `failByHystrix = true` for all fallback paths, and separately distinguish circuit-open if needed, or 2. rename the flag/method to something more precise like `circuitOpen`? -- 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]
