fix: redundant zfs pool tag (#10871)
This commit is contained in:
parent
93a2202e73
commit
b9151ff560
|
|
@ -68,13 +68,17 @@ func getPools(kstatPath string) ([]poolInfo, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func getTags(pools []poolInfo) map[string]string {
|
func getTags(pools []poolInfo) map[string]string {
|
||||||
var poolNames string
|
poolNames := ""
|
||||||
|
knownPools := make(map[string]struct{})
|
||||||
for _, pool := range pools {
|
for _, entry := range pools {
|
||||||
if len(poolNames) != 0 {
|
name := entry.name
|
||||||
poolNames += "::"
|
if _, ok := knownPools[name]; !ok {
|
||||||
|
knownPools[name] = struct{}{}
|
||||||
|
if poolNames != "" {
|
||||||
|
poolNames += "::"
|
||||||
|
}
|
||||||
|
poolNames += name
|
||||||
}
|
}
|
||||||
poolNames += pool.name
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return map[string]string{"pools": poolNames}
|
return map[string]string{"pools": poolNames}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
package zfs
|
package zfs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
|
@ -323,6 +324,43 @@ func TestZfsGeneratesMetrics(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetTags(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
pools []poolInfo
|
||||||
|
expected map[string]string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
"no pools",
|
||||||
|
[]poolInfo{},
|
||||||
|
map[string]string{"pools": ""},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"single pool",
|
||||||
|
[]poolInfo{
|
||||||
|
{"data", "/proc/spl/kstat/zfs/data/objset-0x9288", v2},
|
||||||
|
},
|
||||||
|
map[string]string{"pools": "data"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"duplicate pool names",
|
||||||
|
[]poolInfo{
|
||||||
|
{"pool", "/proc/spl/kstat/zfs/pool/objset-0x23ce1", v2},
|
||||||
|
{"pool", "/proc/spl/kstat/zfs/pool/objset-0x2e", v2},
|
||||||
|
{"data", "/proc/spl/kstat/zfs/data/objset-0x9288", v2},
|
||||||
|
},
|
||||||
|
map[string]string{"pools": "pool::data"},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range tests {
|
||||||
|
t.Run(fmt.Sprintf(tc.name), func(t *testing.T) {
|
||||||
|
tags := getTags(tc.pools)
|
||||||
|
require.Equal(t, tc.expected, tags)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func getKstatMetricsArcOnly() map[string]interface{} {
|
func getKstatMetricsArcOnly() map[string]interface{} {
|
||||||
return map[string]interface{}{
|
return map[string]interface{}{
|
||||||
"arcstats_hits": int64(5968846374),
|
"arcstats_hits": int64(5968846374),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue