DOCS-3699, DOCS-2567: Add module lifecycle and dependencies guidance#4156
DOCS-3699, DOCS-2567: Add module lifecycle and dependencies guidance#4156JessamyT merged 14 commits intoviamrobotics:mainfrom
Conversation
✅ Deploy Preview for viam-docs ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
| {{% tab name="Python" %}} | ||
|
|
||
| If you prefer to use explicit dependencies (for example, for an optional dependency), the steps are the same as for implicit dependencies above, except that you do not need to return the dependency from the `validate_config` method and can instead return an empty list: | ||
| If you prefer to use explicit dependencies (for example, for an optional dependency), the steps are the same as for implicit dependencies, except that you do not need to return the dependency from the `validate_config` method and can instead return an empty list: |
There was a problem hiding this comment.
I think that saying "for example, for an optional dependency" is wrong here. A resource will still wait for all resources declared in depends_on to be available before starting.
There was a problem hiding this comment.
We have two mechanisms for declaring dependencies which are essentially the same result. Implicit is more common than explicit
There was a problem hiding this comment.
What I mean by "optional" here is that if the user doesn't configure a "camera_name" at all, either in depends_on or in attributes, that the modular resource should still work. But I'm realizing the example I have here doesn't indicate that--I should make this validate_config explicit dependency example show "camera_name" as an optional attribute, and keep it as a required attribute for the implicit dependency example.
Is it true that people should use implicit dependencies for required things and explicit dependencies for optional things?
There was a problem hiding this comment.
I guess, is it currently possible for people to have an optional implicit dependency, or not until the upcoming work happens?
There was a problem hiding this comment.
No way to have an optional explicit dependency. Yeah you could make an implicit dependency optional. Its a bit annoying right now:
- See in validate that its not defined and don't return it as a dependency.
- In your implementation you check to make sure the dependency is not null and gracefully skip using it.
There was a problem hiding this comment.
To illuminate other reviewers: Based on offline sync, we were using "optional" in different ways--If a user does put something in depends_on, the resource won't currently start if the dependency doesn't start. What I was meaning with "optional" is it's optional for the user to even configure it at all. But sounds like you can do that with either implicit or explicit deps--it's all about how you implement validate.
Based on offline convo I will remove explicit dependencies since they just confuse users and aren't actually necessary except in cases of backwards compatibility.
| {{< /tabs >}} | ||
|
|
||
| {{% hiddencontent %}} | ||
| There is not currently an SDK method to access configuration attributes of dependencies in Python or Go, but in Python it is possible to use `get_robot_part` to return information including the whole configuration of a machine part, and then access the configuration attributes of the dependency from there. |
There was a problem hiding this comment.
Maybe this isn't right--looking into this more
|
@michaellee1019 I changed it to optional vs required but LMK if you think that is still confusing or overkill and it'd be better to just have one heading with "use dependencies" in general, with the required deps examples, and omit the optional examples. |
cheukt
left a comment
There was a problem hiding this comment.
did a quick pass, I'll be out next week so no need for my approval - if we want an opinion from netcode we can add @benjirewis
| {{< /tabs >}} | ||
|
|
||
| {{% hiddencontent %}} | ||
| There is not currently an SDK method to directly access configuration attributes of dependencies in Python or Go, but in Python it is possible to use `get_robot_part` to return information including the whole configuration of a machine part, and then access the configuration attributes of the dependency from there. |
There was a problem hiding this comment.
what does this mean? I think we would want to discourage users from looking at configs for other resources
There was a problem hiding this comment.
We got a chatbot question about this specifically (from Sean Yu) and the bot answer was incorrect so was hoping to fix it. This hidden content short code means it’s not visible on the page, only to the chatbot if someone specifically asks. But if we don’t want people to do this at all should I just change this to say “you can’t, period”?
There was a problem hiding this comment.
ok, I guess in that case this is fine - we should definitely discourage it tho
benjirewis
left a comment
There was a problem hiding this comment.
This is awesome! You guys do a great job of adding stuff around this somewhat opaque logic. Some comments and I can help further while Cheuk is on PTO.
| if cfg.CameraName == "" { | ||
| return nil, resource.NewConfigValidationFieldRequiredError(path, "camera_name") | ||
| } | ||
| if reflect.TypeOf(cfg.CameraName).Kind() != reflect.String { |
There was a problem hiding this comment.
I don't think you need this reflection check. cfg.CameraName will definitely be a string at this point.
There was a problem hiding this comment.
Does it get checked by viam-server automatically because CameraName string specifies type?json:"camera_name"
There was a problem hiding this comment.
Basically yep! It's not technically viam-server that does the conversion from proto to a golang string, but the Golang module library code does it and will error if the thing specified in JSON is not actually a string/cfg.CameraName will just "".
There was a problem hiding this comment.
Ah okay ty!! Wait it'll error or it'll assign it an empty string or both?
There was a problem hiding this comment.
Sorry for ambiguity! There will be an error during validation for the resource if camera_name is not a string in the JSON.
michaellee1019
left a comment
There was a problem hiding this comment.
Read through it and LGTM! A great improvement. I would double check on that comment thread with net code about the exact shutdown behavior. It might warrant a quick explanation about the overall timing, and then a more detailed section with the caveats about the shutdown timing based on the modules behavior. For example:
When `viam-server` shuts down, it attempts to stop all running modules. This can take up to x seconds depending on the response time required by a module to shut down.
And then a section that describes the shutdown and killing behavior.
|
Thanks! Benji okayed the suggestion on that thread via slack so I went ahead and committed now |
|
🔎💬 Inkeep AI search and chat service is syncing content for source 'Viam Docs (https://docs.viam.com)' |

Discovery service will be further fleshed out separately
Staging:
https://deploy-preview-4156--viam-docs.netlify.app/operate/get-started/other-hardware/#how-and-where-do-modules-run and https://deploy-preview-4156--viam-docs.netlify.app/operate/get-started/other-hardware/dependencies/