Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add HTTP endpoint /api/echo to query-frontend #714

Merged
merged 1 commit into from
May 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:/grafana/tempo/pull/644)
* [ENHANCEMENT] Add a new endpoint `/api/echo` to test the query frontend is reachable. [#714](https:/grafana/tempo/pull/714)
* [CHANGE] Fix Query Frontend grpc settings to avoid noisy error log. [#690](https:/grafana/tempo/pull/690)
* [CHANGE] GCS SDK update v1.12.0 => v.15.0, ReadAllWithEstimate used in GCS/S3 backends. [#693](https:/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