github.com/anuvu/tyk@v2.9.0-beta9-dl-apic+incompatible/checkup/checkup.go (about)

     1  package checkup
     2  
     3  import (
     4  	"runtime"
     5  	"syscall"
     6  
     7  	"github.com/TykTechnologies/tyk/config"
     8  	logger "github.com/TykTechnologies/tyk/log"
     9  )
    10  
    11  var (
    12  	log            = logger.Get().WithField("prefix", "checkup")
    13  	defaultConfigs = config.Config{
    14  		Secret:     "352d20ee67be67f6340b4c0605b044b7",
    15  		NodeSecret: "352d20ee67be67f6340b4c0605b044b7",
    16  	}
    17  )
    18  
    19  const (
    20  	minCPU             = 2
    21  	minFileDescriptors = 80000
    22  )
    23  
    24  func Run(c config.Config) {
    25  	legacyRateLimiters(c)
    26  	allowInsecureConfigs(c)
    27  	healthCheck(c)
    28  	fileDescriptors()
    29  	cpus()
    30  	defaultSecrets(c)
    31  }
    32  
    33  func legacyRateLimiters(c config.Config) {
    34  	if c.ManagementNode {
    35  		return
    36  	}
    37  	if c.EnableSentinelRateLimiter || c.EnableRedisRollingLimiter {
    38  		log.Warning("SentinelRateLimiter & RedisRollingLimiter are deprecated")
    39  	}
    40  }
    41  
    42  func allowInsecureConfigs(c config.Config) {
    43  	if c.AllowInsecureConfigs {
    44  		log.Warning("Insecure configuration allowed: allow_insecure_configs: true")
    45  	}
    46  }
    47  
    48  func healthCheck(c config.Config) {
    49  	if c.HealthCheck.EnableHealthChecks {
    50  		log.Warn("Health Checker is deprecated and not recommended")
    51  	}
    52  }
    53  
    54  func fileDescriptors() {
    55  	rlimit := &syscall.Rlimit{}
    56  	err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, rlimit)
    57  	if err == nil && rlimit.Cur < minFileDescriptors {
    58  		log.Warningf("File descriptor limit %d too low for production use. Min %d recommended.\n"+
    59  			"\tThis could have a significant negative impact on performance.\n"+
    60  			"\tPlease refer to https://tyk.io/docs/deploy-tyk-premise-production/#file-handles for further guidance.", rlimit.Cur, minFileDescriptors)
    61  	}
    62  }
    63  
    64  func cpus() {
    65  	cpus := runtime.NumCPU()
    66  	if cpus < minCPU {
    67  		log.Warningf("Num CPUs %d too low for production use. Min %d recommended.\n"+
    68  			"\tThis could have a significant negative impact on performance.\n"+
    69  			"\tPlease refer to https://tyk.io/docs/deploy-tyk-premise-production/#use-the-right-hardware for further guidance.", cpus, minCPU)
    70  	}
    71  }
    72  
    73  func defaultSecrets(c config.Config) {
    74  	if c.Secret == defaultConfigs.Secret {
    75  		log.Warningf("Default secret `%s` should be changed for production.", defaultConfigs.Secret)
    76  	}
    77  
    78  	if c.NodeSecret == defaultConfigs.NodeSecret {
    79  		log.Warningf("Default node_secret `%s` should be changed for production.", defaultConfigs.NodeSecret)
    80  	}
    81  }