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
ci: Add Hubble helpers #11232
ci: Add Hubble helpers #11232
Conversation
test-me-please |
20ff8dc
to
d52b6d1
Compare
I've removed the |
test-me-please |
Put back into draft mode, since the follow mode locally has shown flakes due to cilium/hubble#131 (comment) Edit: This has been fixed. |
d52b6d1
to
e77d50e
Compare
test-me-please Edit: Hit #10538 |
test-me-please |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome
test/helpers/kubectl.go
Outdated
res := kub.ExecShort(fmt.Sprintf( | ||
"%s -n %s get pods -l k8s-app=hubble-cli %s", KubectlCmd, namespace, filter)) | ||
if !res.WasSuccessful() { | ||
return "", fmt.Errorf("Cilium pod not found on node '%s'", node) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know it's existing code but would be great to add:
Add : %s", node, res.OutputPrettyPrint())
test/helpers/cmd.go
Outdated
return false | ||
} | ||
|
||
err = WithTimeout( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might want to use the new WaitUntilTrue()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what you are referring to? I did not find any references to WaitUntilTrue
?
Edit: Ah, nevermind. I believe you meant RepeatUntilTrue!
ctx, cancel := context.WithTimeout(context.Background(), helpers.MidCommandTimeout) | ||
defer cancel() | ||
follow := kubectl.HubbleObserveFollow(ctx, hubbleNamespace, hubblePodK8s1, fmt.Sprintf( | ||
"--last 1 --type trace --from-pod %s/%s --to-namespace %s --to-label %s --to-port %d", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you want --last 1
with follow?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is intentional, yes. It's supposed to address a potential race:
The hubble observe --follow
process is started in the background. Therefore, there is a small possibility that we proceed with the curl request before the --follow
process in the background is actually receiving flows yset. Therefore, --follow
would miss the curl request, causing the test to fail. By introducing --last
, we don't care which happens first: If the curl request happened before, we can still get it from the ring buffer thanks to --last
, if the curl request happend later, then we will receive it thanks to follow-mode.
e77d50e
to
8d4710f
Compare
test-me-please |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good overall, two comments inline.
test/helpers/cmd.go
Outdated
// FilterLines works like Filter, but applies the JSONPath filter to each line | ||
// separately and returns returns a FilterBuffer for each line. An error is | ||
// returned only for the first line which cannot be unmarshalled. | ||
func (res *CmdRes) FilterLines(filter string) ([]FilterBuffer, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this used anywhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not yet. However, I expect this to be used in the Hubble tests we will be adding in the upcoming days. If you feel this addition is premature, I can remove it again.
8d4710f
to
7ac2eb6
Compare
test-me-please |
1 similar comment
test-me-please |
test-me-please |
This allows tests to connect to a Hubble client running on a specific node, e.g. to inspect the flows of the cilium-embedded Hubble server. Signed-off-by: Sebastian Wicki <sebastian@isovalent.com>
This commit adds the `HubbleObserve` and `HubbleObserveFollow` helpers to run `hubble observe` commands via Ginkgo. Support for newline- delimited JSON is added to `CmdRes`, allowing to apply JSONPath filters line by line. `helpers.Kubectl`: - `HubbleObserve()` runs `hubble observe --json` on the specified pod and waits for its completion. - `HubbleObserveFollow()` runs `hubble observe --json --follow` on the specified pod in the background (e.g. to combine with `WaitUntilMatchFilterLine()` below). `helpers.CmdRes`: - `FilterLines()` applies a JSONPath filter to each line of the output and returns its result (similar to the existing `Filter` method, but supports newline-delimited JSON). - `WaitUntilMatchFilterLine()` applies a JSONPath filter to each line of the output and waits until a line matches a custom string. - `WaitUntilMatchFilterLineTimeout()` same as above, but with a custom timeout. Signed-off-by: Sebastian Wicki <sebastian@isovalent.com>
This switches the Hubble CI skeleton to use the new `--follow` based helpers and JSONPath filters. Signed-off-by: Sebastian Wicki <sebastian@isovalent.com>
retest-runtime Edit: Rebased |
7ac2eb6
to
3f1f6f0
Compare
test-me-please |
retest-4.9 |
retest-net-next |
1 similar comment
retest-net-next |
All required tests passed (except |
This PR adds various helpers to make it easier to invoke Hubble from Ginkgo:
helpers.Kubectl
:GetHubbleClientPodOnNode()
obtains the name of the hubble-cli pod running on a particular node by its name (mirrors GetCiliumPodOnNode`).GetHubbleClientPodOnNodeWithLabel()
obtains the name of the hubble-cli running on a node by label (mirrors GetCiliumPodOnNodeWithLabel`).HubbleObserve()
runshubble observe --json
on the specified pod and waits for its completion.HubbleObserveFollow()
runshubble observe --json --follow
on the specified pod in the background (e.g. to combine withWaitUntilMatchFilterLine()
below).helpers.CmdRes
:FilterLines()
applies a JSONPath filter to each line of the output and returns its result (similar to the existingFilter
method, but supports newline-delimited JSON).WaitUntilMatchFilterLine()
applies a JSONPath filter to each line of the output and waits until a line matches a custom string.WaitUntilMatchFilterLineTimeout()
same as above, but with a custom timeout.In addition, aExpectHubbleClientReady()
helper is added and invoked as part of the Cilium deployment, which deployes hubble-cli pods if theglobal.hubble.cli.enabled
Helm option is set.The existing Hubble skeleton is adapted to use these new helpers.