gVisor metrics: Re-introduce unimplemented syscall counter metric.

Performance optimizations have made this metric cheap to add: cl/524419594,
cl/524419591.

PiperOrigin-RevId: 526187318
This commit is contained in:
Etienne Perot
2023-04-21 18:41:32 -07:00
committed by gVisor bot
parent 061b4578de
commit f3d91c753f
2 changed files with 18 additions and 12 deletions
+13 -4
View File
@@ -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)
}
+5 -8
View File
@@ -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 */ {