github.com/kyma-incubator/compass/components/director@v0.0.0-20230623144113-d764f56ff805/internal/healthz/config.go (about)

     1  package healthz
     2  
     3  import (
     4  	"fmt"
     5  	"time"
     6  
     7  	"github.com/pkg/errors"
     8  )
     9  
    10  // DefaultName missing godoc
    11  const DefaultName = "default"
    12  
    13  // IndicatorConfig missing godoc
    14  type IndicatorConfig struct {
    15  	Name         string        `envconfig:"default=default"`
    16  	Interval     time.Duration `envconfig:"default=5s"`
    17  	Timeout      time.Duration `envconfig:"default=1s"`
    18  	InitialDelay time.Duration `envconfig:"default=1s"`
    19  	Threshold    int           `envconfig:"default=3"`
    20  }
    21  
    22  // NewDefaultConfig missing godoc
    23  func NewDefaultConfig() IndicatorConfig {
    24  	return IndicatorConfig{
    25  		Name:         DefaultName,
    26  		Interval:     5 * time.Second,
    27  		Timeout:      time.Second,
    28  		InitialDelay: time.Second,
    29  		Threshold:    3,
    30  	}
    31  }
    32  
    33  // Validate missing godoc
    34  func (ic *IndicatorConfig) Validate() error {
    35  	if ic.Interval <= 0 {
    36  		return errors.New("interval could not be <= 0")
    37  	}
    38  	if ic.Timeout <= 0 {
    39  		return errors.New("timeout could not be <= 0")
    40  	}
    41  	if ic.InitialDelay < 0 {
    42  		return errors.New("initial delay could not be < 0")
    43  	}
    44  	if ic.Threshold < 0 {
    45  		return errors.New("threshold could not be < 0")
    46  	}
    47  	return nil
    48  }
    49  
    50  // Config missing godoc
    51  type Config struct {
    52  	Indicators []IndicatorConfig
    53  }
    54  
    55  // Validate missing godoc
    56  func (c *Config) Validate() error {
    57  	for _, ind := range c.Indicators {
    58  		if err := ind.Validate(); err != nil {
    59  			return errors.Wrap(err, fmt.Sprintf("%s indicator", ind.Name))
    60  		}
    61  	}
    62  	return nil
    63  }