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

[DATA-850] Support tags in CLI command #1714

Merged
merged 8 commits into from
Jan 3, 2023

Conversation

tahiyasalam
Copy link
Member

No description provided.

@viambot viambot added the safe to test This pull request is marked safe to test from a trusted zone label Dec 28, 2022
@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 Dec 28, 2022
@tahiyasalam tahiyasalam marked this pull request as ready for review December 28, 2022 21:05
cli/cmd/main.go Outdated
Tags: c.StringSlice(dataFlagTags),
}
}
if c.String(dataFlagTaggedUntagged) != "" {
Copy link
Member Author

Choose a reason for hiding this comment

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

Thinking through how to incorporate tags and made sense to me have separate use cases for 1) filtering based on matching tags and then grabbing either 2) all tagged data or 3) all untagged data.

Very open to alternative ways of going about this

cli/cmd/main.go Outdated
}
case "untagged":
filter.TagsFilter = &datapb.TagsFilter{
Type: datapb.TagsFilterType_TAGS_FILTER_TYPE_TAGGED,
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like this should be untagged

Copy link
Member Author

Choose a reason for hiding this comment

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

thanks for the catch

cli/cmd/main.go Outdated
&cli.StringSliceFlag{
Name: dataFlagTags,
Required: false,
Usage: "indicates filtering based on matching tags",
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this usage message should indicate that it's going to return all data matching any of the passed tags vs those matching all of them. I think the default there is non-obvious, so good to be explicit

Copy link
Member Author

Choose a reason for hiding this comment

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

agreed, done

cli/cmd/main.go Outdated
@@ -303,6 +305,16 @@ func main() {
Required: false,
Usage: "ISO-8601 timestamp indicating the end of the interval filter",
},
&cli.StringFlag{
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like it's a little weird for this to be split across two commands, since both are for the end user use case of "give me data with tags <anything/nothing/specific-things>".

I think it might make sense for them to just be one command and "tagged" and "untagged" to basically be keywords to the dataFlagTags command, i.e. if they pass tags=tagged it would be equivalent to to dataFlagTaggedUntagged=tagged currently. Open to other opinions on how best to combine them, but I do think they should probably be combined

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that's a reasonable solution, agree that want to keep it simple in the CLI versus the explicit nested tags/types that we expose via the API.

So they can pass tags=tagged, tags=untagged, or tags=square,triangle,circle. Would explain that in the usage text, e.g. "indicates filtering based on data with tags. accepts tagged for all tagged data, untagged for all untagged data, or a list of tags for all data matching any of the tags"

If they're specifically only trying to filter on a single tag that's named "tagged" or "untagged" this fails but don't think we need to worry about that :)

Copy link
Member Author

Choose a reason for hiding this comment

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

done!

if they are trying to filter on "tagged" or "untagged",
think that tags=,tagged would do the trick

@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 Dec 29, 2022
@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 Dec 29, 2022
@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 Dec 29, 2022
Copy link
Contributor

@AaronCasas AaronCasas left a comment

Choose a reason for hiding this comment

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

Two quick questions on behavior with bad/invalid inputs!

cli/cmd/main.go Outdated
if c.String(dataFlagTaggedUntagged) != "" {
switch c.String(dataFlagTaggedUntagged) {
tagsLen := len(c.StringSlice(dataFlagTags))
switch c.StringSlice(dataFlagTags)[0] {
Copy link
Contributor

@AaronCasas AaronCasas Dec 30, 2022

Choose a reason for hiding this comment

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

Does this NPE if passed an empty list (if that's possible through the cli even)? If so, should probably add a len==0 check first

Copy link
Contributor

Choose a reason for hiding this comment

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

StringSlice() returns nil if not set, but imo for readability/usability, this and the above two checks can be if len(c.StringSlice(dataFlagTags)) > 0

In this case, makes it clear that it's valid to grab from the first index

Copy link
Contributor

@AaronCasas AaronCasas Dec 30, 2022

Choose a reason for hiding this comment

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

What if it's set but empty? Like --org_ids=a,b --tags= --robot_name=name. Or is that just interpreted as not being set?

Copy link
Contributor

Choose a reason for hiding this comment

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

Just ran it locally, it's interpreted as an array of len 1 with an empty string.

cli/cmd/main.go Outdated
case "tagged":
filter.TagsFilter = &datapb.TagsFilter{
Type: datapb.TagsFilterType_TAGS_FILTER_TYPE_TAGGED,
if tagsLen == 1 {
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens if tagsLen != 1? It looks like it might silently fail or behave in unexpected ways (however our backend responds if no filter is passed)

cli/cmd/main.go Outdated
&cli.StringSliceFlag{
Name: dataFlagTags,
Required: false,
Usage: "indicates filtering based on data with tags. accepts tagged for all tagged data, untagged for all untagged data, or a list of tags for all data matching any of the tags",
Copy link
Contributor

Choose a reason for hiding this comment

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

[nit] to shorten this up, can just be "tags filter. accepts ..."

cli/cmd/main.go Outdated
if c.String(dataFlagTaggedUntagged) != "" {
switch c.String(dataFlagTaggedUntagged) {
tagsLen := len(c.StringSlice(dataFlagTags))
switch c.StringSlice(dataFlagTags)[0] {
Copy link
Contributor

Choose a reason for hiding this comment

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

StringSlice() returns nil if not set, but imo for readability/usability, this and the above two checks can be if len(c.StringSlice(dataFlagTags)) > 0

In this case, makes it clear that it's valid to grab from the first index

@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 Dec 30, 2022
cli/cmd/main.go Outdated
switch c.StringSlice(dataFlagTags)[0] {
case "tagged":
if tagsLen == 1 {
if len(c.StringSlice(dataFlagTags)) == 1 {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this can be simplified with:

if len == 1 && [0] == tagged {
   // all tagged case
} else if len == 1 && [0] == untagged {
 // all untagged case
} else {
 // or case (the current else case)
}

Copy link
Member Author

Choose a reason for hiding this comment

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

yes you're right! ty

@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 Dec 30, 2022
Copy link
Contributor

@AaronCasas AaronCasas left a comment

Choose a reason for hiding this comment

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

One suggestion on a possible simplification of the nested if statement, but other than that looks great 🚀

Copy link
Contributor

@agreenb agreenb left a comment

Choose a reason for hiding this comment

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

Awesome work, this is really clean! 🚀

@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 Dec 30, 2022
@github-actions
Copy link
Contributor

Code Coverage

Package Line Rate Delta Health
go.viam.com/rdk/components/arm 56% 0.00%
go.viam.com/rdk/components/arm/universalrobots 41% 0.00%
go.viam.com/rdk/components/arm/xarm 2% 0.00%
go.viam.com/rdk/components/arm/yahboom 7% 0.00%
go.viam.com/rdk/components/audioinput 55% -0.34%
go.viam.com/rdk/components/base 63% 0.00%
go.viam.com/rdk/components/base/agilex 62% 0.00%
go.viam.com/rdk/components/base/boat 41% 0.00%
go.viam.com/rdk/components/base/wheeled 76% 0.00%
go.viam.com/rdk/components/board 68% 0.00%
go.viam.com/rdk/components/board/arduino 10% 0.00%
go.viam.com/rdk/components/board/commonsysfs 47% 0.00%
go.viam.com/rdk/components/board/fake 38% 0.00%
go.viam.com/rdk/components/board/numato 19% 0.00%
go.viam.com/rdk/components/board/pi 50% 0.00%
go.viam.com/rdk/components/camera 65% 0.00%
go.viam.com/rdk/components/camera/align 63% 0.00%
go.viam.com/rdk/components/camera/fake 67% 0.00%
go.viam.com/rdk/components/camera/ffmpeg 76% -1.43%
go.viam.com/rdk/components/camera/transformpipeline 78% -0.33%
go.viam.com/rdk/components/camera/videosource 50% 0.00%
go.viam.com/rdk/components/encoder/fake 77% 0.00%
go.viam.com/rdk/components/gantry 60% 0.00%
go.viam.com/rdk/components/gantry/multiaxis 84% 0.00%
go.viam.com/rdk/components/gantry/oneaxis 86% 0.00%
go.viam.com/rdk/components/generic 83% 0.00%
go.viam.com/rdk/components/gripper 68% 0.00%
go.viam.com/rdk/components/input 87% 0.00%
go.viam.com/rdk/components/input/gpio 84% 0.00%
go.viam.com/rdk/components/motor 77% 0.00%
go.viam.com/rdk/components/motor/dimensionengineering 63% 0.00%
go.viam.com/rdk/components/motor/dmc4000 69% 0.00%
go.viam.com/rdk/components/motor/fake 57% 0.00%
go.viam.com/rdk/components/motor/gpio 64% 0.00%
go.viam.com/rdk/components/motor/gpiostepper 56% -0.59%
go.viam.com/rdk/components/motor/tmcstepper 62% 0.00%
go.viam.com/rdk/components/movementsensor 75% 0.00%
go.viam.com/rdk/components/movementsensor/cameramono 40% 0.00%
go.viam.com/rdk/components/movementsensor/gpsnmea 37% 0.00%
go.viam.com/rdk/components/movementsensor/gpsrtk 28% 0.00%
go.viam.com/rdk/components/posetracker 86% 0.00%
go.viam.com/rdk/components/sensor 86% 0.00%
go.viam.com/rdk/components/sensor/ultrasonic 34% 0.00%
go.viam.com/rdk/components/servo 68% 0.00%
go.viam.com/rdk/components/servo/gpio 71% 0.00%
go.viam.com/rdk/config 76% 0.00%
go.viam.com/rdk/control 57% 0.00%
go.viam.com/rdk/data 79% 0.00%
go.viam.com/rdk/examples/customresources/demos/complexmodule 0% 0.00%
go.viam.com/rdk/examples/customresources/demos/remoteserver 0% 0.00%
go.viam.com/rdk/grpc 25% 0.00%
go.viam.com/rdk/ml 67% 0.00%
go.viam.com/rdk/ml/inference 70% 0.00%
go.viam.com/rdk/module 64% 0.00%
go.viam.com/rdk/module/modmanager 79% 0.00%
go.viam.com/rdk/motionplan 59% -0.10%
go.viam.com/rdk/octree 98% 0.00%
go.viam.com/rdk/operation 82% 0.00%
go.viam.com/rdk/pointcloud 72% +0.09%
go.viam.com/rdk/protoutils 59% 0.00%
go.viam.com/rdk/referenceframe 70% 0.00%
go.viam.com/rdk/registry 89% 0.00%
go.viam.com/rdk/resource 84% 0.00%
go.viam.com/rdk/rimage 78% 0.00%
go.viam.com/rdk/rimage/depthadapter 94% 0.00%
go.viam.com/rdk/rimage/transform 73% 0.00%
go.viam.com/rdk/rimage/transform/cmd/extrinsic_calibration 67% 0.00%
go.viam.com/rdk/robot 85% 0.00%
go.viam.com/rdk/robot/client 82% 0.00%
go.viam.com/rdk/robot/framesystem 68% 0.00%
go.viam.com/rdk/robot/impl 81% 0.00%
go.viam.com/rdk/robot/server 59% 0.00%
go.viam.com/rdk/robot/web 62% 0.00%
go.viam.com/rdk/robot/web/stream 87% 0.00%
go.viam.com/rdk/services/armremotecontrol 71% 0.00%
go.viam.com/rdk/services/armremotecontrol/builtin 52% 0.00%
go.viam.com/rdk/services/baseremotecontrol 71% 0.00%
go.viam.com/rdk/services/baseremotecontrol/builtin 79% 0.00%
go.viam.com/rdk/services/datamanager 79% 0.00%
go.viam.com/rdk/services/datamanager/builtin 78% 0.00%
go.viam.com/rdk/services/datamanager/datacapture 70% 0.00%
go.viam.com/rdk/services/datamanager/datasync 0% 0.00%
go.viam.com/rdk/services/motion 63% 0.00%
go.viam.com/rdk/services/motion/builtin 88% 0.00%
go.viam.com/rdk/services/navigation 53% 0.00%
go.viam.com/rdk/services/sensors 77% 0.00%
go.viam.com/rdk/services/sensors/builtin 97% 0.00%
go.viam.com/rdk/services/shell 14% 0.00%
go.viam.com/rdk/services/slam 84% 0.00%
go.viam.com/rdk/services/slam/builtin 72% 0.00%
go.viam.com/rdk/services/vision 80% 0.00%
go.viam.com/rdk/services/vision/builtin 74% 0.00%
go.viam.com/rdk/session 97% 0.00%
go.viam.com/rdk/spatialmath 83% 0.00%
go.viam.com/rdk/subtype 92% 0.00%
go.viam.com/rdk/utils 72% -0.18%
go.viam.com/rdk/vision 26% 0.00%
go.viam.com/rdk/vision/chess 80% 0.00%
go.viam.com/rdk/vision/delaunay 87% 0.00%
go.viam.com/rdk/vision/keypoints 92% 0.00%
go.viam.com/rdk/vision/objectdetection 82% 0.00%
go.viam.com/rdk/vision/odometry 60% 0.00%
go.viam.com/rdk/vision/odometry/cmd 0% 0.00%
go.viam.com/rdk/vision/segmentation 49% 0.00%
go.viam.com/rdk/web/server 25% 0.00%
Summary 66% (20717 / 31618) -0.02%

@tahiyasalam tahiyasalam merged commit c140995 into viamrobotics:main Jan 3, 2023
@tahiyasalam tahiyasalam deleted the cli-tags branch January 3, 2023 16:16
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