Validate checks a Config instance. It will return a ConfigurationError if the specified values don't make sense. nolint:gocyclo // This function's cyclomatic complexity has go beyond 100
()
| 612 | // |
| 613 | //nolint:gocyclo // This function's cyclomatic complexity has go beyond 100 |
| 614 | func (c *Config) Validate() error { |
| 615 | // some configuration values should be warned on but not fail completely, do those first |
| 616 | if !c.Net.TLS.Enable && c.Net.TLS.Config != nil { |
| 617 | Logger.Println("Net.TLS is disabled but a non-nil configuration was provided.") |
| 618 | } |
| 619 | if !c.Net.SASL.Enable { |
| 620 | if c.Net.SASL.User != "" { |
| 621 | Logger.Println("Net.SASL is disabled but a non-empty username was provided.") |
| 622 | } |
| 623 | if c.Net.SASL.Password != "" { |
| 624 | Logger.Println("Net.SASL is disabled but a non-empty password was provided.") |
| 625 | } |
| 626 | } |
| 627 | if c.Producer.RequiredAcks > 1 { |
| 628 | Logger.Println("Producer.RequiredAcks > 1 is deprecated and will raise an exception with kafka >= 0.8.2.0.") |
| 629 | } |
| 630 | if c.Producer.MaxMessageBytes >= int(MaxRequestSize) { |
| 631 | Logger.Println("Producer.MaxMessageBytes must be smaller than MaxRequestSize; it will be ignored.") |
| 632 | } |
| 633 | if c.Producer.Flush.Bytes >= int(MaxRequestSize) { |
| 634 | Logger.Println("Producer.Flush.Bytes must be smaller than MaxRequestSize; it will be ignored.") |
| 635 | } |
| 636 | if (c.Producer.Flush.Bytes > 0 || c.Producer.Flush.Messages > 0) && c.Producer.Flush.Frequency == 0 { |
| 637 | Logger.Println("Producer.Flush: Bytes or Messages are set, but Frequency is not; messages may not get flushed.") |
| 638 | } |
| 639 | if c.Producer.Timeout%time.Millisecond != 0 { |
| 640 | Logger.Println("Producer.Timeout only supports millisecond resolution; nanoseconds will be truncated.") |
| 641 | } |
| 642 | if c.Consumer.MaxWaitTime < 100*time.Millisecond { |
| 643 | Logger.Println("Consumer.MaxWaitTime is very low, which can cause high CPU and network usage. See documentation for details.") |
| 644 | } |
| 645 | if c.Consumer.MaxWaitTime%time.Millisecond != 0 { |
| 646 | Logger.Println("Consumer.MaxWaitTime only supports millisecond precision; nanoseconds will be truncated.") |
| 647 | } |
| 648 | if c.Consumer.Offsets.Retention%time.Millisecond != 0 { |
| 649 | Logger.Println("Consumer.Offsets.Retention only supports millisecond precision; nanoseconds will be truncated.") |
| 650 | } |
| 651 | if c.Consumer.Group.Session.Timeout%time.Millisecond != 0 { |
| 652 | Logger.Println("Consumer.Group.Session.Timeout only supports millisecond precision; nanoseconds will be truncated.") |
| 653 | } |
| 654 | if c.Consumer.Group.Heartbeat.Interval%time.Millisecond != 0 { |
| 655 | Logger.Println("Consumer.Group.Heartbeat.Interval only supports millisecond precision; nanoseconds will be truncated.") |
| 656 | } |
| 657 | if c.Consumer.Group.Rebalance.Timeout%time.Millisecond != 0 { |
| 658 | Logger.Println("Consumer.Group.Rebalance.Timeout only supports millisecond precision; nanoseconds will be truncated.") |
| 659 | } |
| 660 | if c.ClientID == defaultClientID { |
| 661 | Logger.Println("ClientID is the default of 'sarama', you should consider setting it to something application-specific.") |
| 662 | } |
| 663 | |
| 664 | // validate Net values |
| 665 | switch { |
| 666 | case c.Net.MaxOpenRequests <= 0: |
| 667 | return ConfigurationError("Net.MaxOpenRequests must be > 0") |
| 668 | case c.Net.DialTimeout <= 0: |
| 669 | return ConfigurationError("Net.DialTimeout must be > 0") |
| 670 | case c.Net.ReadTimeout <= 0: |
| 671 | return ConfigurationError("Net.ReadTimeout must be > 0") |