Rejects push requests with streams without labels. (#3643)

* Rejects push requests with  streams without labels.

Fixes #3638

Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>

* Missing commit

Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>
pull/3644/head
Cyril Tovena 5 years ago committed by GitHub
parent e71cb454ca
commit ae23b7e4ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      pkg/distributor/validator.go
  2. 13
      pkg/distributor/validator_test.go
  3. 5
      pkg/validation/validate.go

@ -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()

@ -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 {
@ -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",

@ -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.

Loading…
Cancel
Save