Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ftr: add sentinel-golang flow control/circuit breaker #748

Merged
merged 4 commits into from
Sep 13, 2020

Conversation

louyuting
Copy link
Contributor

@louyuting louyuting commented Sep 10, 2020

What this PR does:
Integrate sentinel-golang into dubbo-go

Which issue(s) this PR fixes:

Special notes for your reviewer:
@pantianying

Does this PR introduce a user-facing change?:

@louyuting
Copy link
Contributor Author

Hi, guys

I'm still working on this PR. I will mark Ready if I finish the dev.

Thanks

@louyuting louyuting changed the title add sentinel-go adapter integrate sentinel-golang(https://github.com/alibaba/sentinel-golang) as flow control/circuit breaker... Sep 10, 2020
@AlexStocks AlexStocks changed the title integrate sentinel-golang(https://github.com/alibaba/sentinel-golang) as flow control/circuit breaker... Ftr: add sentinel-golang flow control/circuit breaker Sep 10, 2020
@louyuting
Copy link
Contributor Author

@pantianying Could you please review this PR?

Besides, we might need another example to demo how to use Sentinel in dubbo-go

@louyuting louyuting marked this pull request as ready for review September 10, 2020 18:37
@pantianying
Copy link
Member

@pantianying Could you please review this PR?

Besides, we might need another example to demo how to use Sentinel in dubbo-go

I will do it soon

"github.com/apache/dubbo-go/protocol/invocation"
)

func TestConsumerFilter_Invoke(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you provide another test case that tests whether the current limiter is working

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will add a case.
But I am not familiar with dubbogo. Could you please help to review case later.

filter/filter_impl/sentinel_filter.go Show resolved Hide resolved
Comment on lines 57 to 61
if getInterfaceGroupAndVersionEnabled() {
interfaceResourceName = getColonSeparatedKey(invoker.GetUrl())
} else {
interfaceResourceName = invoker.GetUrl().Service()
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refactor this code into getInterfaceResourceName func

Copy link
Member

@beiwei30 beiwei30 Sep 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or simply introduce a func to return both interface resource name and method resource name? func getResourceNames(invoker protocol.Invoker, invocation protocol.Invocation, prefix string) (string, string)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my perspective, encapsulating a func getResourceName(invoker protocol.Invoker, invocation protocol.Invocation, prefix string) (interfaceResourceName, methodResourceName string) is better.

type SentinelProviderFilter struct{}

func (d *SentinelProviderFilter) Invoke(ctx context.Context, invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result {
methodResourceName := getResourceName(invoker, invocation, getProviderPrefix())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change this func name to getMethodResourceName?

Comment on lines 85 to 89
if methodEntry := ctx.Value(MethodEntryKey); methodEntry != nil {
e := methodEntry.(*base.SentinelEntry)
sentinel.TraceError(e, result.Error())
e.Exit()
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it looks to me this block deserves to extract a func so that it can be reused by the following 'InterfaceEntryKey'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sense

Copy link
Member

@beiwei30 beiwei30 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@louyuting pls. check my comments, thx.

}
ctx = context.WithValue(ctx, InterfaceEntryKey, interfaceEntry)

methodEntry, b = sentinel.Entry(methodResourceName, sentinel.WithResourceType(base.ResTypeRPC),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

split it into 4 lines.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok


func getResourceName(invoker protocol.Invoker, invocation protocol.Invocation, prefix string) string {
var (
buf bytes.Buffer
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's more efficient to use strings.Builder to replace bytes.Buffer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will refactor here

@AlexStocks AlexStocks merged commit 57601bc into apache:develop Sep 13, 2020
zouyx added a commit to zouyx/dubbo-go that referenced this pull request Sep 22, 2020
…tion

Ftr: add sentinel-golang  flow control/circuit breaker
# Conflicts:
#	go.sum
AlexStocks pushed a commit that referenced this pull request Apr 14, 2021
Ftr: add sentinel-golang  flow control/circuit breaker
# Conflicts:
#	go.sum
kzhan pushed a commit to kzhan/dubbo-go that referenced this pull request Jun 5, 2021
…tion

Ftr: add sentinel-golang  flow control/circuit breaker
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants