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

bugtool: use gRPC instead of tetra CLI #1217

Merged
merged 1 commit into from
Jul 12, 2023
Merged
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
37 changes: 36 additions & 1 deletion pkg/bugtool/bugtool.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ import (
"strings"
"time"

"github.com/cilium/tetragon/api/v1/tetragon"
"github.com/cilium/tetragon/pkg/defaults"
"github.com/cilium/tetragon/pkg/logger"
"github.com/cilium/tetragon/pkg/policyfilter"
"go.uber.org/multierr"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"

"github.com/sirupsen/logrus"
"github.com/vishvananda/netlink"
Expand Down Expand Up @@ -224,8 +227,8 @@ func doBugtool(info *InitInfo, outFname string) error {
si.addTcInfo(tarWriter)
si.addBpftoolInfo(tarWriter)
si.addGopsInfo(tarWriter)
si.execCmd(tarWriter, "tetra_tracincpolicy_list.json", "tetra", "tracingpolicy", "list", "-o", "json")
si.dumpPolicyFilterMap(tarWriter)
si.addGrpcInfo(tarWriter)
return nil
}

Expand Down Expand Up @@ -493,3 +496,35 @@ func (s *bugtoolInfo) dumpPolicyFilterMap(tarWriter *tar.Writer) error {
}
return s.tarAddJson(tarWriter, policyfilter.MapName+".json", obj)
}

func (s *bugtoolInfo) addGrpcInfo(tarWriter *tar.Writer) {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
conn, err := grpc.DialContext(
ctx,
s.info.ServerAddr,
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithBlock(),
)
if err != nil {
s.multiLog.Warnf("failed to connect to %s: %v", s.info.ServerAddr, err)
return
}
defer conn.Close()
client := tetragon.NewFineGuidanceSensorsClient(conn)

res, err := client.ListTracingPolicies(ctx, &tetragon.ListTracingPoliciesRequest{})
if err != nil || res == nil {
s.multiLog.Warnf("failed to list tracing policies: %v", err)
return
}

fname := "tracing-policies.json"
err = s.tarAddJson(tarWriter, fname, res)
if err != nil {
s.multiLog.Warnf("failed to dump tracing policies: %v", err)
return
}

s.multiLog.Infof("dumped tracing policies in %s", fname)
}