config.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package lancergrpc
  2. import (
  3. "errors"
  4. "time"
  5. "go-common/app/service/ops/log-agent/output/cache/file"
  6. streamEvent "go-common/app/service/ops/log-agent/output/lancergrpc/lancergateway"
  7. xtime "go-common/library/time"
  8. "github.com/BurntSushi/toml"
  9. )
  10. type Config struct {
  11. Local bool `tome:"local"`
  12. Name string `tome:"name"`
  13. AggrSize int `tome:"aggrSize"`
  14. SendConcurrency int `tome:"sendConcurrency"`
  15. CacheConfig *file.Config `tome:"cacheConfig"`
  16. LancerGateway *streamEvent.Config `tome:"lancerGateway"`
  17. SendBatchSize int `tome:"sendBatchSize"`
  18. SendBatchNum int `tome:"sendBatchNum"`
  19. SendBatchTimeout xtime.Duration `tome:"sendBatchTimeout"`
  20. SendFlushInterval xtime.Duration `tome:"sendFlushInterval"`
  21. InitialRetryDuration xtime.Duration `tome:"initialRetryDuration"`
  22. MaxRetryDuration xtime.Duration `tome:"maxRetryDuration"`
  23. }
  24. func (c *Config) ConfigValidate() (error) {
  25. if c == nil {
  26. return errors.New("config of Lancer Output is nil")
  27. }
  28. if c.Name == "" {
  29. return errors.New("output Name can't be nil")
  30. }
  31. if c.AggrSize == 0 {
  32. c.AggrSize = 819200
  33. }
  34. if c.SendConcurrency == 0 {
  35. c.SendConcurrency = 5
  36. }
  37. if err := c.CacheConfig.ConfigValidate(); err != nil {
  38. return err
  39. }
  40. if c.SendFlushInterval == 0 {
  41. c.SendFlushInterval = xtime.Duration(time.Second * 5)
  42. }
  43. if c.InitialRetryDuration == 0 {
  44. c.InitialRetryDuration = xtime.Duration(time.Millisecond * 200)
  45. }
  46. if c.MaxRetryDuration == 0 {
  47. c.MaxRetryDuration = xtime.Duration(time.Second * 2)
  48. }
  49. if c.SendBatchNum == 0 {
  50. c.SendBatchNum = 3000
  51. }
  52. if c.SendBatchSize == 0 {
  53. c.SendBatchSize = 1024 * 1024 * 10
  54. }
  55. if c.SendBatchTimeout == 0 {
  56. c.SendBatchTimeout = xtime.Duration(time.Second * 5)
  57. }
  58. if c.LancerGateway == nil {
  59. c.LancerGateway = &streamEvent.Config{}
  60. }
  61. if err := c.LancerGateway.ConfigValidate(); err != nil {
  62. return err
  63. }
  64. return nil
  65. }
  66. func DecodeConfig(md toml.MetaData, primValue toml.Primitive) (c interface{}, err error) {
  67. c = new(Config)
  68. if err = md.PrimitiveDecode(primValue, c); err != nil {
  69. return nil, err
  70. }
  71. return c, nil
  72. }