diff --git a/pkg/sentry/kernel/syscalls.go b/pkg/sentry/kernel/syscalls.go index 5d99d5ab3..fdf8b1c67 100644 --- a/pkg/sentry/kernel/syscalls.go +++ b/pkg/sentry/kernel/syscalls.go @@ -16,6 +16,7 @@ package kernel import ( "fmt" + "strconv" "google.golang.org/protobuf/proto" "gvisor.dev/gvisor/pkg/abi" @@ -390,8 +391,13 @@ func RegisterSyscallTable(s *SyscallTable) { } allSyscallTables = append(allSyscallTables, s) unimplementedSyscallCounterInit.Do(func() { - allowedValues := make([]string, 1) - // TODO(b/278108862): Add all other syscall numbers once doing so is possible. + allowedValues := make([]string, maxSyscallNum+2) + unimplementedSyscallNumbers = make(map[uintptr]string, len(allowedValues)) + for i := uintptr(0); i <= maxSyscallNum; i++ { + s := strconv.Itoa(int(i)) + allowedValues[i] = s + unimplementedSyscallNumbers[i] = s + } allowedValues[len(allowedValues)-1] = outOfRangeSyscallNumber unimplementedSyscallCounter = metric.MustCreateNewUint64Metric("unimplemented_syscalls", true, "Number of times the application tried to call an unimplemented syscall, broken down by syscall number", metric.NewField("sysno", allowedValues)) }) @@ -493,6 +499,9 @@ type SyscallInfo struct { // //go:nosplit func IncrementUnimplementedSyscallCounter(sysno uintptr) { - // TODO(b/278108862): Use the real syscall number once doing so is possible.s, found := unimplementedSyscallNumbers[sysno] - unimplementedSyscallCounter.Increment(outOfRangeSyscallNumber) + s, found := unimplementedSyscallNumbers[sysno] + if !found { + s = outOfRangeSyscallNumber + } + unimplementedSyscallCounter.Increment(s) } diff --git a/runsc/container/metric_server_test.go b/runsc/container/metric_server_test.go index fa4bb3946..1b954014b 100644 --- a/runsc/container/metric_server_test.go +++ b/runsc/container/metric_server_test.go @@ -859,29 +859,26 @@ func TestMetricServerDoesNotExportZeroValueCounters(t *testing.T) { for _, test := range []struct { cont *Container - sysno int + sysno uintptr wantExistence bool }{ {unimpl1, 1337, true}, - // TODO(b/278108862): Uncomment this: {unimpl1, 1338, false}, - // TODO(b/278108862): Uncomment this: {unimpl2, 1337, false}, + {unimpl1, 1338, false}, + {unimpl2, 1337, false}, {unimpl2, 1338, true}, } { - // TODO(b/278108862): Undo this hack: - test.sysno = -1 - t.Run(fmt.Sprintf("container %s syscall %d", test.cont.ID, test.sysno), func(t *testing.T) { check := func() error { got, _, err := metricDataPtr.GetPrometheusContainerInteger(metricclient.WantMetric{ Metric: "testmetric_unimplemented_syscalls", Sandbox: test.cont.sandboxID(), - ExtraLabels: map[string]string{"sysno": strconv.Itoa(test.sysno)}, + ExtraLabels: map[string]string{"sysno": strconv.Itoa(int(test.sysno))}, }) if test.wantExistence { if err != nil { return fmt.Errorf("cannot get unimplemented syscall metric for sysno=%d even though we expected its presence: %v", test.sysno, err) } - if got <= 0 /* TODO(b/278108862): Revert to got != 1 */ { + if got != 1 { return fmt.Errorf("expected counter value for unimplemented syscall %d be exactly 1, got %d", test.sysno, got) } } else /* !test.wantExistence */ {