Skip to content

Commit f06e579

Browse files
authored
fix: Replace nop logger used in label validation (#4531)
1 parent 6178ec4 commit f06e579

File tree

4 files changed

+9
-5
lines changed

4 files changed

+9
-5
lines changed

pkg/distributor/distributor.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1133,6 +1133,7 @@ func (d *Distributor) visitSampleSeries(s *distributormodel.ProfileSeries, visit
11331133
tenantID: s.TenantID,
11341134
limits: d.limits,
11351135
profile: s.Profile,
1136+
logger: d.logger,
11361137
}
11371138
if err := visit(s.Profile.Profile, s.Labels, relabelingRules, visitor); err != nil {
11381139
validation.DiscardedProfiles.WithLabelValues(string(validation.ReasonOf(err)), s.TenantID).Add(float64(s.TotalProfiles))
@@ -1167,13 +1168,14 @@ type sampleSeriesVisitor struct {
11671168
profile *pprof.Profile
11681169
exp *pprof.SampleExporter
11691170
series []*distributormodel.ProfileSeries
1171+
logger log.Logger
11701172

11711173
discardedBytes int
11721174
discardedProfiles int
11731175
}
11741176

11751177
func (v *sampleSeriesVisitor) ValidateLabels(labels phlaremodel.Labels) error {
1176-
return validation.ValidateLabels(v.limits, v.tenantID, labels)
1178+
return validation.ValidateLabels(v.limits, v.tenantID, labels, v.logger)
11771179
}
11781180

11791181
func (v *sampleSeriesVisitor) VisitProfile(labels phlaremodel.Labels) {

pkg/util/logger.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"github.com/grafana/dskit/tracing"
1414
)
1515

16-
// Logger is a global logger to use only where you cannot inject a logger.
16+
// Logger is a nop global logger
1717
var Logger = log.NewNopLogger()
1818

1919
// LoggerWithUserID returns a Logger that has information about the current user in

pkg/validation/validate.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
"github.com/grafana/pyroscope/pkg/pprof"
1313

14+
"github.com/go-kit/log"
1415
"github.com/go-kit/log/level"
1516
"github.com/pkg/errors"
1617
"github.com/prometheus/client_golang/prometheus"
@@ -125,7 +126,7 @@ type LabelValidationLimits interface {
125126
}
126127

127128
// ValidateLabels validates the labels of a profile.
128-
func ValidateLabels(limits LabelValidationLimits, tenantID string, ls []*typesv1.LabelPair) error {
129+
func ValidateLabels(limits LabelValidationLimits, tenantID string, ls []*typesv1.LabelPair, logger log.Logger) error {
129130
if len(ls) == 0 {
130131
return NewErrorf(MissingLabels, MissingLabelsErrorMsg)
131132
}
@@ -162,7 +163,7 @@ func ValidateLabels(limits LabelValidationLimits, tenantID string, ls []*typesv1
162163
if err != nil {
163164
return err
164165
}
165-
level.Debug(util.Logger).Log(
166+
level.Debug(logger).Log(
166167
"msg", "label name sanitized",
167168
"origName", origName,
168169
"serviceName", serviceNameValue)

pkg/validation/validate_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"testing"
55
"time"
66

7+
"github.com/go-kit/log"
78
"github.com/prometheus/common/model"
89
"github.com/stretchr/testify/require"
910

@@ -140,7 +141,7 @@ func TestValidateLabels(t *testing.T) {
140141
MaxLabelNamesPerSeriesValue: 4,
141142
MaxLabelNameLengthValue: 12,
142143
MaxLabelValueLengthValue: 10,
143-
}, "foo", tt.lbs)
144+
}, "foo", tt.lbs, log.NewNopLogger())
144145
if tt.expectedErr != "" {
145146
require.Error(t, err)
146147
require.Equal(t, tt.expectedErr, err.Error())

0 commit comments

Comments
 (0)