Skip to content

Commit

Permalink
Add HTTP endpoint /api/echo to query-frontend
Browse files Browse the repository at this point in the history
The echo endpoint can be used by Grafana to test Tempo whether is reachable. #624
  • Loading branch information
yvrhdn committed May 28, 2021
1 parent cb551a3 commit ab2fbe3
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
This change requires a specific rollout process to prevent dropped spans. First, rollout everything except distributors. After all ingesters have updated
you can then rollout distributors to the latest version. This is due to changes in the communication between ingesters <-> distributors.
* [ENHANCEMENT] Allow setting the bloom filter shard size with support dynamic shard count.[#644](https://github.com/grafana/tempo/pull/644)
* [ENHANCEMENT] Add a new endpoint `/api/echo` to test the query frontend is reachable. [#714](https://github.com/grafana/tempo/pull/714)
* [CHANGE] Fix Query Frontend grpc settings to avoid noisy error log. [#690](https://github.com/grafana/tempo/pull/690)
* [CHANGE] GCS SDK update v1.12.0 => v.15.0, ReadAllWithEstimate used in GCS/S3 backends. [#693](https://github.com/grafana/tempo/pull/693)

Expand Down
22 changes: 18 additions & 4 deletions cmd/tempo/app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package app
import (
"fmt"
"net/http"
"path"

"github.com/cortexproject/cortex/pkg/cortex"
cortex_frontend "github.com/cortexproject/cortex/pkg/frontend"
Expand Down Expand Up @@ -45,6 +46,11 @@ const (
All string = "all"
)

const (
apiPathTraces string = "/api/traces/{traceID}"
apiPathEcho string = "/api/echo"
)

func (t *App) initServer() (services.Service, error) {
t.cfg.Server.MetricsNamespace = metricsNamespace
t.cfg.Server.ExcludeRequestInLog = true
Expand Down Expand Up @@ -151,7 +157,7 @@ func (t *App) initQuerier() (services.Service, error) {
t.httpAuthMiddleware,
).Wrap(http.HandlerFunc(t.querier.TraceByIDHandler))

t.server.HTTP.Handle("/querier"+queryEndpoint(&t.cfg), tracesHandler)
t.server.HTTP.Handle(path.Join("/querier", addHTTPAPIPrefix(&t.cfg, apiPathTraces)), tracesHandler)
return t.querier, t.querier.CreateAndRegisterWorker(t.server.HTTPServer.Handler)
}

Expand Down Expand Up @@ -183,7 +189,9 @@ func (t *App) initQueryFrontend() (services.Service, error) {
// register grpc server for queriers to connect to
cortex_frontend_v1pb.RegisterFrontendServer(t.server.GRPC, t.frontend)
// http query endpoint
t.server.HTTP.Handle(queryEndpoint(&t.cfg), tracesHandler)
t.server.HTTP.Handle(addHTTPAPIPrefix(&t.cfg, apiPathTraces), tracesHandler)

t.server.HTTP.Handle(addHTTPAPIPrefix(&t.cfg, apiPathEcho), echoHandler())

return t.frontend, nil
}
Expand Down Expand Up @@ -271,6 +279,12 @@ func (t *App) setupModuleManager() error {
return nil
}

func queryEndpoint(cfg *Config) string {
return cfg.HTTPAPIPrefix + "/api/traces/{traceID}"
func addHTTPAPIPrefix(cfg *Config, apiPath string) string {
return path.Join(cfg.HTTPAPIPrefix, apiPath)
}

func echoHandler() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
http.Error(w, "echo", http.StatusOK)
}
}
16 changes: 16 additions & 0 deletions integration/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ func TestAllInOne(t *testing.T) {

hexID := fmt.Sprintf("%016x%016x", batch.Spans[0].TraceIdHigh, batch.Spans[0].TraceIdLow)

// test echo
assertEcho(t, "http://"+tempo.Endpoint(3100)+"/api/echo")

// ensure trace is created in ingester (trace_idle_time has passed)
require.NoError(t, tempo.WaitSumMetrics(cortex_e2e.Equals(1), "tempo_ingester_traces_created_total"))

Expand Down Expand Up @@ -117,6 +120,9 @@ func TestAzuriteAllInOne(t *testing.T) {

hexID := fmt.Sprintf("%016x%016x", batch.Spans[0].TraceIdHigh, batch.Spans[0].TraceIdLow)

// test echo
assertEcho(t, "http://"+tempo.Endpoint(3100)+"/api/echo")

// ensure trace is created in ingester (trace_idle_time has passed)
require.NoError(t, tempo.WaitSumMetrics(cortex_e2e.Equals(1), "tempo_ingester_traces_created_total"))

Expand Down Expand Up @@ -186,6 +192,9 @@ func TestMicroservices(t *testing.T) {

hexID := fmt.Sprintf("%016x%016x", batch.Spans[0].TraceIdHigh, batch.Spans[0].TraceIdLow)

// test echo
assertEcho(t, "http://"+tempoQueryFrontend.Endpoint(3100)+"/api/echo")

// ensure trace is created in ingester (trace_idle_time has passed)
require.NoError(t, tempoIngester1.WaitSumMetrics(cortex_e2e.Equals(1), "tempo_ingester_traces_created_total"))
require.NoError(t, tempoIngester2.WaitSumMetrics(cortex_e2e.Equals(1), "tempo_ingester_traces_created_total"))
Expand Down Expand Up @@ -265,6 +274,13 @@ func makeThriftBatchWithSpanCount(n int) *thrift.Batch {
return &thrift.Batch{Spans: spans}
}

func assertEcho(t *testing.T, url string) {
res, err := cortex_e2e.GetRequest(url)
require.NoError(t, err)
require.Equal(t, 200, res.StatusCode)
defer res.Body.Close()
}

//nolint:unparam
func queryAndAssertTrace(t *testing.T, url string, expectedName string, expectedBatches int) {
res, err := cortex_e2e.GetRequest(url)
Expand Down

0 comments on commit ab2fbe3

Please sign in to comment.