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

Tempo Serverless: Error clarity #1305

Merged
merged 3 commits into from
Feb 23, 2022
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 @@
* [FEATURE] Added metrics-generator: an optional components to generate metrics from ingested traces [#1282](https://github.com/grafana/tempo/pull/1282) (@mapno, @kvrhdn)
* [ENHANCEMENT] Enterprise jsonnet: add config to create tokengen job explicitly [#1256](https://github.com/grafana/tempo/pull/1256) (@kvrhdn)
* [ENHANCEMENT] Add new scaling alerts to the tempo-mixin [#1292](https://github.com/grafana/tempo/pull/1292) (@mapno)
* [ENHANCEMENT] Improve serverless handler error messages [#1305](https://github.com/grafana/tempo/pull/1305) (@joe-elliott)
* [BUGFIX]: Remove unnecessary PersistentVolumeClaim [#1245](https://github.com/grafana/tempo/issues/1245)
* [BUGFIX] Fixed issue when query-frontend doesn't log request details when request is cancelled [#1136](https://github.com/grafana/tempo/issues/1136) (@adityapwr)
* [BUGFIX] Update OTLP port in examples (docker-compose & kubernetes) from legacy ports (55680/55681) to new ports (4317/4318) [#1294](https://github.com/grafana/tempo/pull/1294) (@mapno)
Expand Down
57 changes: 17 additions & 40 deletions cmd/tempo-serverless/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,43 +47,28 @@ type HTTPError struct {
func Handler(r *http.Request) (*tempopb.SearchResponse, *HTTPError) {
searchReq, err := api.ParseSearchBlockRequest(r)
if err != nil {
return nil, &HTTPError{
Err: err,
Status: http.StatusBadRequest,
}
return nil, httpError("parsing search request", err, http.StatusBadRequest)
}

// load config, fields are set through env vars TEMPO_
reader, cfg, err := loadBackend()
if err != nil {
return nil, &HTTPError{
Err: err,
Status: http.StatusInternalServerError,
}
return nil, httpError("loading backend", err, http.StatusInternalServerError)
}

tenant, _, err := user.ExtractOrgIDFromHTTPRequest(r)
if err != nil {
return nil, &HTTPError{
Err: err,
Status: http.StatusBadRequest,
}
return nil, httpError("extracting org id", err, http.StatusBadRequest)
}

blockID, err := uuid.Parse(searchReq.BlockID)
if err != nil {
return nil, &HTTPError{
Err: err,
Status: http.StatusBadRequest,
}
return nil, httpError("parsing uuid", err, http.StatusBadRequest)
}

enc, err := backend.ParseEncoding(searchReq.Encoding)
if err != nil {
return nil, &HTTPError{
Err: err,
Status: http.StatusBadRequest,
}
return nil, httpError("parsing encoding", err, http.StatusBadRequest)
}

// /giphy so meta
Expand All @@ -99,20 +84,14 @@ func Handler(r *http.Request) (*tempopb.SearchResponse, *HTTPError) {

block, err := encoding.NewBackendBlock(meta, reader)
if err != nil {
return nil, &HTTPError{
Err: err,
Status: http.StatusInternalServerError,
}
return nil, httpError("creating backend block", err, http.StatusInternalServerError)
}

// tempodb exposes an IterateObjects() method to basically perform the below loop. currently we are purposefully
// not using that so that the serverless function doesn't have to instantiate a full tempodb instance.
iter, err := block.PartialIterator(cfg.Search.ChunkSizeBytes, int(searchReq.StartPage), int(searchReq.PagesToSearch))
if err != nil {
return nil, &HTTPError{
Err: err,
Status: http.StatusInternalServerError,
}
return nil, httpError("creating partial iterator", err, http.StatusInternalServerError)
}
iter = encoding.NewPrefetchIterator(r.Context(), iter, cfg.Search.PrefetchTraceCount)

Expand All @@ -122,10 +101,7 @@ func Handler(r *http.Request) (*tempopb.SearchResponse, *HTTPError) {

decoder, err := model.NewObjectDecoder(searchReq.DataEncoding)
if err != nil {
return nil, &HTTPError{
Err: err,
Status: http.StatusInternalServerError,
}
return nil, httpError("creating decoder", err, http.StatusInternalServerError)
}

for {
Expand All @@ -134,21 +110,15 @@ func Handler(r *http.Request) (*tempopb.SearchResponse, *HTTPError) {
break
}
if err != nil {
return nil, &HTTPError{
Err: err,
Status: http.StatusInternalServerError,
}
return nil, httpError("iterating", err, http.StatusInternalServerError)
}

resp.Metrics.InspectedTraces++
resp.Metrics.InspectedBytes += uint64(len(obj))

metadata, err := decoder.Matches(id, obj, searchReq.SearchReq)
if err != nil {
return nil, &HTTPError{
Err: err,
Status: http.StatusInternalServerError,
}
return nil, httpError("matching", err, http.StatusInternalServerError)
}
if metadata == nil {
continue
Expand Down Expand Up @@ -270,3 +240,10 @@ func stringToFlagExt() mapstructure.DecodeHookFunc {
}, nil
}
}

func httpError(action string, err error, status int) *HTTPError {
return &HTTPError{
Err: fmt.Errorf("serverless [%s]: %w", action, err),
Status: status,
}
}