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

Update label validation to run once per metric #369

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 10 additions & 4 deletions expfmt/text_parse.go
Expand Up @@ -272,7 +272,7 @@ func (p *TextParser) startLabelName() stateFn {
if p.skipBlankTab(); p.err != nil {
return nil // Unexpected end of input.
}
return p.readingValue
return p.validateLabelNames
}
if p.readTokenAsLabelName(); p.err != nil {
return nil // Unexpected end of input.
Expand All @@ -299,7 +299,13 @@ func (p *TextParser) startLabelName() stateFn {
p.parseError(fmt.Sprintf("expected '=' after label name, found %q", p.currentByte))
return nil
}
// Check for duplicate label names.

return p.startLabelValue
}

// validateLabelNames represents the state where label names and values have been read
// and should be checked for duplicates
func (p *TextParser) validateLabelNames() stateFn {
labels := make(map[string]struct{})
for _, l := range p.currentMetric.Label {
lName := l.GetName()
Expand All @@ -310,7 +316,7 @@ func (p *TextParser) startLabelName() stateFn {
return nil
}
}
return p.startLabelValue
return p.readingValue
}

// startLabelValue represents the state where the next byte read from p.buf is
Expand Down Expand Up @@ -368,7 +374,7 @@ func (p *TextParser) startLabelValue() stateFn {
if p.skipBlankTab(); p.err != nil {
return nil // Unexpected end of input.
}
return p.readingValue
return p.validateLabelNames
default:
p.parseError(fmt.Sprintf("unexpected end of label value %q", p.currentLabelPair.GetValue()))
return nil
Expand Down