Informer/disk: deprecate RepoSize metric
The allocator is hardcoded to descendalloc for freespace so it is not even useful as it would allocate to peers with largest reposize first no matter what. We are, in any case, reworking allocators and informers etc.
This commit is contained in:
parent
396a348a65
commit
3e54c4c695
|
@ -14,33 +14,19 @@ const envConfigKey = "cluster_disk"
|
|||
|
||||
// Default values for disk Config
|
||||
const (
|
||||
DefaultMetricTTL = 30 * time.Second
|
||||
DefaultMetricType = MetricFreeSpace
|
||||
DefaultMetricTTL = 30 * time.Second
|
||||
)
|
||||
|
||||
// String returns a string representation for MetricType.
|
||||
func (t MetricType) String() string {
|
||||
switch t {
|
||||
case MetricFreeSpace:
|
||||
return "freespace"
|
||||
case MetricRepoSize:
|
||||
return "reposize"
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// Config is used to initialize an Informer and customize
|
||||
// the type and parameters of the metric it produces.
|
||||
type Config struct {
|
||||
config.Saver
|
||||
|
||||
MetricTTL time.Duration
|
||||
MetricType MetricType
|
||||
MetricTTL time.Duration
|
||||
}
|
||||
|
||||
type jsonConfig struct {
|
||||
MetricTTL string `json:"metric_ttl"`
|
||||
MetricType string `json:"metric_type"`
|
||||
MetricTTL string `json:"metric_ttl"`
|
||||
}
|
||||
|
||||
// ConfigKey returns a human-friendly identifier for this type of Metric.
|
||||
|
@ -51,7 +37,6 @@ func (cfg *Config) ConfigKey() string {
|
|||
// Default initializes this Config with sensible values.
|
||||
func (cfg *Config) Default() error {
|
||||
cfg.MetricTTL = DefaultMetricTTL
|
||||
cfg.MetricType = DefaultMetricType
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -75,9 +60,6 @@ func (cfg *Config) Validate() error {
|
|||
return errors.New("disk.metric_ttl is invalid")
|
||||
}
|
||||
|
||||
if cfg.MetricType.String() == "" {
|
||||
return errors.New("disk.metric_type is invalid")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -100,15 +82,6 @@ func (cfg *Config) applyJSONConfig(jcfg *jsonConfig) error {
|
|||
t, _ := time.ParseDuration(jcfg.MetricTTL)
|
||||
cfg.MetricTTL = t
|
||||
|
||||
switch jcfg.MetricType {
|
||||
case "reposize":
|
||||
cfg.MetricType = MetricRepoSize
|
||||
case "freespace":
|
||||
cfg.MetricType = MetricFreeSpace
|
||||
default:
|
||||
return errors.New("disk.metric_type is invalid")
|
||||
}
|
||||
|
||||
return cfg.Validate()
|
||||
}
|
||||
|
||||
|
@ -123,8 +96,7 @@ func (cfg *Config) ToJSON() (raw []byte, err error) {
|
|||
|
||||
func (cfg *Config) toJSONConfig() *jsonConfig {
|
||||
return &jsonConfig{
|
||||
MetricTTL: cfg.MetricTTL.String(),
|
||||
MetricType: cfg.MetricType.String(),
|
||||
MetricTTL: cfg.MetricTTL.String(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -30,25 +30,6 @@ func TestLoadJSON(t *testing.T) {
|
|||
if err == nil {
|
||||
t.Error("expected error decoding metric_ttl")
|
||||
}
|
||||
|
||||
j = &jsonConfig{}
|
||||
json.Unmarshal(cfgJSON, j)
|
||||
j.MetricType = "abc"
|
||||
tst, _ = json.Marshal(j)
|
||||
err = cfg.LoadJSON(tst)
|
||||
if err == nil {
|
||||
t.Error("expected error decoding check_interval")
|
||||
}
|
||||
|
||||
j = &jsonConfig{}
|
||||
json.Unmarshal(cfgJSON, j)
|
||||
j.MetricType = "reposize"
|
||||
tst, _ = json.Marshal(j)
|
||||
err = cfg.LoadJSON(tst)
|
||||
if err != nil {
|
||||
t.Error("reposize should be a valid type")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestToJSON(t *testing.T) {
|
||||
|
@ -76,12 +57,6 @@ func TestDefault(t *testing.T) {
|
|||
if cfg.Validate() == nil {
|
||||
t.Fatal("expected error validating")
|
||||
}
|
||||
|
||||
cfg.Default()
|
||||
cfg.MetricType = MetricRepoSize
|
||||
if cfg.Validate() != nil {
|
||||
t.Fatal("MetricRepoSize is a valid type")
|
||||
}
|
||||
}
|
||||
|
||||
func TestApplyEnvVars(t *testing.T) {
|
||||
|
|
|
@ -50,7 +50,7 @@ func NewInformer(cfg *Config) (*Informer, error) {
|
|||
|
||||
// Name returns the user-facing name of this informer.
|
||||
func (disk *Informer) Name() string {
|
||||
return disk.config.MetricType.String()
|
||||
return "reposize"
|
||||
}
|
||||
|
||||
// SetClient provides us with an rpc.Client which allows
|
||||
|
@ -108,17 +108,12 @@ func (disk *Informer) GetMetric(ctx context.Context) *api.Metric {
|
|||
logger.Error(err)
|
||||
valid = false
|
||||
} else {
|
||||
switch disk.config.MetricType {
|
||||
case MetricFreeSpace:
|
||||
size := repoStat.RepoSize
|
||||
total := repoStat.StorageMax
|
||||
if size < total {
|
||||
metric = total - size
|
||||
} else { // Make sure we don't underflow
|
||||
metric = 0
|
||||
}
|
||||
case MetricRepoSize:
|
||||
metric = repoStat.RepoSize
|
||||
size := repoStat.RepoSize
|
||||
total := repoStat.StorageMax
|
||||
if size < total {
|
||||
metric = total - size
|
||||
} else { // Make sure we don't underflow
|
||||
metric = 0
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -52,7 +52,6 @@ func TestFreeSpace(t *testing.T) {
|
|||
ctx := context.Background()
|
||||
cfg := &Config{}
|
||||
cfg.Default()
|
||||
cfg.MetricType = MetricFreeSpace
|
||||
|
||||
inf, err := NewInformer(cfg)
|
||||
if err != nil {
|
||||
|
@ -74,32 +73,6 @@ func TestFreeSpace(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestRepoSize(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
cfg := &Config{}
|
||||
cfg.Default()
|
||||
cfg.MetricType = MetricRepoSize
|
||||
|
||||
inf, err := NewInformer(cfg)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer inf.Shutdown(ctx)
|
||||
m := inf.GetMetric(ctx)
|
||||
if m.Valid {
|
||||
t.Error("metric should be invalid")
|
||||
}
|
||||
inf.SetClient(test.NewMockRPCClient(t))
|
||||
m = inf.GetMetric(ctx)
|
||||
if !m.Valid {
|
||||
t.Error("metric should be valid")
|
||||
}
|
||||
// The mock client reports 100KB and 2 pins of 1 KB
|
||||
if m.Value != "2000" {
|
||||
t.Error("bad metric value")
|
||||
}
|
||||
}
|
||||
|
||||
func TestWithErrors(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
cfg := &Config{}
|
||||
|
|
Loading…
Reference in New Issue
Block a user