Skip to content

Commit

Permalink
Breadcrumbs for generator to serve a span summary
Browse files Browse the repository at this point in the history
Signed-off-by: Zach Leslie <[email protected]>
  • Loading branch information
zalegrala committed May 3, 2023
1 parent be68ed9 commit 6f6ee6c
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 0 deletions.
1 change: 1 addition & 0 deletions modules/generator/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type Config struct {
// MetricsIngestionSlack is the max amount of time passed since a span's start time
// for the span to be considered in metrics generation
MetricsIngestionSlack time.Duration `yaml:"metrics_ingestion_time_range_slack"`
SummaryTimeout time.Duration `yaml:"summary_timeout"`
}

// RegisterFlagsAndApplyDefaults registers the flags.
Expand Down
14 changes: 14 additions & 0 deletions modules/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,3 +283,17 @@ func (g *Generator) OnRingInstanceStopping(lifecycler *ring.BasicLifecycler) {
// OnRingInstanceHeartbeat implements ring.BasicLifecyclerDelegate
func (g *Generator) OnRingInstanceHeartbeat(lifecycler *ring.BasicLifecycler, ringDesc *ring.Desc, instanceDesc *ring.InstanceDesc) {
}

func (q *Generator) SpanSummary(ctx context.Context, req *tempopb.SpanSummaryRequest) (*tempopb.SpanSummaryResponse, error) {
instanceID, err := user.ExtractOrgID(ctx)
if err != nil {
return nil, err
}

instance, err := q.getOrCreateInstance(instanceID)
if err != nil {
return nil, err
}

return instance.spanSummary(ctx, req)
}
43 changes: 43 additions & 0 deletions modules/generator/http.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package generator

import (
"context"
"net/http"
"time"

"github.com/gogo/protobuf/jsonpb"
"github.com/grafana/tempo/pkg/api"
"github.com/grafana/tempo/pkg/tempopb"
"github.com/opentracing/opentracing-go"
)

func (g *Generator) SpanSummaryHandler(w http.ResponseWriter, r *http.Request) {
ctx, cancel := context.WithDeadline(r.Context(), time.Now().Add(g.cfg.SummaryTimeout))
defer cancel()

span, ctx := opentracing.StartSpanFromContext(ctx, "Generator.SpanSummaryHandler")
defer span.Finish()

span.SetTag("requestURI", r.RequestURI)

req, err := api.ParseSummaryRequest(r)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}

var resp *tempopb.SpanSummaryResponse
resp, err = g.SpanSummary(ctx, req)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}

marshaller := &jsonpb.Marshaler{}

err = marshaller.Marshal(w, resp)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.Header().Set(api.HeaderContentType, api.HeaderAcceptJSON)
}
16 changes: 16 additions & 0 deletions modules/generator/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,22 @@ func (i *instance) preprocessSpans(req *tempopb.PushSpansRequest) {
i.updatePushMetrics(size, spanCount, expiredSpanCount)
}

func (i *instance) spanSummary(ctx context.Context, req *tempopb.SpanSummaryRequest) (resp *tempopb.SpanSummaryResponse, err error) {
select {
case <-ctx.Done():
return nil, nil
// case i.spanSummaryCh <- req:
default:
// for _, processor := range i.processors {
// switch p := processor.(type) {
// case *localblocks.Processor:
// processor.GetMetrics(ctx, req)
// }
// }
return nil, fmt.Errorf("not implemented yet")
}
}

func (i *instance) updatePushMetrics(bytesIngested int, spanCount int, expiredSpanCount int) {
metricBytesIngested.WithLabelValues(i.instanceID).Add(float64(bytesIngested))
metricSpansIngested.WithLabelValues(i.instanceID).Add(float64(spanCount))
Expand Down

0 comments on commit 6f6ee6c

Please sign in to comment.