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

Fix/sentinel filter #2621

Merged
merged 5 commits into from
Mar 22, 2024
Merged

Fix/sentinel filter #2621

merged 5 commits into from
Mar 22, 2024

Conversation

r27153733
Copy link
Contributor

@chickenlj chickenlj self-requested a review March 14, 2024 04:45
@codecov-commenter
Copy link

codecov-commenter commented Mar 14, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 47.44%. Comparing base (8997917) to head (8997917).

❗ Current head 8997917 differs from pull request most recent head 2b40a1c. Consider uploading reports for the commit 2b40a1c to get more accurate results

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2621   +/-   ##
=======================================
  Coverage   47.44%   47.44%           
=======================================
  Files         341      341           
  Lines       25168    25168           
=======================================
  Hits        11940    11940           
  Misses      12084    12084           
  Partials     1144     1144           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@justxuewei justxuewei left a comment

Choose a reason for hiding this comment

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

Thanks! A few comments about code style.

In addition, I have another concern: sentinel.TraceError is called by OnResponse() previously, but now is called by Invoke(). THE SIDE EFFECT: You changes the behavior of the filter.

IMHO, your concern is that the context isn't updated with the latest data, right? So a possible fix could be:

 func (fi *FilterInvoker) Invoke(ctx context.Context, invocation protocol.Invocation) protocol.Result { 
 	result := fi.filter.Invoke(ctx, fi.next, invocation)
 	// do something to copy the context from the latest one
 	return fi.filter.OnResponse(ctx, result, fi.invoker, invocation) 
 } 

Wdyt?

UPDATE 1: Maybe the above way is not easy to implement. But the main idea is to share the context between fi.filter.Invoke() and fi.filter.OnResponse().

Comment on lines 105 to 108
err := sentinel.InitDefault()
if err != nil {
panic(err)
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
err := sentinel.InitDefault()
if err != nil {
panic(err)
}
if err := sentinel.InitDefault(); err != nil {
panic(err)
}

Comment on lines 129 to 131
} else {
defer interfaceEntry.Exit()
}
Copy link
Member

Choose a reason for hiding this comment

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

else here could be removed.

Suggested change
} else {
defer interfaceEntry.Exit()
}
}
defer interfaceEntry.Exit()

Comment on lines 140 to 142
} else {
defer methodEntry.Exit()
}
Copy link
Member

Choose a reason for hiding this comment

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

Ditto.

Comment on lines 190 to 192
} else {
defer interfaceEntry.Exit()
}
Copy link
Member

Choose a reason for hiding this comment

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

Ditto.

Comment on lines 199 to 201
} else {
defer methodEntry.Exit()
}
Copy link
Member

Choose a reason for hiding this comment

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

Ditto.

@r27153733
Copy link
Contributor Author

r27153733 commented Mar 18, 2024

Thanks! A few comments about code style.

In addition, I have another concern: sentinel.TraceError is called by OnResponse() previously, but now is called by Invoke(). THE SIDE EFFECT: You changes the behavior of the filter.

IMHO, your concern is that the context isn't updated with the latest data, right? So a possible fix could be:

 func (fi *FilterInvoker) Invoke(ctx context.Context, invocation protocol.Invocation) protocol.Result { 
 	result := fi.filter.Invoke(ctx, fi.next, invocation)
 	// do something to copy the context from the latest one
 	return fi.filter.OnResponse(ctx, result, fi.invoker, invocation) 
 } 

Wdyt?

UPDATE 1: Maybe the above way is not easy to implement. But the main idea is to share the context between fi.filter.Invoke() and fi.filter.OnResponse().

I also wanted to share context between fi.filter.Invoke() and fi.filter.OnResponse(), unfortunately, modifying FilterInvoker is not enough; it's necessary to change the definition of the Filter interface. I once sought inspiration from Java, but...

https://github.com/apache/dubbo-sentinel-support/blob/910a466809371331fdaf5c16b602bca3e48666d1/src/main/java/com/alibaba/csp/sentinel/adapter/dubbo/SentinelDubboConsumerFilter.java#L52-L83

Perhaps there will never be a need to perform some operations between fi.filter.Invoke() and fi.filter.OnResponse(). I have come to terms with it.

Copy link
Member

@justxuewei justxuewei left a comment

Choose a reason for hiding this comment

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

This looks good to me overall. For what I mentioned eariler, I found a post introducing a wrapped context, which could be worth considering.

Copy link

sonarcloud bot commented Mar 20, 2024

Quality Gate Passed Quality Gate passed

Issues
4 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@justxuewei justxuewei merged commit 55a0639 into apache:main Mar 22, 2024
5 checks passed
FoghostCn pushed a commit to FoghostCn/dubbo-go that referenced this pull request Mar 27, 2024
* fix: the bug of sentinel.TraceError and sentinel.Exit not being called, and sentinel.InitDefault() not being called

* test: add test sentinel filter error count

* fix: The problem of sentinel.TraceError not being called in sentinelConsumerFilter.

* style: adjust code style.
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.

3 participants