-
Notifications
You must be signed in to change notification settings - Fork 720
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
grpc: add caller info to client and wrap innerClient #8704
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: okJiang <[email protected]>
Skipping CI for Draft Pull Request. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
…or-grpc Signed-off-by: okJiang <[email protected]>
/retest |
Signed-off-by: okJiang <[email protected]>
Signed-off-by: okJiang <[email protected]>
Signed-off-by: okJiang <[email protected]>
/retest |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #8704 +/- ##
==========================================
- Coverage 75.80% 75.73% -0.07%
==========================================
Files 461 461
Lines 72315 72072 -243
==========================================
- Hits 54817 54584 -233
- Misses 14000 14002 +2
+ Partials 3498 3486 -12
Flags with carried forward coverage won't be shown. Click here to find out more. |
…or-grpc Signed-off-by: okJiang <[email protected]>
Signed-off-by: okJiang <[email protected]>
Signed-off-by: okJiang <[email protected]>
Signed-off-by: okJiang <[email protected]>
Signed-off-by: okJiang <[email protected]>
Signed-off-by: okJiang <[email protected]>
/retest |
/cc @JmPotato |
wg sync.WaitGroup | ||
tlsCfg *tls.Config | ||
option *option | ||
inner *innerClient |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A nested struct without introducing the field inner
may reduce the code changes. But I'm not sure whether the pointer here still works, maybe we can have a try.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But I'm not sure whether the pointer here still works, maybe we can have a try.
I tried it before and indeed encountered some issues, so I wrapped the inner client.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And I think wrapping innerclient
also helps to reduce the amount of code in client.go, as the code lines in client.go are a bit excessive.
Signed-off-by: okJiang <[email protected]>
Signed-off-by: okJiang <[email protected]>
WithCallerID(callerID caller.ID) RPCClient | ||
// WithCallerComponent returns a new RPCClient with the specified caller component. | ||
// Caller component refers to the components within the process. | ||
WithCallerComponent(callerComponent caller.Component) RPCClient |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we provide an automatic method to ingest the CallerID and Component? Like:
package processutil
import "os"
// GetCallerID returns the name of the currently running process
func GetCallerID() string {
return os.Args[0]
}
func GetTheComponent() string {
// Get the program counter for the calling function
pc, _, _, ok := runtime.Caller(1)
if !ok {
return "unknown"
}
// Retrieve the full function name, including the package path
fullFuncName := runtime.FuncForPC(pc).Name()
// Find the last slash, which separates the package path from the function name
lastSlash := strings.LastIndex(fullFuncName, "/")
if lastSlash == -1 {
// No slash, use the last period instead, which separates the package and function
lastSlash = strings.LastIndex(fullFuncName, ".")
}
// Extract the package name
return fullFuncName[:lastSlash]
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very good suggestion👍, I will consider if there are any flaws
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps the HTTP client could also adopt this method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added these two functions to this pr. In the default situation, CreateClient
will set the callerID
and callerComponent
by these two functions. I removed callerID
input from CreateClient
and keep the callerComponent
to allow caller set component.
And I expose the upperLayer to allow user to set it. For example, client-go can set it to catch the real caller in TiDB.
How do you think about these changes?
Signed-off-by: okJiang <[email protected]>
…llerid-for-grpc Signed-off-by: okJiang <[email protected]>
Signed-off-by: okJiang <[email protected]>
Signed-off-by: okJiang <[email protected]>
Signed-off-by: okJiang <[email protected]>
Signed-off-by: okJiang <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rest lgtm
svrUrls: svrAddrs, | ||
tlsCfg: tlsCfg, | ||
option: newOption(), | ||
callerID: caller.GetCallerID(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not move to innerClient, and make callerComponent as ClientOption
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What you said is exactly what I thought at the beginning. You can see it here
The ClientOption
is not actually universal; if we want to apply it across all interfaces, we need to further organize the various options. Therefore, I adopted @JmPotato 's suggestion. In my view, I can accept both implementation methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think @JmPotato's suggestion also doesn't require changing the function signature. However, if you intend to require the client to set the component name, I'm fine with changing it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I intend to require the client to set it.
What problem does this PR solve?
Issue Number: Ref #8593
What is changed and how does it work?
Check List
Tests
Release note