Tempo: Add start time and end time parameters while querying traces (#48068) (#57459)

* Add start time and end time parameters while querying tempo traces

* Added configurable time shift to query by trace id

* Test that the URL is formatted correctly

* Added test to check for time shift

* Improved label and tooltip of new time shift settings

Co-authored-by: André Pereira <adrapereira@gmail.com>
(cherry picked from commit 98053cfde8)

Co-authored-by: bikashmishra100 <bikashprakash@gmail.com>
This commit is contained in:
Andre Pereira
2022-10-21 16:51:48 +01:00
committed by GitHub
co-authored by bikashmishra100
parent aff8e62b8c
commit 559ef42767
7 changed files with 155 additions and 10 deletions
+10 -3
View File
@@ -73,7 +73,7 @@ func (s *Service) QueryData(ctx context.Context, req *backend.QueryDataRequest)
return nil, err
}
request, err := s.createRequest(ctx, dsInfo, model.TraceID)
request, err := s.createRequest(ctx, dsInfo, model.TraceID, req.Queries[0].TimeRange.From.Unix(), req.Queries[0].TimeRange.To.Unix())
if err != nil {
return result, err
}
@@ -117,8 +117,15 @@ func (s *Service) QueryData(ctx context.Context, req *backend.QueryDataRequest)
return result, nil
}
func (s *Service) createRequest(ctx context.Context, dsInfo *datasourceInfo, traceID string) (*http.Request, error) {
req, err := http.NewRequestWithContext(ctx, "GET", dsInfo.URL+"/api/traces/"+traceID, nil)
func (s *Service) createRequest(ctx context.Context, dsInfo *datasourceInfo, traceID string, start int64, end int64) (*http.Request, error) {
var tempoQuery string
if start == 0 || end == 0 {
tempoQuery = fmt.Sprintf("%s/api/traces/%s", dsInfo.URL, traceID)
} else {
tempoQuery = fmt.Sprintf("%s/api/traces/%s?start=%d&end=%d", dsInfo.URL, traceID, start, end)
}
req, err := http.NewRequestWithContext(ctx, "GET", tempoQuery, nil)
if err != nil {
return nil, err
}
+10 -2
View File
@@ -10,10 +10,18 @@ import (
)
func TestTempo(t *testing.T) {
t.Run("createRequest - success", func(t *testing.T) {
t.Run("createRequest without time range - success", func(t *testing.T) {
service := &Service{tlog: log.New("tempo-test")}
req, err := service.createRequest(context.Background(), &datasourceInfo{}, "traceID")
req, err := service.createRequest(context.Background(), &datasourceInfo{}, "traceID", 0, 0)
require.NoError(t, err)
assert.Equal(t, 1, len(req.Header))
})
t.Run("createRequest with time range - success", func(t *testing.T) {
service := &Service{tlog: log.New("tempo-test")}
req, err := service.createRequest(context.Background(), &datasourceInfo{}, "traceID", 1, 2)
require.NoError(t, err)
assert.Equal(t, 1, len(req.Header))
assert.Equal(t, "/api/traces/traceID?start=1&end=2", req.URL.String())
})
}