-
Notifications
You must be signed in to change notification settings - Fork 2.8k
/
hubble.go
43 lines (38 loc) · 1.31 KB
/
hubble.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// SPDX-License-Identifier: Apache-2.0
// Copyright Authors of Cilium
package helpers
import (
"context"
"fmt"
"strings"
)
const (
// older versions of the Hubble CLI use a different default path
hubbleSock = "unix:///var/run/cilium/hubble.sock"
)
// HubbleObserve runs `hubble observe --output=jsonpb <args>`. JSON output is
// enabled such that CmdRes.FilterLines may be used to grep for specific events
// in the output.
func (s *SSHMeta) HubbleObserve(args ...string) *CmdRes {
argsCoalesced := ""
if len(args) > 0 {
argsCoalesced = strings.Join(args, " ")
}
hubbleCmd := fmt.Sprintf("hubble observe --server=%q --output=jsonpb %s",
hubbleSock, argsCoalesced)
return s.Exec(hubbleCmd)
}
// HubbleObserveFollow runs `hubble observe --follow --output=jsonpb <args>`. The
// command is running in the background and will be terminated only once ctx
// is cancelled. JSON output is enabled such that
// CmdRes.WaitUntilMatchFilterLine may be used to wait for specific events in
// the output.
func (s *SSHMeta) HubbleObserveFollow(ctx context.Context, args ...string) *CmdRes {
argsCoalesced := ""
if len(args) > 0 {
argsCoalesced = strings.Join(args, " ")
}
hubbleCmd := fmt.Sprintf("hubble observe --server=%q --follow --output=jsonpb %s",
hubbleSock, argsCoalesced)
return s.ExecInBackground(ctx, hubbleCmd)
}