pool: Fix logic of falling back to replicated expansion in computation of ExpansionFactor.
The code was assuming that the command would succeed with empty output if a non-EC profile was given, when in fact it fails. Re-work the code to properly handle this case.
This commit is contained in:
parent
dc4541a398
commit
32de4574a5
|
@ -16,6 +16,7 @@ package collectors
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/ceph/go-ceph/rados"
|
||||
|
@ -157,6 +158,9 @@ func (n *NoopConn) MonCommand(args []byte) ([]byte, string, error) {
|
|||
"w": "8"
|
||||
}`
|
||||
return []byte(ec42Return), "", nil
|
||||
|
||||
default:
|
||||
return []byte(""), "", errors.New("unknown erasure code profile")
|
||||
}
|
||||
|
||||
case "osd erasure-code-profile get replicated-ruleset":
|
||||
|
|
|
@ -221,7 +221,7 @@ func (p *PoolInfoCollector) collect() error {
|
|||
p.QuotaMaxBytes.WithLabelValues(pool.Name, pool.Profile).Set(pool.QuotaMaxBytes)
|
||||
p.QuotaMaxObjects.WithLabelValues(pool.Name, pool.Profile).Set(pool.QuotaMaxObjects)
|
||||
p.StripeWidth.WithLabelValues(pool.Name, pool.Profile).Set(pool.StripeWidth)
|
||||
p.ExpansionFactor.WithLabelValues(pool.Name, pool.Profile).Set(p.getExpansionCommand(pool))
|
||||
p.ExpansionFactor.WithLabelValues(pool.Name, pool.Profile).Set(p.getExpansionFactor(pool))
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -262,7 +262,15 @@ func (p *PoolInfoCollector) Collect(ch chan<- prometheus.Metric) {
|
|||
}
|
||||
}
|
||||
|
||||
func (p *PoolInfoCollector) getExpansionCommand(pool poolInfo) float64 {
|
||||
func (p *PoolInfoCollector) getExpansionFactor(pool poolInfo) float64 {
|
||||
if ef, ok := p.getECExpansionFactor(pool); ok {
|
||||
return ef
|
||||
}
|
||||
// Non-EC pool (or unable to get profile info); assume that it's replicated.
|
||||
return pool.ActualSize
|
||||
}
|
||||
|
||||
func (p *PoolInfoCollector) getECExpansionFactor(pool poolInfo) (float64, bool) {
|
||||
prefix := fmt.Sprintf("osd erasure-code-profile get")
|
||||
cmd, err := json.Marshal(map[string]interface{}{
|
||||
"prefix": prefix,
|
||||
|
@ -272,7 +280,7 @@ func (p *PoolInfoCollector) getExpansionCommand(pool poolInfo) float64 {
|
|||
|
||||
buf, _, err := p.conn.MonCommand(cmd)
|
||||
if err != nil {
|
||||
return -1
|
||||
return -1, false
|
||||
}
|
||||
|
||||
type ecInfo struct {
|
||||
|
@ -283,7 +291,7 @@ func (p *PoolInfoCollector) getExpansionCommand(pool poolInfo) float64 {
|
|||
ecStats := ecInfo{}
|
||||
err = json.Unmarshal(buf, &ecStats)
|
||||
if err != nil || ecStats.K == "" || ecStats.M == "" {
|
||||
return pool.ActualSize
|
||||
return -1, false
|
||||
}
|
||||
|
||||
k, _ := strconv.ParseFloat(ecStats.K, 64)
|
||||
|
@ -291,5 +299,5 @@ func (p *PoolInfoCollector) getExpansionCommand(pool poolInfo) float64 {
|
|||
|
||||
expansionFactor := (k + m) / k
|
||||
roundedExpansion := math.Round(expansionFactor*100) / 100
|
||||
return roundedExpansion
|
||||
return roundedExpansion, true
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue