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

Don't set --last if --input-file is specified #1153

Merged
merged 1 commit into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/observe/flows.go
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ func getFlowsRequest(ofilter *flowFilter, allowlist []string, denylist []string)
case selectorOpts.all:
// all is an alias for last=uint64_max
selectorOpts.last = ^uint64(0)
case selectorOpts.last == 0 && !selectorOpts.follow:
case selectorOpts.last == 0 && !selectorOpts.follow && otherOpts.inputFile == "":
// no specific parameters were provided, just a vanilla
// `hubble observe` in non-follow mode
selectorOpts.last = defaults.FlowPrintCount
Expand Down
15 changes: 15 additions & 0 deletions cmd/observe/flows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,18 @@ func Test_getFlowsRequest_ExperimentalFieldMask_non_json_output(t *testing.T) {
err := handleFlowArgs(os.Stdout, filter, false)
assert.ErrorContains(t, err, "not compatible")
}

func Test_getFlowsRequestWithInputFile(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we have a test where --last is used with --input-file too?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

good idea 🥰

// Don't set the number flag in GetFlowsRequest by default if --input-file is specified
selectorOpts.last = 0
otherOpts.inputFile = "myfile"
req, err := getFlowsRequest(newFlowFilter(), nil, nil)
assert.NoError(t, err)
assert.Equal(t, uint64(0), req.Number)

// .. but you can explicitly specify --last flag
selectorOpts.last = 42
req, err = getFlowsRequest(newFlowFilter(), nil, nil)
assert.NoError(t, err)
assert.Equal(t, uint64(42), req.Number)
}