Skip to content

Commit

Permalink
Move experimentalFieldMask to separate struct
Browse files Browse the repository at this point in the history
Signed-off-by: Aleksander Mistewicz <amistewicz@google.com>
  • Loading branch information
AwesomePatrol committed Jun 21, 2023
1 parent c4f77d1 commit d3b8d41
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
4 changes: 2 additions & 2 deletions cmd/observe/flows.go
Original file line number Diff line number Diff line change
Expand Up @@ -702,8 +702,8 @@ func getFlowsRequest(ofilter *flowFilter, allowlist []string, denylist []string)
First: first,
}

if len(otherOpts.experimentalFieldMask) > 0 {
fm, err := fieldmaskpb.New(&flowpb.Flow{}, strings.Split(otherOpts.experimentalFieldMask, ",")...)
if len(experimentalOpts.fieldMask) > 0 {
fm, err := fieldmaskpb.New(&flowpb.Flow{}, strings.Split(experimentalOpts.fieldMask, ",")...)
if err != nil {
return nil, fmt.Errorf("failed to construct field mask: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/observe/flows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ denylist:

func Test_getFlowsRequest_ExperimentalFieldMask_valid(t *testing.T) {
selectorOpts.until = ""
otherOpts.experimentalFieldMask = "time,verdict"
experimentalOpts.fieldMask = "time,verdict"
filter := newFlowFilter()
req, err := getFlowsRequest(filter, nil, nil)
assert.NoError(t, err)
Expand All @@ -142,7 +142,7 @@ func Test_getFlowsRequest_ExperimentalFieldMask_valid(t *testing.T) {
}

func Test_getFlowsRequest_ExperimentalFieldMask_invalid(t *testing.T) {
otherOpts.experimentalFieldMask = "time,verdict,invalid-field"
experimentalOpts.fieldMask = "time,verdict,invalid-field"
filter := newFlowFilter()
_, err := getFlowsRequest(filter, nil, nil)
assert.ErrorContains(t, err, "invalid-field")
Expand Down
13 changes: 8 additions & 5 deletions cmd/observe/observe.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,13 @@ var (
}

otherOpts struct {
ignoreStderr bool
printRawFilters bool
inputFile string
experimentalFieldMask string
ignoreStderr bool
printRawFilters bool
inputFile string
}

experimentalOpts struct {
fieldMask string
}

printer *hubprinter.Printer
Expand Down Expand Up @@ -152,7 +155,7 @@ func init() {
otherFlags.StringVar(&otherOpts.inputFile, "input-file", "",
"Query flows from this file instead of the server. Use '-' to read from stdin.")

otherFlags.StringVar(&otherOpts.experimentalFieldMask, "experimental-field-mask", "",
otherFlags.StringVar(&experimentalOpts.fieldMask, "experimental-field-mask", "",
"Experimental: Comma-separated list of fields for mask. Fields not in the mask will be removed from server response.")
}

Expand Down

0 comments on commit d3b8d41

Please sign in to comment.