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

RSDK-9818: Annotate gRPC requests from modules to the viam-server with module names. #4749

Merged
merged 5 commits into from
Jan 30, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
comments
dgottlieb committed Jan 28, 2025
commit bfda26d91ec069f3ff33d56d55b60dc2fa024a25
3 changes: 2 additions & 1 deletion module/module.go
Original file line number Diff line number Diff line change
@@ -175,7 +175,8 @@ type peerResourceState struct {

// Module represents an external resource module that services components/services.
type Module struct {
// The name of the module as per the robot config.
// The name of the module as per the robot config. This value is communicated via the
// `VIAM_MODULE_NAME` env var.
name string

shutdownCtx context.Context
6 changes: 2 additions & 4 deletions module/testmodule/main.go
Original file line number Diff line number Diff line change
@@ -108,10 +108,8 @@ func newHelper(
ctx context.Context, deps resource.Dependencies, conf resource.Config, logger logging.Logger,
) (resource.Resource, error) {
var dependsOnSensor sensor.Sensor
Copy link
Member

Choose a reason for hiding this comment

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

[opt] Doesn't really matter, but generally I've seen FromDependencies used instead of for loop searches like the one you're doing.

Copy link
Member Author

Choose a reason for hiding this comment

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

I made a change, but I feel there's still some awkwardness.

I think the trouble arises because this "helper" model is "schema-less". Most tests aren't creating this with dependencies (obviously as per needing this change). And if they did want dependencies, it's not clear they'd want a sensor one? I don't think there's really a way to make this dependency parsing usage for "helper" be forward compatible.

Copy link
Member

Choose a reason for hiding this comment

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

Cool; yeah it's still awkward, sorry about that. What you have seems fine. I think you're right that if we wanted this to "look good" (and I don't really care too much since this is just testing code) we'd need a type for helper configs and probably an associated Validate method.

for _, resObj := range deps {
if resSensor, ok := resObj.(sensor.Sensor); ok {
dependsOnSensor = resSensor
}
if len(conf.DependsOn) > 0 {
dependsOnSensor, err := sensor.FromDependencies(deps, conf.DependsOn[0])
}

if len(deps) > 0 && dependsOnSensor == nil {
2 changes: 1 addition & 1 deletion robot/client/client_options.go
Original file line number Diff line number Diff line change
@@ -59,7 +59,7 @@ func newFuncRobotClientOption(f func(*robotClientOpts)) *funcRobotClientOption {
}

// WithModName attaches a unary interceptor that attaches the module name for each outgoing gRPC
// request.
// request. Should only be used in Viam module library code.
func WithModName(modName string) RobotClientOption {
return newFuncRobotClientOption(func(o *robotClientOpts) {
o.modName = modName