Skip to content

Commit

Permalink
chore: comments and use helper funcs
Browse files Browse the repository at this point in the history
Signed-off-by: Manik Rana <[email protected]>
  • Loading branch information
Maniktherana committed Aug 8, 2024
1 parent acbeb52 commit e725fcd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
13 changes: 4 additions & 9 deletions model/textparse/openmetricsparse.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ func (p *OpenMetricsParser) Exemplar(e *exemplar.Exemplar) bool {
// CreatedTimestamp returns the created timestamp for a current Metric if exists or nil.
// NOTE(Maniktherana): Might use additional CPU/mem resources due to deep copy of parser required for peeking given 1.0 OM specification on _created series.
func (p *OpenMetricsParser) CreatedTimestamp() *int64 {
if !typeRequiresCT(p.mtype) {
if !TypeRequiresCT(p.mtype) {
// Not a CT supported metric type, fast path.
return nil
}
Expand Down Expand Up @@ -302,8 +302,8 @@ func (p *OpenMetricsParser) CreatedTimestamp() *int64 {
}
}

// typeRequiresCT returns true if the metric type requires a _created timestamp.
func typeRequiresCT(t model.MetricType) bool {
// TypeRequiresCT returns true if the metric type requires a _created timestamp.
func TypeRequiresCT(t model.MetricType) bool {
switch t {
case model.MetricTypeCounter, model.MetricTypeSummary, model.MetricTypeHistogram:
return true
Expand Down Expand Up @@ -594,13 +594,8 @@ func (p *OpenMetricsParser) isCreatedSeries() bool {
var newLbs labels.Labels
p.Metric(&newLbs)
name := newLbs.Get(model.MetricNameLabel)
switch p.mtype {
case model.MetricTypeCounter, model.MetricTypeSummary, model.MetricTypeHistogram:
if strings.HasSuffix(name, "_created") {
if TypeRequiresCT(p.mtype) && strings.HasSuffix(name, "_created") {
return true
}
default:
break
}
return false
}
Expand Down
3 changes: 3 additions & 0 deletions model/textparse/openmetricsparse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,9 @@ func TestOMNullByteHandling(t *testing.T) {
}
}

// While not desirable, there are cases were CT fails to parse and
// these tests show them.
// TODO(maniktherana): Make sure OM 1.1/2.0 pass CT via metadata or exemplar-like to avoid this.
func TestCTParseFailures(t *testing.T) {
input := `# HELP something Histogram with _created between buckets and summary
# TYPE something histogram
Expand Down
6 changes: 2 additions & 4 deletions model/textparse/promparse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,8 @@ func checkParseResultsWithCT(t *testing.T, p Parser, exp []expectedParse, ctLine
if ctLinesRemoved {
// Are CT series skipped?
_, typ := p.Type()
if typ == model.MetricTypeCounter || typ == model.MetricTypeSummary || typ == model.MetricTypeHistogram {
if strings.HasSuffix(res.Get(labels.MetricName), "_created") {
t.Fatalf("we exped created lines skipped")
}
if TypeRequiresCT(typ) && strings.HasSuffix(res.Get(labels.MetricName), "_created") {
t.Fatalf("we exped created lines skipped")
}
}

Expand Down

0 comments on commit e725fcd

Please sign in to comment.