mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Tempo: Add start time and end time parameters while querying traces (#48068)
* 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>
This commit is contained in:
@@ -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,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())
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user