From a2c3dd3e8375bcdcd47d7a92072d249a999aeef1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 27 Jul 2023 01:34:29 +0000 Subject: [PATCH 1/3] build(deps): bump github.com/ogen-go/ogen from 0.71.1 to 0.72.0 Bumps [github.com/ogen-go/ogen](https://github.com/ogen-go/ogen) from 0.71.1 to 0.72.0. - [Release notes](https://github.com/ogen-go/ogen/releases) - [Commits](https://github.com/ogen-go/ogen/compare/v0.71.1...v0.72.0) --- updated-dependencies: - dependency-name: github.com/ogen-go/ogen dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- go.mod | 4 ++-- go.sum | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 84cda4b5..1cd382a5 100644 --- a/go.mod +++ b/go.mod @@ -16,7 +16,7 @@ require ( github.com/go-faster/tcpproxy v0.1.0 github.com/go-logfmt/logfmt v0.6.0 github.com/google/uuid v1.3.0 - github.com/ogen-go/ogen v0.71.1 + github.com/ogen-go/ogen v0.72.0 github.com/opentracing/opentracing-go v1.2.0 github.com/prometheus/common v0.44.0 github.com/prometheus/prometheus v0.46.0 @@ -45,7 +45,7 @@ require ( go.ytsaurus.tech/library/go/core/log v0.0.3 go.ytsaurus.tech/yt/go v0.0.6 go4.org/netipx v0.0.0-20230303233057-f1b76eb4bb35 - golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1 + golang.org/x/exp v0.0.0-20230725093048-515e97ebf090 golang.org/x/sync v0.3.0 golang.org/x/tools v0.11.0 google.golang.org/grpc v1.56.2 diff --git a/go.sum b/go.sum index 84284d45..1481231b 100644 --- a/go.sum +++ b/go.sum @@ -355,8 +355,8 @@ github.com/mrunalp/fileutils v0.5.0/go.mod h1:M1WthSahJixYnrXQl/DFQuteStB1weuxD2 github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/npillmayer/nestext v0.1.3/go.mod h1:h2lrijH8jpicr25dFY+oAJLyzlya6jhnuG+zWp9L0Uk= -github.com/ogen-go/ogen v0.71.1 h1:X/TYjyi5XkXpuvLCRQYbPF/T4VJ/bjBNjdcW8ZW+NK0= -github.com/ogen-go/ogen v0.71.1/go.mod h1:DN3Tv8Zqla1f0JYUANyR7aEb9sRHwIwrxguv0pzVH6o= +github.com/ogen-go/ogen v0.72.0 h1:BmwbInSq2DRStoaEgF9od1da5bq1q+viZlwPS6qXQ1c= +github.com/ogen-go/ogen v0.72.0/go.mod h1:2SgZ9FRMXsuUhdTq23nFBFgMaXQl6yennmAnIs+hofM= github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA= github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= @@ -644,8 +644,8 @@ golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4 golang.org/x/crypto v0.11.0 h1:6Ewdq3tDic1mg5xRO4milcWCfMVQhI4NkqWWvqejpuA= golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= -golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1 h1:MGwJjxBy0HJshjDNfLsYO8xppfqWlA5ZT9OhtUUhTNw= -golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= +golang.org/x/exp v0.0.0-20230725093048-515e97ebf090 h1:Di6/M8l0O2lCLc6VVRWhgCiApHV8MnQurBnFSHsQtNY= +golang.org/x/exp v0.0.0-20230725093048-515e97ebf090/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= From 2e5ad25b190de93c2c8abc3e87a887c4da886f2f Mon Sep 17 00:00:00 2001 From: tdakkota Date: Fri, 28 Jul 2023 18:40:16 +0300 Subject: [PATCH 2/3] chore: commit generated files --- internal/lokiapi/oas_json_gen.go | 14 ++++++-------- internal/promapi/oas_json_gen.go | 24 ++++++++++++------------ internal/tempoapi/oas_json_gen.go | 19 +++++++++++++++++++ 3 files changed, 37 insertions(+), 20 deletions(-) diff --git a/internal/lokiapi/oas_json_gen.go b/internal/lokiapi/oas_json_gen.go index c242d694..a3da7ab8 100644 --- a/internal/lokiapi/oas_json_gen.go +++ b/internal/lokiapi/oas_json_gen.go @@ -938,31 +938,29 @@ func (s *QueryResponse) UnmarshalJSON(data []byte) error { // Encode encodes QueryResponseData as json. func (s QueryResponseData) Encode(e *jx.Encoder) { + e.ObjStart() + s.encodeFields(e) + e.ObjEnd() +} + +func (s QueryResponseData) encodeFields(e *jx.Encoder) { switch s.Type { case MatrixResultQueryResponseData: - e.ObjStart() e.FieldStart("resultType") e.Str("matrix") s.MatrixResult.encodeFields(e) - e.ObjEnd() case ScalarResultQueryResponseData: - e.ObjStart() e.FieldStart("resultType") e.Str("scalar") s.ScalarResult.encodeFields(e) - e.ObjEnd() case StreamsResultQueryResponseData: - e.ObjStart() e.FieldStart("resultType") e.Str("streams") s.StreamsResult.encodeFields(e) - e.ObjEnd() case VectorResultQueryResponseData: - e.ObjStart() e.FieldStart("resultType") e.Str("vector") s.VectorResult.encodeFields(e) - e.ObjEnd() } } diff --git a/internal/promapi/oas_json_gen.go b/internal/promapi/oas_json_gen.go index e64ff1f0..b142cfbb 100644 --- a/internal/promapi/oas_json_gen.go +++ b/internal/promapi/oas_json_gen.go @@ -491,31 +491,29 @@ func (s *AlertingRuleState) UnmarshalJSON(data []byte) error { // Encode encodes Data as json. func (s Data) Encode(e *jx.Encoder) { + e.ObjStart() + s.encodeFields(e) + e.ObjEnd() +} + +func (s Data) encodeFields(e *jx.Encoder) { switch s.Type { case MatrixData: - e.ObjStart() e.FieldStart("resultType") e.Str("matrix") s.Matrix.encodeFields(e) - e.ObjEnd() case ScalarData: - e.ObjStart() e.FieldStart("resultType") e.Str("scalar") s.Scalar.encodeFields(e) - e.ObjEnd() case StringData: - e.ObjStart() e.FieldStart("resultType") e.Str("string") s.String.encodeFields(e) - e.ObjEnd() case VectorData: - e.ObjStart() e.FieldStart("resultType") e.Str("vector") s.Vector.encodeFields(e) - e.ObjEnd() } } @@ -2913,19 +2911,21 @@ func (s *RecordingRule) UnmarshalJSON(data []byte) error { // Encode encodes Rule as json. func (s Rule) Encode(e *jx.Encoder) { + e.ObjStart() + s.encodeFields(e) + e.ObjEnd() +} + +func (s Rule) encodeFields(e *jx.Encoder) { switch s.Type { case AlertingRuleRule: - e.ObjStart() e.FieldStart("type") e.Str("alerting") s.AlertingRule.encodeFields(e) - e.ObjEnd() case RecordingRuleRule: - e.ObjStart() e.FieldStart("type") e.Str("recording") s.RecordingRule.encodeFields(e) - e.ObjEnd() } } diff --git a/internal/tempoapi/oas_json_gen.go b/internal/tempoapi/oas_json_gen.go index 41e1461d..2c739fe4 100644 --- a/internal/tempoapi/oas_json_gen.go +++ b/internal/tempoapi/oas_json_gen.go @@ -33,6 +33,25 @@ func (s AnyValue) Encode(e *jx.Encoder) { } } +func (s AnyValue) encodeFields(e *jx.Encoder) { + switch s.Type { + case StringValueAnyValue: + s.StringValue.encodeFields(e) + case BoolValueAnyValue: + s.BoolValue.encodeFields(e) + case IntValueAnyValue: + s.IntValue.encodeFields(e) + case DoubleValueAnyValue: + s.DoubleValue.encodeFields(e) + case ArrayValueAnyValue: + s.ArrayValue.encodeFields(e) + case KvlistValueAnyValue: + s.KvlistValue.encodeFields(e) + case BytesValueAnyValue: + s.BytesValue.encodeFields(e) + } +} + // Decode decodes AnyValue from json. func (s *AnyValue) Decode(d *jx.Decoder) error { if s == nil { From 708bbdd59486e369222684dee3b5e73cb9203be6 Mon Sep 17 00:00:00 2001 From: tdakkota Date: Fri, 28 Jul 2023 18:41:00 +0300 Subject: [PATCH 3/3] chore: update code due to `x/exp/slices` upgrade --- internal/cmp/cmp.go | 16 ++++++++++++++++ internal/logql/logqlengine/engine_test.go | 3 ++- .../logql/logqlengine/logqlmetric/prom_math.go | 8 +++++--- .../logql/logqlengine/logqlmetric/query_test.go | 9 +++++---- .../logql/logqlengine/logqlmetric/vector_agg.go | 7 ++++++- 5 files changed, 34 insertions(+), 9 deletions(-) create mode 100644 internal/cmp/cmp.go diff --git a/internal/cmp/cmp.go b/internal/cmp/cmp.go new file mode 100644 index 00000000..d089aa04 --- /dev/null +++ b/internal/cmp/cmp.go @@ -0,0 +1,16 @@ +// Package cmp is a simple utility package for comparing values. +package cmp + +import "golang.org/x/exp/constraints" + +// Compare is a comparator. +func Compare[T constraints.Ordered](a, b T) int { + switch { + case a < b: + return -1 + case a > b: + return 1 + default: + return 0 + } +} diff --git a/internal/logql/logqlengine/engine_test.go b/internal/logql/logqlengine/engine_test.go index 39c61f27..e948e546 100644 --- a/internal/logql/logqlengine/engine_test.go +++ b/internal/logql/logqlengine/engine_test.go @@ -12,6 +12,7 @@ import ( "go.opentelemetry.io/collector/pdata/pcommon" "golang.org/x/exp/slices" + "github.com/go-faster/oteldb/internal/cmp" "github.com/go-faster/oteldb/internal/iterators" "github.com/go-faster/oteldb/internal/logql" "github.com/go-faster/oteldb/internal/logstorage" @@ -339,7 +340,7 @@ func TestEngineEvalStream(t *testing.T) { }) } } - slices.SortFunc(entries, func(a, b entry) bool { return a.ts < b.ts }) + slices.SortFunc(entries, func(a, b entry) int { return cmp.Compare(a.ts, b.ts) }) assert.Len(t, entries, len(tt.wantData)) for i, e := range entries { diff --git a/internal/logql/logqlengine/logqlmetric/prom_math.go b/internal/logql/logqlengine/logqlmetric/prom_math.go index 2da8f38f..4d0fd85a 100644 --- a/internal/logql/logqlengine/logqlmetric/prom_math.go +++ b/internal/logql/logqlengine/logqlmetric/prom_math.go @@ -4,6 +4,8 @@ import ( "math" "golang.org/x/exp/slices" + + "github.com/go-faster/oteldb/internal/cmp" ) // Note: this file contains stats functions from Prometheus. @@ -25,11 +27,11 @@ func quantile(q float64, values []FPoint) float64 { if q > 1 { return math.Inf(+1) } - slices.SortFunc(values, func(a, b FPoint) bool { + slices.SortFunc(values, func(a, b FPoint) int { if math.IsNaN(a.Value) { - return true + return -1 } - return a.Value < b.Value + return cmp.Compare(a.Value, b.Value) }) n := float64(len(values)) diff --git a/internal/logql/logqlengine/logqlmetric/query_test.go b/internal/logql/logqlengine/logqlmetric/query_test.go index 0cdc1c1c..33736c9b 100644 --- a/internal/logql/logqlengine/logqlmetric/query_test.go +++ b/internal/logql/logqlengine/logqlmetric/query_test.go @@ -11,6 +11,7 @@ import ( "golang.org/x/exp/maps" "golang.org/x/exp/slices" + "github.com/go-faster/oteldb/internal/cmp" "github.com/go-faster/oteldb/internal/iterators" "github.com/go-faster/oteldb/internal/logql" "github.com/go-faster/oteldb/internal/lokiapi" @@ -18,8 +19,8 @@ import ( func testSampler(samples []SampledEntry) SampleSelector { return func(_ *logql.RangeAggregationExpr, _, _ time.Time) (iterators.Iterator[SampledEntry], error) { - slices.SortStableFunc(samples, func(a, b SampledEntry) bool { - return a.Timestamp < b.Timestamp + slices.SortStableFunc(samples, func(a, b SampledEntry) int { + return cmp.Compare(a.Timestamp, b.Timestamp) }) return iterators.Slice(samples), nil } @@ -489,10 +490,10 @@ func TestGroupedAggregation(t *testing.T) { } got = append(got, to) } - slices.SortFunc(got, func(a, b series) bool { + slices.SortFunc(got, func(a, b series) int { akey := a.labels["foo"] + a.labels["method"] bkey := b.labels["foo"] + b.labels["method"] - return akey < bkey + return cmp.Compare(akey, bkey) }) require.Equal(t, tt.expected, got) }) diff --git a/internal/logql/logqlengine/logqlmetric/vector_agg.go b/internal/logql/logqlengine/logqlmetric/vector_agg.go index ce33f287..7c42d7e4 100644 --- a/internal/logql/logqlengine/logqlmetric/vector_agg.go +++ b/internal/logql/logqlengine/logqlmetric/vector_agg.go @@ -180,7 +180,12 @@ func (i *vectorAggHeapIterator) Next(r *Step) bool { r.Samples = r.Samples[:0] for _, g := range result { samples := g.heap.elements - slices.SortFunc(samples, i.less) + slices.SortFunc(samples, func(a, b Sample) int { + if i.less(a, b) { + return -1 + } + return 0 + }) r.Samples = append(r.Samples, samples...) }