From 35d0572151e7e92dcefcf227bea1a1512914a9ae Mon Sep 17 00:00:00 2001 From: kadern0 Date: Sun, 12 Apr 2020 12:12:45 +1000 Subject: [PATCH] Added extra check for sorting time Duration and int strings Signed-off-by: kadern0 --- CHANGELOG.md | 2 +- cmd/thanos/bucket.go | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 017ec2e415..72a13749da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,7 @@ We use *breaking* word for marking changes that are not backward compatible (rel ## Unreleased ### Fixed - +- [#2416](https://github.com/thanos-io/thanos/pull/2416) Bucket: Fixes issue #2416 bug in `inspect --sort-by` doesn't work correctly in all cases - [#2288](https://github.com/thanos-io/thanos/pull/2288) Ruler: Fixes issue #2281 bug in ruler with parsing query addr with path prefix - [#2238](https://github.com/thanos-io/thanos/pull/2238) Ruler: Fixed Issue #2204 bug in alert queue signalling filled up queue and alerts were dropped - [#2231](https://github.com/thanos-io/thanos/pull/2231) Bucket Web - Sort chunks by thanos.downsample.resolution for better grouping diff --git a/cmd/thanos/bucket.go b/cmd/thanos/bucket.go index 375814fc68..0b75fa55d3 100644 --- a/cmd/thanos/bucket.go +++ b/cmd/thanos/bucket.go @@ -582,10 +582,21 @@ func (t Table) Less(i, j int) bool { } func compare(s1, s2 string) bool { + // Values can be either Time, Duration, comma-delimited integers or strings. s1Time, s1Err := time.Parse("02-01-2006 15:04:05", s1) s2Time, s2Err := time.Parse("02-01-2006 15:04:05", s2) if s1Err != nil || s2Err != nil { - return s1 < s2 + s1Duration, s1Err := time.ParseDuration(s1) + s2Duration, s2Err := time.ParseDuration(s2) + if s1Err != nil || s2Err != nil { + s1Int, s1Err := strconv.ParseUint(strings.Replace(s1, ",", "", -1), 10, 64) + s2Int, s2Err := strconv.ParseUint(strings.Replace(s2, ",", "", -1), 10, 64) + if s1Err != nil || s2Err != nil { + return s1 < s2 + } + return s1Int < s2Int + } + return s1Duration < s2Duration } return s1Time.Before(s2Time) }