Merge pull request #14949 from Maniktherana/minor-fixes-ct

refac: make typeRequiresCT private
This commit is contained in:
Arthur Silva Sens 2024-09-20 17:41:06 +01:00 committed by GitHub
commit ca18f298e1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 5 additions and 5 deletions

View file

@ -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. // 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. // 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 { func (p *OpenMetricsParser) CreatedTimestamp() *int64 {
if !TypeRequiresCT(p.mtype) { if !typeRequiresCT(p.mtype) {
// Not a CT supported metric type, fast path. // Not a CT supported metric type, fast path.
return nil return nil
} }
@ -302,8 +302,8 @@ func (p *OpenMetricsParser) CreatedTimestamp() *int64 {
} }
} }
// TypeRequiresCT returns true if the metric type requires a _created timestamp. // typeRequiresCT returns true if the metric type requires a _created timestamp.
func TypeRequiresCT(t model.MetricType) bool { func typeRequiresCT(t model.MetricType) bool {
switch t { switch t {
case model.MetricTypeCounter, model.MetricTypeSummary, model.MetricTypeHistogram: case model.MetricTypeCounter, model.MetricTypeSummary, model.MetricTypeHistogram:
return true return true
@ -594,7 +594,7 @@ func (p *OpenMetricsParser) isCreatedSeries() bool {
var newLbs labels.Labels var newLbs labels.Labels
p.Metric(&newLbs) p.Metric(&newLbs)
name := newLbs.Get(model.MetricNameLabel) name := newLbs.Get(model.MetricNameLabel)
if TypeRequiresCT(p.mtype) && strings.HasSuffix(name, "_created") { if typeRequiresCT(p.mtype) && strings.HasSuffix(name, "_created") {
return true return true
} }
return false return false

View file

@ -214,7 +214,7 @@ func checkParseResultsWithCT(t *testing.T, p Parser, exp []expectedParse, ctLine
if ctLinesRemoved { if ctLinesRemoved {
// Are CT series skipped? // Are CT series skipped?
_, typ := p.Type() _, typ := p.Type()
if TypeRequiresCT(typ) && strings.HasSuffix(res.Get(labels.MetricName), "_created") { if typeRequiresCT(typ) && strings.HasSuffix(res.Get(labels.MetricName), "_created") {
t.Fatalf("we exped created lines skipped") t.Fatalf("we exped created lines skipped")
} }
} }