Skip to content

Commit 019ebad

Browse files
authored
add additional tracing span for merging labels responses (#5322)
Signed-off-by: Ben Ye <[email protected]>
1 parent e9ecc3f commit 019ebad

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

pkg/distributor/distributor.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,12 @@ func (d *Distributor) ForReplicationSet(ctx context.Context, replicationSet ring
909909
}
910910

911911
func (d *Distributor) LabelValuesForLabelNameCommon(ctx context.Context, from, to model.Time, labelName model.LabelName, f func(ctx context.Context, rs ring.ReplicationSet, req *ingester_client.LabelValuesRequest) ([]interface{}, error), matchers ...*labels.Matcher) ([]string, error) {
912+
span, ctx := opentracing.StartSpanFromContext(ctx, "Distributor.LabelValues", opentracing.Tags{
913+
"name": labelName,
914+
"start": from.Unix(),
915+
"end": to.Unix(),
916+
})
917+
defer span.Finish()
912918
replicationSet, err := d.GetIngestersForMetadata(ctx)
913919
if err != nil {
914920
return nil, err
@@ -924,6 +930,8 @@ func (d *Distributor) LabelValuesForLabelNameCommon(ctx context.Context, from, t
924930
return nil, err
925931
}
926932

933+
span, _ = opentracing.StartSpanFromContext(ctx, "response_merge")
934+
defer span.Finish()
927935
valueSet := map[string]struct{}{}
928936
for _, resp := range resps {
929937
for _, v := range resp.([]string) {
@@ -938,11 +946,12 @@ func (d *Distributor) LabelValuesForLabelNameCommon(ctx context.Context, from, t
938946

939947
// We need the values returned to be sorted.
940948
sort.Strings(values)
949+
span.SetTag("result_length", len(values))
941950

942951
return values, nil
943952
}
944953

945-
// LabelValuesForLabelName returns all of the label values that are associated with a given label name.
954+
// LabelValuesForLabelName returns all the label values that are associated with a given label name.
946955
func (d *Distributor) LabelValuesForLabelName(ctx context.Context, from, to model.Time, labelName model.LabelName, matchers ...*labels.Matcher) ([]string, error) {
947956
return d.LabelValuesForLabelNameCommon(ctx, from, to, labelName, func(ctx context.Context, rs ring.ReplicationSet, req *ingester_client.LabelValuesRequest) ([]interface{}, error) {
948957
return d.ForReplicationSet(ctx, rs, func(ctx context.Context, client ingester_client.IngesterClient) (interface{}, error) {
@@ -955,7 +964,7 @@ func (d *Distributor) LabelValuesForLabelName(ctx context.Context, from, to mode
955964
}, matchers...)
956965
}
957966

958-
// LabelValuesForLabelName returns all of the label values that are associated with a given label name.
967+
// LabelValuesForLabelNameStream returns all the label values that are associated with a given label name.
959968
func (d *Distributor) LabelValuesForLabelNameStream(ctx context.Context, from, to model.Time, labelName model.LabelName, matchers ...*labels.Matcher) ([]string, error) {
960969
return d.LabelValuesForLabelNameCommon(ctx, from, to, labelName, func(ctx context.Context, rs ring.ReplicationSet, req *ingester_client.LabelValuesRequest) ([]interface{}, error) {
961970
return d.ForReplicationSet(ctx, rs, func(ctx context.Context, client ingester_client.IngesterClient) (interface{}, error) {
@@ -982,6 +991,11 @@ func (d *Distributor) LabelValuesForLabelNameStream(ctx context.Context, from, t
982991
}
983992

984993
func (d *Distributor) LabelNamesCommon(ctx context.Context, from, to model.Time, f func(ctx context.Context, rs ring.ReplicationSet, req *ingester_client.LabelNamesRequest) ([]interface{}, error)) ([]string, error) {
994+
span, ctx := opentracing.StartSpanFromContext(ctx, "Distributor.LabelNames", opentracing.Tags{
995+
"start": from.Unix(),
996+
"end": to.Unix(),
997+
})
998+
defer span.Finish()
985999
replicationSet, err := d.GetIngestersForMetadata(ctx)
9861000
if err != nil {
9871001
return nil, err
@@ -996,6 +1010,8 @@ func (d *Distributor) LabelNamesCommon(ctx context.Context, from, to model.Time,
9961010
return nil, err
9971011
}
9981012

1013+
span, _ = opentracing.StartSpanFromContext(ctx, "response_merge")
1014+
defer span.Finish()
9991015
valueSet := map[string]struct{}{}
10001016
for _, resp := range resps {
10011017
for _, v := range resp.([]string) {
@@ -1009,6 +1025,7 @@ func (d *Distributor) LabelNamesCommon(ctx context.Context, from, to model.Time,
10091025
}
10101026

10111027
sort.Strings(values)
1028+
span.SetTag("result_length", len(values))
10121029

10131030
return values, nil
10141031
}
@@ -1038,7 +1055,7 @@ func (d *Distributor) LabelNamesStream(ctx context.Context, from, to model.Time)
10381055
})
10391056
}
10401057

1041-
// LabelNames returns all of the label names.
1058+
// LabelNames returns all the label names.
10421059
func (d *Distributor) LabelNames(ctx context.Context, from, to model.Time) ([]string, error) {
10431060
return d.LabelNamesCommon(ctx, from, to, func(ctx context.Context, rs ring.ReplicationSet, req *ingester_client.LabelNamesRequest) ([]interface{}, error) {
10441061
return d.ForReplicationSet(ctx, rs, func(ctx context.Context, client ingester_client.IngesterClient) (interface{}, error) {

0 commit comments

Comments
 (0)