Skip to content

Commit

Permalink
Fix grouping of metrics with shared prefix
Browse files Browse the repository at this point in the history
Naive sorting messes up the order of submetrics when they share a common
prefix. Providing a custom sort function makes sure that "longer" metric
names (without the submetric filter) are sorted after all submetrics of
the previous metric.

Example before:

    prefix...............: 1   414.40196/s
    prefix_suffix........: 1   414.40196/s
      { sub:two }........: 1   414.40196/s
      { sub:one }........: 1   414.40196/s

Example after:

    prefix...............: 1   414.40196/s
      { sub:one }........: 1   414.40196/s
    prefix_suffix........: 1   414.40196/s
      { sub:two }........: 1   414.40196/s

Closes grafana#2194
  • Loading branch information
knittl authored and na-- committed Oct 29, 2021
1 parent db955d0 commit b5a7d79
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion js/summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,18 @@ function summarizeMetrics(options, data, decorate) {
}
})

names.sort()
// sort all metrics but keep sub metrics grouped with their parent metrics
names.sort(function (metric1, metric2) {
var parent1 = metric1.split('{', 1)[0]
var parent2 = metric2.split('{', 1)[0]
var result = parent1.localeCompare(parent2)
if (result !== 0) {
return result
}
var sub1 = metric1.substring(parent1.length)
var sub2 = metric2.substring(parent2.length)
return sub1.localeCompare(sub2)
})

var getData = function (name) {
if (trendCols.hasOwnProperty(name)) {
Expand Down

0 comments on commit b5a7d79

Please sign in to comment.