Skip to content

Commit

Permalink
Merge branch 'main' into feat/optional-tls-version
Browse files Browse the repository at this point in the history
Signed-off-by: pureiboi <[email protected]
  • Loading branch information
pureiboi committed Oct 29, 2024
2 parents 05b2e90 + a31af1d commit b370f3d
Show file tree
Hide file tree
Showing 29 changed files with 693 additions and 123 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re
- [#7679](https://github.com/thanos-io/thanos/pull/7679) Query: respect store.limit.* flags when evaluating queries
- [#7821](https://github.com/thanos-io/thanos/pull/7679) Query/Receive: Fix coroutine leak introduced in https://github.com/thanos-io/thanos/pull/7796.
- [#7843](https://github.com/thanos-io/thanos/pull/7843) Query Frontend: fix slow query logging for non-query endpoints.
- [#7852](https://github.com/thanos-io/thanos/pull/7852) Query Frontend: pass "stats" parameter forward to queriers and fix Prometheus stats merging.

### Added
- [#7763](https://github.com/thanos-io/thanos/pull/7763) Ruler: use native histograms for client latency metrics.
Expand All @@ -31,6 +32,7 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re
- [#7560](https://github.com/thanos-io/thanos/pull/7560) Query: Added the possibility of filtering rules by rule_name, rule_group or file to HTTP api.
- [#7652](https://github.com/thanos-io/thanos/pull/7652) Store: Implement metadata API limit in stores.
- [#7659](https://github.com/thanos-io/thanos/pull/7659) Receive: Add support for replication using [Cap'n Proto](https://capnproto.org/). This protocol has a lower CPU and memory footprint, which leads to a reduction in resource usage in Receivers. Before enabling it, make sure that all receivers are updated to a version which supports this replication method.
- [#7853](https://github.com/thanos-io/thanos/pull/7853) UI: Add support for selecting graph time range with mouse drag.
- [#7654](https://github.com/thanos-io/thanos/pull/7654) *: Add '--grpc-server-tls-min-version' flag to allow user to specify TLS version, otherwise default to TLS 1.3

### Changed
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ require (
go.elastic.co/apm/module/apmot v1.15.0
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0 // indirect
go.opentelemetry.io/otel v1.31.0
go.opentelemetry.io/otel/bridge/opentracing v1.29.0
go.opentelemetry.io/otel/bridge/opentracing v1.31.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.29.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.29.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.29.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2344,8 +2344,8 @@ go.opentelemetry.io/otel v1.21.0/go.mod h1:QZzNPQPm1zLX4gZK4cMi+71eaorMSGT3A4znn
go.opentelemetry.io/otel v1.22.0/go.mod h1:eoV4iAi3Ea8LkAEI9+GFT44O6T/D0GWAVFyZVCC6pMI=
go.opentelemetry.io/otel v1.31.0 h1:NsJcKPIW0D0H3NgzPDHmo0WW6SptzPdqg/L1zsIm2hY=
go.opentelemetry.io/otel v1.31.0/go.mod h1:O0C14Yl9FgkjqcCZAsE053C13OaddMYr/hz6clDkEJE=
go.opentelemetry.io/otel/bridge/opentracing v1.29.0 h1:qrife6xWXoBwBeif0/9nVr+18Gq3+st7kT2iTTKbu5o=
go.opentelemetry.io/otel/bridge/opentracing v1.29.0/go.mod h1:9MckCOAmd8dHQS92890ShcIwkVz/0tF/WvnMUMd9mGQ=
go.opentelemetry.io/otel/bridge/opentracing v1.31.0 h1:S6SA1IQdNHgfZfgkaWBKQqNIlMNiPoyQDACii2uKQ9k=
go.opentelemetry.io/otel/bridge/opentracing v1.31.0/go.mod h1:DnEoPjq3eNCtnB41TqlUQYtarWe8PqJNWRt37daADe4=
go.opentelemetry.io/otel/exporters/jaeger v1.16.0 h1:YhxxmXZ011C0aDZKoNw+juVWAmEfv/0W2XBOv9aHTaA=
go.opentelemetry.io/otel/exporters/jaeger v1.16.0/go.mod h1:grYbBo/5afWlPpdPZYhyn78Bk04hnvxn2+hvxQhKIQM=
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.29.0 h1:dIIDULZJpgdiHz5tXrTgKIMLkus6jEFa7x5SOKcyR7E=
Expand Down
16 changes: 13 additions & 3 deletions internal/cortex/querier/queryrange/query_range.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"context"
stdjson "encoding/json"
"fmt"
io "io"
"io"
"math"
"net/http"
"net/url"
Expand Down Expand Up @@ -329,6 +329,7 @@ func (prometheusCodec) DecodeRequest(_ context.Context, r *http.Request, forward
result.Query = r.FormValue("query")
result.Stats = r.FormValue("stats")
result.Path = r.URL.Path
result.Stats = r.FormValue("stats")

// Include the specified headers from http request in prometheusRequest.
for _, header := range forwardHeaders {
Expand Down Expand Up @@ -706,6 +707,8 @@ func (s *PrometheusInstantQueryData) MarshalJSON() ([]byte, error) {
func StatsMerge(resps []Response) *PrometheusResponseStats {
output := map[int64]*PrometheusResponseQueryableSamplesStatsPerStep{}
hasStats := false
peakSamples := int32(0)
totalSamples := int64(0)
for _, resp := range resps {
stats := resp.GetStats()
if stats == nil {
Expand All @@ -720,6 +723,11 @@ func StatsMerge(resps []Response) *PrometheusResponseStats {
for _, s := range stats.Samples.TotalQueryableSamplesPerStep {
output[s.GetTimestampMs()] = s
}

if stats.Samples.PeakSamples > peakSamples {
peakSamples = stats.Samples.PeakSamples
}
totalSamples += stats.Samples.TotalQueryableSamples
}

if !hasStats {
Expand All @@ -733,10 +741,12 @@ func StatsMerge(resps []Response) *PrometheusResponseStats {

sort.Slice(keys, func(i, j int) bool { return keys[i] < keys[j] })

result := &PrometheusResponseStats{Samples: &PrometheusResponseSamplesStats{}}
result := &PrometheusResponseStats{Samples: &PrometheusResponseSamplesStats{
PeakSamples: peakSamples,
TotalQueryableSamples: totalSamples,
}}
for _, key := range keys {
result.Samples.TotalQueryableSamplesPerStep = append(result.Samples.TotalQueryableSamplesPerStep, output[key])
result.Samples.TotalQueryableSamples += output[key].Value
}

return result
Expand Down
46 changes: 38 additions & 8 deletions internal/cortex/querier/queryrange/query_range_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package queryrange
import (
"bytes"
"context"
io "io"
"io"
"net/http"
"strconv"
"testing"
Expand Down Expand Up @@ -36,6 +36,20 @@ func TestRequest(t *testing.T) {
url: query,
expected: &parsedRequestWithHeaders,
},
{
url: "/api/v1/query_range?end=60&query=sum%28container_memory_rss%29+by+%28namespace%29&start=0&stats=all&step=14",
expected: &PrometheusRequest{
Path: "/api/v1/query_range",
Start: 0,
End: 60_000,
Step: 14_000,
Query: "sum(container_memory_rss) by (namespace)",
Stats: "all",
Headers: []*PrometheusRequestHeader{
{Name: "Test-Header", Values: []string{"test"}},
},
},
},
{
url: "api/v1/query_range?start=foo&stats=all",
expectedErr: httpgrpc.Errorf(http.StatusBadRequest, "invalid parameter \"start\"; cannot parse \"foo\" to a valid timestamp"),
Expand Down Expand Up @@ -129,7 +143,7 @@ func TestResponseWithStats(t *testing.T) {
expected *PrometheusResponse
}{
{
body: `{"status":"success","data":{"resultType":"matrix","result":[{"metric":{"foo":"bar"},"values":[[1536673680,"137"],[1536673780,"137"]]}],"stats":{"samples":{"totalQueryableSamples":10,"totalQueryableSamplesPerStep":[[1536673680,5],[1536673780,5]]}},"analysis":null}}`,
body: `{"status":"success","data":{"resultType":"matrix","result":[{"metric":{"foo":"bar"},"values":[[1536673680,"137"],[1536673780,"137"]]}],"stats":{"samples":{"peakSamples":0,"totalQueryableSamples":10,"totalQueryableSamplesPerStep":[[1536673680,5],[1536673780,5]]}},"analysis":null}}`,
expected: &PrometheusResponse{
Status: "success",
Data: PrometheusData{
Expand Down Expand Up @@ -158,7 +172,7 @@ func TestResponseWithStats(t *testing.T) {
},
},
{
body: `{"status":"success","data":{"resultType":"matrix","result":[{"metric":{"foo":"bar"},"values":[[1536673680,"137"],[1536673780,"137"]]}],"stats":{"samples":{"totalQueryableSamples":10,"totalQueryableSamplesPerStep":[[1536673680,5],[1536673780,5]]}},"analysis":{"name":"[noArgFunction]","executionTime":"1s","children":null}}}`,
body: `{"status":"success","data":{"resultType":"matrix","result":[{"metric":{"foo":"bar"},"values":[[1536673680,"137"],[1536673780,"137"]]}],"stats":{"samples":{"peakSamples":0,"totalQueryableSamples":10,"totalQueryableSamplesPerStep":[[1536673680,5],[1536673780,5]]}},"analysis":{"name":"[noArgFunction]","executionTime":"1s","children":null}}}`,
expected: &PrometheusResponse{
Status: "success",
Data: PrometheusData{
Expand Down Expand Up @@ -211,11 +225,27 @@ func TestResponseWithStats(t *testing.T) {
}
resp2, err := PrometheusCodec.EncodeResponse(context.Background(), resp)
require.NoError(t, err)
assert.Equal(t, response, resp2)
assert.Equal(t, prettyPrintJsonBody(t, response.Body), prettyPrintJsonBody(t, resp2.Body))
})
}
}

func prettyPrintJsonBody(t *testing.T, body io.ReadCloser) string {
t.Helper()

bodyContent, err := io.ReadAll(body)
require.NoError(t, err)

var jsonData interface{}
err = json.Unmarshal(bodyContent, &jsonData)
require.NoError(t, err)

prettyBytes, err := json.MarshalIndent(jsonData, "", " ")
require.NoError(t, err)

return string(prettyBytes)
}

func TestMergeAPIResponses(t *testing.T) {
for _, tc := range []struct {
name string
Expand Down Expand Up @@ -659,7 +689,7 @@ func TestMergeAPIResponses(t *testing.T) {
},
},
Stats: &PrometheusResponseStats{Samples: &PrometheusResponseSamplesStats{
TotalQueryableSamples: 25,
TotalQueryableSamples: 30,
TotalQueryableSamplesPerStep: []*PrometheusResponseQueryableSamplesStatsPerStep{
{Value: 5, TimestampMs: 1000},
{Value: 5, TimestampMs: 2000},
Expand Down Expand Up @@ -696,7 +726,7 @@ func TestMergeAPIResponses(t *testing.T) {
},
},
Stats: &PrometheusResponseStats{Samples: &PrometheusResponseSamplesStats{
TotalQueryableSamples: 28,
TotalQueryableSamples: 36,
TotalQueryableSamplesPerStep: []*PrometheusResponseQueryableSamplesStatsPerStep{
{Value: 1, TimestampMs: 1000},
{Value: 2, TimestampMs: 2000},
Expand Down Expand Up @@ -734,7 +764,7 @@ func TestMergeAPIResponses(t *testing.T) {
},
},
Stats: &PrometheusResponseStats{Samples: &PrometheusResponseSamplesStats{
TotalQueryableSamples: 15,
TotalQueryableSamples: 26,
TotalQueryableSamplesPerStep: []*PrometheusResponseQueryableSamplesStatsPerStep{
{Value: 1, TimestampMs: 1000},
{Value: 2, TimestampMs: 2000},
Expand Down Expand Up @@ -769,7 +799,7 @@ func TestMergeAPIResponses(t *testing.T) {
},
},
Stats: &PrometheusResponseStats{Samples: &PrometheusResponseSamplesStats{
TotalQueryableSamples: 14,
TotalQueryableSamples: 40,
TotalQueryableSamplesPerStep: []*PrometheusResponseQueryableSamplesStatsPerStep{
{Value: 2, TimestampMs: 2000},
{Value: 3, TimestampMs: 3000},
Expand Down
Loading

0 comments on commit b370f3d

Please sign in to comment.