Skip to content

Commit cef51d2

Browse files
committed
fix(observability-proxy): name the logs time out of range exactly
When both bounds were out of range the answer named one of them at random, as the check walked a map, and it printed the instant without its fraction, so a time one nanosecond past the last one vlselect can hold was shown as a time inside the range. The end is now checked first and the instant is printed in full; tests pin the inclusive bound. Assisted-by: LLM Signed-off-by: ZverGuy <[email protected]>
1 parent 3fb2c6f commit cef51d2

2 files changed

Lines changed: 30 additions & 5 deletions

File tree

‎internal/observabilityproxy/logsparams.go‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,11 @@ func window(in url.Values, now time.Time, lim LogsLimits) (time.Time, time.Time,
160160
if end.Sub(start) > lim.MaxRange {
161161
start = end.Add(-lim.MaxRange)
162162
}
163-
for k, t := range map[string]time.Time{"start": start, "end": end} {
164-
if herr := sendableTime(k, t); herr != nil {
165-
return time.Time{}, time.Time{}, herr
166-
}
163+
if herr := sendableTime("end", end); herr != nil {
164+
return time.Time{}, time.Time{}, herr
165+
}
166+
if herr := sendableTime("start", start); herr != nil {
167+
return time.Time{}, time.Time{}, herr
167168
}
168169
return start.UTC(), end.UTC(), nil
169170
}
@@ -337,7 +338,7 @@ func scaleDuration(f float64, unit time.Duration) (time.Duration, bool) {
337338
// actually sent are checked; an older start is clamped first.
338339
func sendableTime(key string, t time.Time) *HTTPError {
339340
if t.Before(time.Unix(0, math.MinInt64)) || t.After(time.Unix(0, math.MaxInt64)) {
340-
return errorf(http.StatusBadRequest, "invalid %s: %s is outside 1677..2262", key, t.Format(time.RFC3339))
341+
return errorf(http.StatusBadRequest, "invalid %s: %s is outside 1677..2262", key, t.UTC().Format(time.RFC3339Nano))
341342
}
342343
return nil
343344
}

‎internal/observabilityproxy/logsparams_test.go‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package observabilityproxy
1818

1919
import (
20+
"math"
2021
"net/http"
2122
"net/url"
2223
"sort"
@@ -408,3 +409,26 @@ func TestBuildLogsParamsOldTimesClamped(t *testing.T) {
408409
t.Errorf("start_offset = %s, want the %s cap", got, lim.MaxTailResume)
409410
}
410411
}
412+
413+
// TestBuildLogsParamsSendableBoundary pins the inclusive int64-nanosecond
414+
// bound and that the refusal names the instant exactly.
415+
func TestBuildLogsParamsSendableBoundary(t *testing.T) {
416+
last := time.Unix(0, math.MaxInt64).UTC()
417+
in := url.Values{"start": {last.Add(-time.Hour).Format(time.RFC3339Nano)}, "end": {last.Format(time.RFC3339Nano)}}
418+
if _, herr := BuildLogsParams("query", in, "tenant-a", testNow, testLimits()); herr != nil {
419+
t.Fatalf("the last int64 nanosecond refused: %v", herr)
420+
}
421+
past := last.Add(time.Nanosecond).Format(time.RFC3339Nano)
422+
in = url.Values{"start": {last.Add(-time.Hour).Format(time.RFC3339Nano)}, "end": {past}}
423+
_, herr := BuildLogsParams("query", in, "tenant-a", testNow, testLimits())
424+
if herr == nil || !strings.Contains(herr.Message, "invalid end") || !strings.Contains(herr.Message, past) {
425+
t.Fatalf("one nanosecond past answered %v, want end refused naming %s", herr, past)
426+
}
427+
// Both out of range: the answer names end, deterministically.
428+
for range 20 {
429+
_, herr := BuildLogsParams("query", url.Values{"start": {"0001-01-01T00:00:00Z"}, "end": {"0001-01-02T00:00:00Z"}}, "tenant-a", testNow, testLimits())
430+
if herr == nil || !strings.Contains(herr.Message, "invalid end") {
431+
t.Fatalf("answer = %v, want end named", herr)
432+
}
433+
}
434+
}

0 commit comments

Comments
 (0)