Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'er-pa/ursrv-storage' into infra-test-ursrv
* er-pa/ursrv-storage: Adjust compatibility env address Add copyright notes multi-instance support for incoming reports code style unused param wip wip wip cmd/ursrv: Improve data storage and aggregation (fixes #9212)
- Loading branch information
Showing
18 changed files
with
1,674 additions
and
1,116 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright (C) 2024 The Syncthing Authors. | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
package aggregate | ||
|
||
import ( | ||
"regexp" | ||
"strings" | ||
"unicode" | ||
) | ||
|
||
var ( | ||
plusRe = regexp.MustCompile(`(\+.*|\.dev\..*)$`) | ||
plusStr = "(+dev)" | ||
) | ||
|
||
func prettyCase(input string) string { | ||
output := "" | ||
for i, runeValue := range input { | ||
if i == 0 { | ||
runeValue = unicode.ToUpper(runeValue) | ||
} else if unicode.IsUpper(runeValue) { | ||
output += " " | ||
} | ||
output += string(runeValue) | ||
} | ||
return output | ||
} | ||
|
||
// transformVersion returns a version number formatted correctly, with all | ||
// development versions aggregated into one. | ||
func transformVersion(v string) string { | ||
if v == "unknown-dev" { | ||
return v | ||
} | ||
if !strings.HasPrefix(v, "v") { | ||
v = "v" + v | ||
} | ||
v = plusRe.ReplaceAllString(v, " "+plusStr) | ||
|
||
return v | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright (C) 2024 The Syncthing Authors. | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
package aggregate | ||
|
||
import "github.com/syncthing/syncthing/cmd/ursrv/report" | ||
|
||
// add sets a key in a nested map, initializing things if needed as we go. | ||
func add(storage map[string]map[string]int, parent, child string, value int) { | ||
n, ok := storage[parent] | ||
if !ok { | ||
n = make(map[string]int) | ||
storage[parent] = n | ||
} | ||
n[child] += value | ||
} | ||
|
||
// inc makes sure that even for unused features, we initialize them in the | ||
// feature map. Furthermore, this acts as a helper that accepts booleans | ||
// to increment by one, or integers to increment by that integer. | ||
func inc(storage map[string]int, key string, i interface{}) { | ||
cv := storage[key] | ||
switch v := i.(type) { | ||
case bool: | ||
if v { | ||
cv++ | ||
} | ||
case int: | ||
cv += v | ||
} | ||
storage[key] = cv | ||
} | ||
|
||
type sortableFeatureList []report.Feature | ||
|
||
func (l sortableFeatureList) Less(a, b int) bool { | ||
if l[a].Pct != l[b].Pct { | ||
return l[a].Pct < l[b].Pct | ||
} | ||
return l[a].Key > l[b].Key | ||
} | ||
|
||
func (l sortableFeatureList) Swap(a, b int) { | ||
l[a], l[b] = l[b], l[a] | ||
} | ||
|
||
func (l sortableFeatureList) Len() int { | ||
return len(l) | ||
} |
Oops, something went wrong.