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

[fix] name_prefix invalid to prometheus sample #64

Merged
merged 3 commits into from
Jun 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions inputs/inputs.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@ func NewSamples(fields map[string]interface{}, labels ...map[string]string) []*t

func PushSamples(slist *list.SafeList, fields map[string]interface{}, labels ...map[string]string) {
for metric, value := range fields {
floatValue, err := conv.ToFloat64(value)
if err != nil {
continue
}
slist.PushFront(NewSample(metric, floatValue, labels...))
slist.PushFront(NewSample(metric, value, labels...))
}
}
10 changes: 8 additions & 2 deletions parser/prometheus/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ func (p *Parser) Parse(buf []byte, slist *list.SafeList) error {
} else if mf.GetType() == dto.MetricType_HISTOGRAM {
p.handleHistogram(m, tags, metricName, slist)
} else {
fields := getNameAndValue(m, metricName)
inputs.PushSamples(slist, fields, tags)
p.handleGaugeCounter(m, tags, metricName, slist)
}
}
}
Expand Down Expand Up @@ -113,6 +112,13 @@ func (p *Parser) handleHistogram(m *dto.Metric, tags map[string]string, metricNa
}
}

func (p *Parser) handleGaugeCounter(m *dto.Metric, tags map[string]string, metricName string, slist *list.SafeList) {
fields := getNameAndValue(m, metricName)
for metric, value := range fields {
slist.PushFront(inputs.NewSample(prom.BuildMetric(p.NamePrefix, metric, ""), value, tags))
}
}

// Get labels from metric
func (p *Parser) makeLabels(m *dto.Metric) map[string]string {
result := map[string]string{}
Expand Down