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

Add experimental-field-mask flags #1101

Merged

Conversation

AwesomePatrol
Copy link
Contributor

@AwesomePatrol AwesomePatrol commented Jun 21, 2023

Follow-up to change in cilium exposing a new experimental field in GetFlowsRequests: cilium/cilium#23198

Usage example with custom field mask and JSON output format:

% hubble observe --experimental-field-mask time,verdict --output jsonpb

Usage example with default field mask and default output format:

% hubble observe --experimental-use-default-field-masks

Example of providing invalid fieldmask:

% hubble observe --experimental-field-mask time,verdict,invalid --output jsonpb
failed to construct field mask: proto: invalid path "invalid" for message "flow.Flow"

Example of providing custom field mask for non-JSON output format:

% hubble observe --experimental-field-mask time,verdict
compact output format is not compatible with custom field mask

@AwesomePatrol AwesomePatrol requested a review from a team as a code owner June 21, 2023 15:19
@AwesomePatrol AwesomePatrol requested review from chancez and removed request for a team June 21, 2023 15:19
@maintainer-s-little-helper maintainer-s-little-helper bot added the dont-merge/needs-release-note-label PR is blocked until the release note is set label Jun 21, 2023
cmd/observe/observe.go Outdated Show resolved Hide resolved
cmd/observe/observe.go Outdated Show resolved Hide resolved
Copy link
Contributor

@chancez chancez left a comment

Choose a reason for hiding this comment

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

We can skip splitting inside getFlowsRequest if we switch to a StringSliceVar flag instead.

@AwesomePatrol AwesomePatrol force-pushed the add-flag-experimental-field-mask branch from d3b8d41 to 2e43cdf Compare June 22, 2023 07:14
@chancez chancez added ⌨️ area/cli Impacts the command line interface of any command in the repository. 🌟 kind/feature This introduces new functionality. release-note/major This PR introduces major new functionality to Hubble. and removed dont-merge/needs-release-note-label PR is blocked until the release note is set labels Jun 22, 2023
@kaworu
Copy link
Member

kaworu commented Jun 23, 2023

@chancez I'm hesitant to tag an experimental feature as release-note/major, so switching to release-note/minor instead. It won't have effect until the next release anyway, so please reply if you feel strongly about this.

@kaworu kaworu added release-note/minor This PR introduces functionality that users may find relevant to operating Hubble. and removed release-note/major This PR introduces major new functionality to Hubble. labels Jun 23, 2023
Copy link
Member

@kaworu kaworu left a comment

Choose a reason for hiding this comment

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

CI is unhappy about the observe help output test, please update cmd/observe_help.txt accordingly.

go run ./main.go observe --help > cmd/observe_help.txt
git add -p cmd/observe_help.txt

(avoid staging the hunk about the --config flag, keeping the %s template).

Copy link
Member

@kaworu kaworu left a comment

Choose a reason for hiding this comment

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

Thanks for the test fix @AwesomePatrol, one more thing:

Using the experimental flag (e.g. hubble observe --experimental-field-mask verdict) works well in combination with --output json, less so with other output formats:

% ./hubble observe --last 1 --experimental-field-mask verdict --output compact
N/A:  (unknown) <>  (unknown) UNKNOWN FORWARDED ()
N/A:  (unknown) <>  (unknown) UNKNOWN FORWARDED ()
% ./hubble observe --last 1 --experimental-field-mask verdict --output dict
  TIMESTAMP: N/A
     SOURCE:
DESTINATION:
       TYPE: UNKNOWN
    VERDICT: FORWARDED
    SUMMARY:
------------
  TIMESTAMP: N/A
     SOURCE:
DESTINATION:
       TYPE: UNKNOWN
    VERDICT: FORWARDED
    SUMMARY:
% ./hubble observe --last 1 --experimental-field-mask verdict --output tab
TIMESTAMP   SOURCE   DESTINATION   TYPE      VERDICT     SUMMARY
N/A                                UNKNOWN   FORWARDED
N/A                                UNKNOWN   FORWARDED
% ./hubble observe --last 1 --experimental-field-mask verdict --output json
{"flow":{"verdict":"FORWARDED"}}
{"flow":{"verdict":"FORWARDED"}}

I think we should

  1. disallow --experimental-field-mask when the output format is not JSON.
  2. For compact and dict/tab consider hardcoding a mask requesting only the fields used by the output format (see WriteProtoFlow).

@AwesomePatrol
Copy link
Contributor Author

AwesomePatrol commented Jul 3, 2023

I added another flag --experimental-use-default-field-masks that specifies if we should use the new experimental field when output format other than JSON is specified. It is disabled by default. Given backwards compatibility from protobuf it is likely safe to default to true.

I also added a test to verify that all fields needed by output formats are part of the default field mask (which currently captures a bit more data than necessary).

Copy link
Member

@kaworu kaworu left a comment

Choose a reason for hiding this comment

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

Thanks for the quick update @AwesomePatrol 🎉

Couple of nitpicking comments, other than that LGTM.

cmd/observe/flows.go Outdated Show resolved Hide resolved
cmd/observe/observe.go Outdated Show resolved Hide resolved
Follow-up to change in cilium exposing new experimental field in
requests: cilium/cilium#23198

Usage example:
  hubble observe --experimental-field-mask time,verdict

Signed-off-by: Aleksander Mistewicz <amistewicz@google.com>
It is gated behind experimental-use-default-field-masks command line
flag (defaults to false).

It also prints an error in all cases when attempting to use a custom
field mask with non-json output format.

Signed-off-by: Aleksander Mistewicz <amistewicz@google.com>
Signed-off-by: Aleksander Mistewicz <amistewicz@google.com>
@AwesomePatrol AwesomePatrol force-pushed the add-flag-experimental-field-mask branch from 034f42e to 6cd37a6 Compare July 4, 2023 10:25
@AwesomePatrol AwesomePatrol changed the title Add experimental-field-mask flag Add experimental-field-mask flags Jul 4, 2023
@kaworu kaworu merged commit f06e1e9 into cilium:master Jul 4, 2023
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⌨️ area/cli Impacts the command line interface of any command in the repository. 🌟 kind/feature This introduces new functionality. release-note/minor This PR introduces functionality that users may find relevant to operating Hubble.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants