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:
Hector Sanjuan 2021-09-08 17:36:54 +02:00
parent 396a348a65
commit 3e54c4c695
4 changed files with 11 additions and 96 deletions

View File

@ -15,32 +15,18 @@ const envConfigKey = "cluster_disk"
// Default values for disk Config
const (
DefaultMetricTTL = 30 * time.Second
DefaultMetricType = MetricFreeSpace
)
// 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
}
type jsonConfig struct {
MetricTTL string `json:"metric_ttl"`
MetricType string `json:"metric_type"`
}
// 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()
}
@ -124,7 +97,6 @@ func (cfg *Config) ToJSON() (raw []byte, err error) {
func (cfg *Config) toJSONConfig() *jsonConfig {
return &jsonConfig{
MetricTTL: cfg.MetricTTL.String(),
MetricType: cfg.MetricType.String(),
}
}

View File

@ -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) {

View File

@ -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,8 +108,6 @@ 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 {
@ -117,9 +115,6 @@ func (disk *Informer) GetMetric(ctx context.Context) *api.Metric {
} else { // Make sure we don't underflow
metric = 0
}
case MetricRepoSize:
metric = repoStat.RepoSize
}
}
m := &api.Metric{

View File

@ -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{}