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

Rejects push requests with streams without labels. #3643

Merged
merged 2 commits into from
Apr 22, 2021
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
4 changes: 4 additions & 0 deletions pkg/distributor/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ func (v Validator) ValidateEntry(ctx validationContext, labels string, entry log

// Validate labels returns an error if the labels are invalid
func (v Validator) ValidateLabels(ctx validationContext, ls labels.Labels, stream logproto.Stream) error {
if len(ls) == 0 {
validation.DiscardedSamples.WithLabelValues(validation.MissingLabels, ctx.userID).Inc()
return httpgrpc.Errorf(http.StatusBadRequest, validation.MissingLabelsErrorMsg)
}
numLabelNames := len(ls)
if numLabelNames > ctx.maxLabelNamesPerSeries {
validation.DiscardedSamples.WithLabelValues(validation.MaxLabelNamesPerSeries, ctx.userID).Inc()
Expand Down
13 changes: 11 additions & 2 deletions pkg/distributor/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ import (
"github.com/grafana/loki/pkg/validation"
)

var testStreamLabels = "FIXME"
var testTime = time.Now()
var (
testStreamLabels = "FIXME"
testTime = time.Now()
)

func TestValidator_ValidateEntry(t *testing.T) {
tests := []struct {
Expand Down Expand Up @@ -95,6 +97,13 @@ func TestValidator_ValidateLabels(t *testing.T) {
"{foo=\"bar\"}",
nil,
},
{
"empty",
"test",
nil,
"{}",
httpgrpc.Errorf(http.StatusBadRequest, validation.MissingLabelsErrorMsg),
},
{
"test too many labels",
"test",
Expand Down
5 changes: 4 additions & 1 deletion pkg/validation/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import (
const (
discardReasonLabel = "reason"
// InvalidLabels is a reason for discarding log lines which have labels that cannot be parsed.
InvalidLabels = "invalid_labels"
InvalidLabels = "invalid_labels"
MissingLabels = "missing_labels"

MissingLabelsErrorMsg = "error at least one label pair is required per stream"
InvalidLabelsErrorMsg = "Error parsing labels '%s' with error: %s"
// RateLimited is one of the values for the reason to discard samples.
// Declared here to avoid duplication in ingester and distributor.
Expand Down