Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mapno committed Apr 6, 2022
1 parent 5577aac commit 309793e
Show file tree
Hide file tree
Showing 7 changed files with 318 additions and 48 deletions.
2 changes: 1 addition & 1 deletion cmd/tempo-vulture/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ func searchTag(client *util.Client, seed time.Time) (traceMetrics, error) {
// around the seed.
start := seed.Add(-30 * time.Minute).Unix()
end := seed.Add(30 * time.Minute).Unix()
resp, err := client.SearchWithRange(fmt.Sprintf("%s=%s", attr.Key, attr.Value.GetStringValue()), start, end)
resp, err := client.SearchWithRange(fmt.Sprintf("%s=%s", attr.Key, util.StringifyAnyValue(attr.Value)), start, end)
if err != nil {
logger.Error(fmt.Sprintf("failed to search traces with tag %s: %s", attr.Key, err.Error()))
tm.requestFailed++
Expand Down
31 changes: 18 additions & 13 deletions modules/generator/processor/servicegraphs/servicegraphs.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/opentracing/opentracing-go"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prometheus/prometheus/util/strutil"

gen "github.com/grafana/tempo/modules/generator/processor"
"github.com/grafana/tempo/modules/generator/processor/servicegraphs/store"
Expand Down Expand Up @@ -74,7 +75,7 @@ func New(cfg Config, tenant string, registry registry.Registry, logger log.Logge
labels := []string{"client", "server"}

for _, d := range cfg.Dimensions {
labels = append(labels, commonUtil.SanitizeLabelName(d))
labels = append(labels, strutil.SanitizeLabelName(d))
}

p := &processor{
Expand Down Expand Up @@ -204,7 +205,10 @@ func (p *processor) Shutdown(_ context.Context) {
// Returns true if the edge is completed or expired and should be deleted.
func (p *processor) collectEdge(e *store.Edge) {
if e.IsCompleted() {
values := []string{e.ClientService, e.ServerService}
values := make([]string, 0, 2+len(p.cfg.Dimensions))
values = append(values, e.ClientService)
values = append(values, e.ServerService)

for _, dimension := range p.cfg.Dimensions {
values = append(values, e.Dimensions[dimension])
}
Expand All @@ -222,22 +226,23 @@ func (p *processor) collectEdge(e *store.Edge) {
}
}

func (p *processor) upsertDimensions(m map[string]string, resourceAttr []*v1common.KeyValue, attr []*v1common.KeyValue) {
func (p *processor) upsertDimensions(m map[string]string, resourceAttr []*v1common.KeyValue, spanAttr []*v1common.KeyValue) {
for _, dim := range p.cfg.Dimensions {
for _, kv := range resourceAttr {
key := kv.Key
if key == dim {
m[key] = commonUtil.StringifyAnyValue(kv.Value)
continue
}
if v, found := p.findAttrValue(dim, resourceAttr, spanAttr); found {
m[dim] = v
}
for _, kv := range attr {
key := kv.Key
if key == dim {
m[key] = commonUtil.StringifyAnyValue(kv.Value)
}
}

func (p *processor) findAttrValue(key string, attrSlices ...[]*v1common.KeyValue) (string, bool) {
for _, attrs := range attrSlices {
for _, kv := range attrs {
if key == kv.Key {
return commonUtil.StringifyAnyValue(kv.Value), true
}
}
}
return "", false
}

func (p *processor) spanFailed(_ *v1.Span) bool {
Expand Down
8 changes: 0 additions & 8 deletions pkg/util/attributes.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package util

import (
"regexp"
"strconv"

v1common "github.com/grafana/tempo/pkg/tempopb/common/v1"
Expand Down Expand Up @@ -35,10 +34,3 @@ func StringifyAnyValue(anyValue *v1common.AnyValue) string {

return ""
}

var invalidLabelCharRE = regexp.MustCompile(`[^a-zA-Z0-9_]`)

// SanitizeLabelName sanitizes a label name for Prometheus.
func SanitizeLabelName(name string) string {
return invalidLabelCharRE.ReplaceAllString(name, "_")
}
26 changes: 0 additions & 26 deletions pkg/util/attributes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,29 +91,3 @@ func TestStringifyAnyValue(t *testing.T) {
})
}
}

func TestSanitizeLabelName(t *testing.T) {
testCases := []struct {
name string
label string
expected string
}{
{
name: "label with no special characters",
label: "label",
expected: "label",
},
{
name: "label with special characters",
label: "label-with.special/characters",
expected: "label_with_special_characters",
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
str := SanitizeLabelName(tc.label)
assert.Equal(t, tc.expected, str)
})
}
}
255 changes: 255 additions & 0 deletions vendor/github.com/prometheus/prometheus/util/strutil/quote.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 309793e

Please sign in to comment.