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

Discard Summary metrics #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
18 changes: 10 additions & 8 deletions cmd/prom-aggregation-gateway/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,10 @@ func mergeMetric(ty dto.MetricType, a, b *dto.Metric) *dto.Metric {
},
}

case dto.MetricType_SUMMARY:
// No way of merging summaries, abort.
default:
// No way of merging other metrics types, discard.
return nil
}

return nil
}

func mergeFamily(a, b *dto.MetricFamily) (*dto.MetricFamily, error) {
Expand Down Expand Up @@ -206,15 +204,19 @@ func (a *aggate) parseAndMerge(r io.Reader) error {
a.familiesLock.Lock()
defer a.familiesLock.Unlock()
for name, family := range inFamilies {
// Sort labels in case source sends them inconsistently
for _, m := range family.Metric {
sort.Sort(byName(m.Label))
// Discard unsupported types
if *family.Type == dto.MetricType_SUMMARY {
continue
}

if err := validateFamily(family); err != nil {
return err
}

// Sort labels in case source sends them inconsistently
for _, m := range family.Metric {
sort.Sort(byName(m.Label))
}

Comment on lines +215 to +219
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason to move this code?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea was to keep the validation first before doing actual work

// family must be sorted for the merge
sort.Sort(byLabel(family.Metric))

Expand Down
15 changes: 15 additions & 0 deletions cmd/prom-aggregation-gateway/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,20 @@ counter{b="b",a="a"} 2
reorderedLabelsResult = `# HELP counter A counter
# TYPE counter counter
counter{a="a",b="b"} 3
`

summaryInput = `# HELP cpu_temperature_celsius Current temperature of the CPU.
# TYPE cpu_temperature_celsius summary
cpu_temperature_celsius_sum 30.2
cpu_temperature_celsius_count 1
# HELP counter A counter
# TYPE counter counter
counter 1
`

summaryDiscardedOutput = `# HELP counter A counter
# TYPE counter counter
counter 2
`
)

Expand All @@ -153,6 +167,7 @@ func TestAggate(t *testing.T) {
{labelFields1, labelFields2, labelFieldResult, nil, nil},
{duplicateLabels, "", "", fmt.Errorf("%s", duplicateError), nil},
{reorderedLabels1, reorderedLabels2, reorderedLabelsResult, nil, nil},
{summaryInput, summaryInput, summaryDiscardedOutput, nil, nil},
} {
a := newAggate()

Expand Down