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 {
|
||||
var poolNames string
|
||||
|
||||
for _, pool := range pools {
|
||||
if len(poolNames) != 0 {
|
||||
poolNames += "::"
|
||||
poolNames := ""
|
||||
knownPools := make(map[string]struct{})
|
||||
for _, entry := range pools {
|
||||
name := entry.name
|
||||
if _, ok := knownPools[name]; !ok {
|
||||
knownPools[name] = struct{}{}
|
||||
if poolNames != "" {
|
||||
poolNames += "::"
|
||||
}
|
||||
poolNames += name
|
||||
}
|
||||
poolNames += pool.name
|
||||
}
|
||||
|
||||
return map[string]string{"pools": poolNames}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
package zfs
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
|
|
@ -323,6 +324,43 @@ func TestZfsGeneratesMetrics(t *testing.T) {
|
|||
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{} {
|
||||
return map[string]interface{}{
|
||||
"arcstats_hits": int64(5968846374),
|
||||
|
|
|
|||
Loading…
Reference in New Issue