-
Notifications
You must be signed in to change notification settings - Fork 343
Decoder: Remove use of global name validation and add validation #808
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -78,6 +78,9 @@ type TextParser struct { | |
| // These indicate if the metric name from the current line being parsed is inside | ||
| // braces and if that metric name was found respectively. | ||
| currentMetricIsInsideBraces, currentMetricInsideBracesIsPresent bool | ||
| // scheme sets the desired ValidationScheme for names. Defaults to the invalid | ||
| // UnsetValidation. | ||
| scheme model.ValidationScheme | ||
| } | ||
|
|
||
| // TextToMetricFamilies reads 'in' as the simple and flat text-based exchange | ||
|
|
@@ -126,6 +129,7 @@ func (p *TextParser) TextToMetricFamilies(in io.Reader) (map[string]*dto.MetricF | |
|
|
||
| func (p *TextParser) reset(in io.Reader) { | ||
| p.metricFamiliesByName = map[string]*dto.MetricFamily{} | ||
| p.currentLabelPairs = nil | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the fact that this member was not reset does not bode well for the correctness of the whole parser
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. It also proves it's not heavily used (: |
||
| if p.buf == nil { | ||
| p.buf = bufio.NewReader(in) | ||
| } else { | ||
|
|
@@ -216,6 +220,9 @@ func (p *TextParser) startComment() stateFn { | |
| return nil | ||
| } | ||
| p.setOrCreateCurrentMF() | ||
| if p.err != nil { | ||
| return nil | ||
| } | ||
| if p.skipBlankTab(); p.err != nil { | ||
| return nil // Unexpected end of input. | ||
| } | ||
|
|
@@ -244,6 +251,9 @@ func (p *TextParser) readingMetricName() stateFn { | |
| return nil | ||
| } | ||
| p.setOrCreateCurrentMF() | ||
| if p.err != nil { | ||
| return nil | ||
| } | ||
| // Now is the time to fix the type if it hasn't happened yet. | ||
| if p.currentMF.Type == nil { | ||
| p.currentMF.Type = dto.MetricType_UNTYPED.Enum() | ||
|
|
@@ -311,6 +321,9 @@ func (p *TextParser) startLabelName() stateFn { | |
| switch p.currentByte { | ||
| case ',': | ||
| p.setOrCreateCurrentMF() | ||
| if p.err != nil { | ||
| return nil | ||
| } | ||
| if p.currentMF.Type == nil { | ||
| p.currentMF.Type = dto.MetricType_UNTYPED.Enum() | ||
| } | ||
|
|
@@ -319,6 +332,10 @@ func (p *TextParser) startLabelName() stateFn { | |
| return p.startLabelName | ||
| case '}': | ||
| p.setOrCreateCurrentMF() | ||
| if p.err != nil { | ||
| p.currentLabelPairs = nil | ||
| return nil | ||
| } | ||
| if p.currentMF.Type == nil { | ||
| p.currentMF.Type = dto.MetricType_UNTYPED.Enum() | ||
| } | ||
|
|
@@ -341,6 +358,12 @@ func (p *TextParser) startLabelName() stateFn { | |
| p.currentLabelPair = &dto.LabelPair{Name: proto.String(p.currentToken.String())} | ||
| if p.currentLabelPair.GetName() == string(model.MetricNameLabel) { | ||
| p.parseError(fmt.Sprintf("label name %q is reserved", model.MetricNameLabel)) | ||
| p.currentLabelPairs = nil | ||
| return nil | ||
| } | ||
| if !p.scheme.IsValidLabelName(p.currentLabelPair.GetName()) { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these checks were not done at all previously |
||
| p.parseError(fmt.Sprintf("invalid label name %q", p.currentLabelPair.GetName())) | ||
| p.currentLabelPairs = nil | ||
| return nil | ||
| } | ||
| // Special summary/histogram treatment. Don't add 'quantile' and 'le' | ||
|
|
@@ -805,6 +828,10 @@ func (p *TextParser) setOrCreateCurrentMF() { | |
| p.currentIsHistogramCount = false | ||
| p.currentIsHistogramSum = false | ||
| name := p.currentToken.String() | ||
| if !p.scheme.IsValidMetricName(name) { | ||
| p.parseError(fmt.Sprintf("invalid metric name %q", name)) | ||
| return | ||
| } | ||
| if p.currentMF = p.metricFamiliesByName[name]; p.currentMF != nil { | ||
| return | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.