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-9261] Initial clean up of webcam.go #4555

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

hexbabe
Copy link
Member

@hexbabe hexbabe commented Nov 13, 2024

Summary

Let's put the numerous private helpers above their caller and arrange this file to be more readable. Additionally we remove some vestigial logic that doesn't belong anymore.

95% of changes are syntax, var renaming, function rearranging, comment additions and updates.
The only three semantic changes made:

  1. [RSDK-9261] Initial clean up of webcam.go #4555 (comment)
  2. [RSDK-9261] Initial clean up of webcam.go #4555 (comment)
  3. [RSDK-9261] Initial clean up of webcam.go #4555 (comment)

Manual testing

Tested using go run with two webcams. Made sure hot swap and discovery and stream look good.

Tip for reviewing

Diff best viewed in split mode

Screenshot 2024-11-13 at 1 57 32 PM

Reminder for myself to merge in the Go interface PR before this one to avoid conflicts with the more high priority one

@viambot viambot added the safe to test This pull request is marked safe to test from a trusted zone label Nov 13, 2024
@hexbabe hexbabe changed the title [RSDK-9261] Clean up webcam.go [RSDK-9261] Initial clean up of webcam.go Nov 13, 2024
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Nov 13, 2024
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Nov 13, 2024
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Nov 13, 2024
Copy link
Member

@randhid randhid left a comment

Choose a reason for hiding this comment

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

Looks good, definitley merge in after the camera interface pr, and one request about the two loggers that maybe would be bets left to a follow up pr, feel free to comment exactly that.

Comment on lines 333 to 334
logger logging.Logger
originalLogger logging.Logger
Copy link
Member

Choose a reason for hiding this comment

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

Can we try to just have one?

Copy link
Member

Choose a reason for hiding this comment

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

I guess the separation is used for log search when path/label changes during reconnects.

c.logger = c.originalLogger.WithFields("camera_label", c.targetPath)

I think we can preserve the log structure for queryablity with multiple fields. something like:

logger: logger.WithFields(logrus.Fields{
    "camera_name":  conf.ResourceName().ShortName(),
    "camera_label": c.targetPath,
}),

Copy link
Member

Choose a reason for hiding this comment

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

I don't see the "camera_label" logger anywhere in NewWebCam, where are you looking?

Copy link
Member

Choose a reason for hiding this comment

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

It happens in reconnectCamera here.

Copy link
Member Author

@hexbabe hexbabe Nov 14, 2024

Choose a reason for hiding this comment

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

Talked to @dgottlieb and we now have the adapter support between the zap logger and our rdk logger i.e. we can assign the return value of WithFields to logger instead of having to use originalLogger to do so.

components/camera/videosource/webcam.go Outdated Show resolved Hide resolved
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Nov 13, 2024
components/camera/videosource/webcam.go Show resolved Hide resolved
components/camera/videosource/webcam.go Show resolved Hide resolved
Comment on lines 333 to 334
logger logging.Logger
originalLogger logging.Logger
Copy link
Member

Choose a reason for hiding this comment

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

I guess the separation is used for log search when path/label changes during reconnects.

c.logger = c.originalLogger.WithFields("camera_label", c.targetPath)

I think we can preserve the log structure for queryablity with multiple fields. something like:

logger: logger.WithFields(logrus.Fields{
    "camera_name":  conf.ResourceName().ShortName(),
    "camera_label": c.targetPath,
}),

components/camera/videosource/webcam.go Show resolved Hide resolved
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Nov 13, 2024
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Nov 13, 2024
Comment on lines 333 to 334
logger logging.Logger
originalLogger logging.Logger
Copy link
Member

Choose a reason for hiding this comment

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

It happens in reconnectCamera here.

@viambot viambot removed the safe to test This pull request is marked safe to test from a trusted zone label Nov 14, 2024
@viambot viambot added the safe to test This pull request is marked safe to test from a trusted zone label Nov 14, 2024
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
safe to test This pull request is marked safe to test from a trusted zone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants