Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion test/metricsviz/metricsviz.go
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,8 @@ func Parse(logs string, hasPrefix bool) (*Data, error) {
if len(tabularData) != len(header)+1 {
return nil, fmt.Errorf("invalid data line: %q with %d components which does not match header which has %d components. This is likely due to a log buffer overrun or similar issue causing the line to be cut off; please configure the container or the runtime to allow higher logging volume", line, len(tabularData), len(header))
}
offsetNanos, err := strconv.ParseUint(tabularData[0], 10, 64)
// Offsets must fit in time.Duration without becoming negative.
offsetNanos, err := strconv.ParseUint(tabularData[0], 10, 63)
if err != nil {
return nil, fmt.Errorf("invalid data line: %q (bad timestamp: %w)", line, err)
}
Expand Down
23 changes: 23 additions & 0 deletions test/metricsviz/metricsviz_cli/metricsviz_cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ package metricsviz_cli_test

import (
"context"
"errors"
"fmt"
"math"
"math/rand/v2"
"os"
"os/exec"
"path"
"strconv"
"strings"
"testing"
"time"
Expand All @@ -31,6 +34,26 @@ import (
"gvisor.dev/gvisor/test/metricsviz"
)

func TestTimestampOffset(t *testing.T) {
for _, tc := range []struct {
offset uint64
wantErr error
}{
{offset: 0},
{offset: math.MaxInt64},
{offset: math.MaxInt64 + 1, wantErr: strconv.ErrRange},
{offset: math.MaxUint64, wantErr: strconv.ErrRange},
} {
t.Run(strconv.FormatUint(tc.offset, 10), func(t *testing.T) {
logs := fmt.Sprintf("%s/counter\t{}\n%s1\n%s\t/counter\n%d\t1\n",
metric.MetricsMetaIndicator, metric.MetricsStartTimeIndicator, metric.TimeColumn, tc.offset)
if _, err := metricsviz.Parse(logs, false); !errors.Is(err, tc.wantErr) {
t.Fatalf("Parse() error = %v, want %v", err, tc.wantErr)
}
})
}
}

func TestMetricsvizCLI(t *testing.T) {
ctx := context.Background()
cliPath, err := testutil.FindFile("test/metricsviz/metricsviz_cli/metricsviz_cli")
Expand Down
Loading