-
Notifications
You must be signed in to change notification settings - Fork 545
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add exemplars to TraceQL metrics (#3824)
* Add exemplars to TraceQL metric queries Add query hint Fix test Might work now fmt Almost there A few fixes Doc fix Drop percentage More more Consolidating fmt Fix tests More changes chlog Minor fix Exemplars in compare() and other fixes Fix test Improvements Bucketize ups Cleaning up Stuff Change benchmark Clean up Exemplar iterator Ditch predicate approach * Quit early predicate improvements * Docs * Post-review improvements * Consolidate hint checking * Empty exemplars cleanup * Not a map anymore * Split observe() and observeExemplar() * Minor fixes * Consolidate exemplar sampling * Some improvements * Reduce allocs * Remove unnecessary func * Review comments * Pass callback in Condition * Comment * Fix tests
- Loading branch information
Showing
31 changed files
with
1,492 additions
and
471 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
target: all | ||
stream_over_http_enabled: true | ||
|
||
server: | ||
http_listen_port: 3200 | ||
log_level: debug | ||
|
||
query_frontend: | ||
search: | ||
query_backend_after: 0 # setting these both to 0 will force all range searches to hit the backend | ||
query_ingesters_until: 0 | ||
metrics: | ||
exemplars: true | ||
rf1_read_path: true | ||
|
||
distributor: | ||
receivers: | ||
jaeger: | ||
protocols: | ||
grpc: | ||
otlp: | ||
protocols: | ||
grpc: | ||
zipkin: | ||
log_received_spans: | ||
enabled: true | ||
|
||
metrics_generator: | ||
processor: | ||
local_blocks: | ||
flush_check_period: 1s | ||
max_block_duration: 10s | ||
flush_to_storage: true | ||
storage: | ||
path: /var/tempo | ||
remote_write: | ||
- url: http://tempo_e2e-prometheus:9090/api/v1/write | ||
send_exemplars: true | ||
traces_storage: | ||
path: /var/tempo/generator/traces | ||
|
||
ingester: | ||
lifecycler: | ||
address: 127.0.0.1 | ||
ring: | ||
kvstore: | ||
store: inmemory | ||
replication_factor: 1 | ||
final_sleep: 0s | ||
trace_idle_period: 1s | ||
max_block_bytes: 1 | ||
max_block_duration: 2s | ||
complete_block_timeout: 20s | ||
flush_check_period: 1s | ||
|
||
storage: | ||
trace: | ||
backend: local | ||
local: | ||
path: /var/tempo | ||
pool: | ||
max_workers: 10 | ||
queue_depth: 100 | ||
block: | ||
version: vParquet4 | ||
blocklist_poll: 1s | ||
|
||
overrides: | ||
defaults: | ||
metrics_generator: | ||
processors: [ local-blocks ] | ||
user_configurable_overrides: | ||
enabled: true | ||
poll_interval: 10s | ||
client: | ||
backend: local | ||
local: | ||
path: /var/tempo/overrides |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package e2e | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"io" | ||
"net/http" | ||
"net/url" | ||
"testing" | ||
"time" | ||
|
||
"github.com/grafana/e2e" | ||
"github.com/grafana/tempo/integration/util" | ||
"github.com/grafana/tempo/pkg/tempopb" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
const configQueryRange = "config-query-range.yaml" | ||
|
||
// Set debugMode to true to print the response body | ||
var debugMode = false | ||
|
||
func TestQueryRangeExemplars(t *testing.T) { | ||
s, err := e2e.NewScenario("tempo_e2e") | ||
require.NoError(t, err) | ||
defer s.Close() | ||
|
||
require.NoError(t, util.CopyFileToSharedDir(s, configQueryRange, "config.yaml")) | ||
tempo := util.NewTempoAllInOne() | ||
require.NoError(t, s.StartAndWaitReady(tempo)) | ||
|
||
jaegerClient, err := util.NewJaegerGRPCClient(tempo.Endpoint(14250)) | ||
require.NoError(t, err) | ||
require.NotNil(t, jaegerClient) | ||
|
||
ticker := time.NewTicker(500 * time.Millisecond) | ||
defer ticker.Stop() | ||
timer := time.NewTimer(5 * time.Second) | ||
defer timer.Stop() | ||
sendLoop: | ||
for { | ||
select { | ||
case <-ticker.C: | ||
require.NoError(t, jaegerClient.EmitBatch(context.Background(), util.MakeThriftBatch())) | ||
case <-timer.C: | ||
break sendLoop | ||
} | ||
} | ||
|
||
// Wait for traces to be flushed to blocks | ||
require.NoError(t, tempo.WaitSumMetricsWithOptions(e2e.GreaterOrEqual(1), []string{"tempo_metrics_generator_processor_local_blocks_spans_total"}, e2e.WaitMissingMetrics)) | ||
require.NoError(t, tempo.WaitSumMetricsWithOptions(e2e.GreaterOrEqual(1), []string{"tempo_metrics_generator_processor_local_blocks_cut_blocks"}, e2e.WaitMissingMetrics)) | ||
|
||
for _, query := range []string{ | ||
"{} | rate()", | ||
"{} | compare({status=error})", | ||
} { | ||
t.Run(query, func(t *testing.T) { | ||
callQueryRange(t, tempo.Endpoint(3200), query, debugMode) | ||
}) | ||
} | ||
} | ||
|
||
func callQueryRange(t *testing.T, endpoint, query string, printBody bool) { | ||
url := buildURL(endpoint, fmt.Sprintf("%s with(exemplars=true)", query)) | ||
req, err := http.NewRequest(http.MethodGet, url, nil) | ||
require.NoError(t, err) | ||
|
||
res, err := http.DefaultClient.Do(req) | ||
require.NoError(t, err) | ||
require.Equal(t, http.StatusOK, res.StatusCode) | ||
|
||
// Read body and print it | ||
body, err := io.ReadAll(res.Body) | ||
require.NoError(t, err) | ||
if printBody { | ||
fmt.Println(string(body)) | ||
} | ||
|
||
queryRangeRes := tempopb.QueryRangeResponse{} | ||
require.NoError(t, json.Unmarshal(body, &queryRangeRes)) | ||
require.NotNil(t, queryRangeRes) | ||
require.GreaterOrEqual(t, len(queryRangeRes.GetSeries()), 1) | ||
exemplarCount := 0 | ||
for _, series := range queryRangeRes.GetSeries() { | ||
exemplarCount += len(series.GetExemplars()) | ||
} | ||
require.GreaterOrEqual(t, exemplarCount, 1) | ||
} | ||
|
||
func buildURL(endpoint, query string) string { | ||
return fmt.Sprintf( | ||
"http://%s/api/metrics/query_range?query=%s&start=%d&end=%d&step=%s", | ||
endpoint, | ||
url.QueryEscape(query), | ||
time.Now().Add(-5*time.Minute).UnixNano(), | ||
time.Now().Add(time.Minute).UnixNano(), | ||
"5s", | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.