diff --git a/informer/disk/config.go b/informer/disk/config.go index e7cec8b2..961cf068 100644 --- a/informer/disk/config.go +++ b/informer/disk/config.go @@ -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(), } } diff --git a/informer/disk/config_test.go b/informer/disk/config_test.go index acfc2116..4d3adeed 100644 --- a/informer/disk/config_test.go +++ b/informer/disk/config_test.go @@ -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) { diff --git a/informer/disk/disk.go b/informer/disk/disk.go index f3ff237b..804fb518 100644 --- a/informer/disk/disk.go +++ b/informer/disk/disk.go @@ -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 } } diff --git a/informer/disk/disk_test.go b/informer/disk/disk_test.go index a4c4dbcc..2b393c0b 100644 --- a/informer/disk/disk_test.go +++ b/informer/disk/disk_test.go @@ -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{}