Add sinks to runsc trace metadata output

Updates #4805

PiperOrigin-RevId: 465150097
This commit is contained in:
Fabricio Voznika
2022-08-03 14:32:46 -07:00
committed by gVisor bot
parent 1c220bf2a4
commit dc4cd669fc
5 changed files with 30 additions and 10 deletions
+1 -1
View File
@@ -225,7 +225,7 @@ func setFields(names []string, fields []FieldDesc) (FieldMask, error) {
}
func findSinkDesc(name string) (SinkDesc, error) {
if desc, ok := sinks[name]; ok {
if desc, ok := Sinks[name]; ok {
return desc, nil
}
return SinkDesc{}, fmt.Errorf("sink %q not found", name)
+7 -5
View File
@@ -61,11 +61,13 @@ const (
FieldSentryExecveBinaryInfo Field = iota
)
// Points is a map with all the Points registered in the system.
// Points is a map with all the trace points registered in the system.
var Points = map[string]PointDesc{}
var sinks = map[string]SinkDesc{}
// defaultContextFields are the fields present in most Points.
// Sinks is a map with all the sinks registered in the system.
var Sinks = map[string]SinkDesc{}
// defaultContextFields are the fields present in most trace points.
var defaultContextFields = []FieldDesc{
{
ID: FieldCtxtTime,
@@ -122,10 +124,10 @@ type SinkDesc struct {
// RegisterSink registers a new sink to make it discoverable.
func RegisterSink(sink SinkDesc) {
if _, ok := sinks[sink.Name]; ok {
if _, ok := Sinks[sink.Name]; ok {
panic(fmt.Sprintf("Sink %q already registered", sink.Name))
}
sinks[sink.Name] = sink
Sinks[sink.Name] = sink
}
// PointDesc describes a Point that is available to be configured.
+1 -1
View File
@@ -21,7 +21,7 @@ import (
func TestSinkRegistration(t *testing.T) {
sink := SinkDesc{Name: "test"}
RegisterSink(sink)
if _, ok := sinks["test"]; !ok {
if _, ok := Sinks["test"]; !ok {
t.Errorf("sink registration failed")
}
+5
View File
@@ -64,6 +64,11 @@ func (l *metadata) Execute(context.Context, *flag.FlagSet, ...interface{}) subco
ctxFields := fieldNames(pt.ContextFields)
fmt.Printf("Name: %s, optional fields: [%s], context fields: [%s]\n", pt.Name, strings.Join(optFields, "|"), strings.Join(ctxFields, "|"))
}
fmt.Printf("\nSINKS (%d)\n", len(seccheck.Sinks))
for _, sink := range seccheck.Sinks {
fmt.Printf("Name: %s\n", sink.Name)
}
return subcommands.ExitSuccess
}
+16 -3
View File
@@ -61,14 +61,24 @@ func (b *Builder) LoadAllPoints(runscPath string) error {
// The command above produces an output like the following:
// POINTS (907)
// Name: container/start, optional fields: [], context fields: [time|thread_id]
//
// SINKS (2)
// Name: remote
scanner := bufio.NewScanner(bytes.NewReader(out))
if !scanner.Scan() {
return fmt.Errorf("%q returned empty", cmd)
}
if !scanner.Scan() {
return fmt.Errorf("%q returned empty", cmd)
if line := scanner.Text(); !strings.HasPrefix(line, "POINTS (") {
return fmt.Errorf("%q missing POINTS header: %q", cmd, line)
}
for line := scanner.Text(); scanner.Scan(); line = scanner.Text() {
for scanner.Scan() {
line := scanner.Text()
if len(line) == 0 {
continue // Skip empty lines.
}
if strings.HasPrefix(line, "SINKS (") {
break // Starting SINKS section, POINTS section is over.
}
elems := strings.Split(line, ",")
if len(elems) != 3 {
return fmt.Errorf("invalid line: %q", line)
@@ -88,6 +98,9 @@ func (b *Builder) LoadAllPoints(runscPath string) error {
ContextFields: ctxFields,
})
}
if len(b.points) == 0 {
return fmt.Errorf("%q returned no points", cmd)
}
return scanner.Err()
}