github.com/yankunsam/loki/v2@v2.6.3-0.20220817130409-389df5235c27/clients/pkg/promtail/client/config.go (about) 1 package client 2 3 import ( 4 "flag" 5 "time" 6 7 "github.com/grafana/dskit/backoff" 8 "github.com/grafana/dskit/flagext" 9 "github.com/prometheus/common/config" 10 11 lokiflag "github.com/grafana/loki/pkg/util/flagext" 12 ) 13 14 // NOTE the helm chart for promtail and fluent-bit also have defaults for these values, please update to match if you make changes here. 15 const ( 16 BatchWait = 1 * time.Second 17 BatchSize int = 1024 * 1024 18 MinBackoff = 500 * time.Millisecond 19 MaxBackoff = 5 * time.Minute 20 MaxRetries int = 10 21 Timeout = 10 * time.Second 22 ) 23 24 // Config describes configuration for an HTTP pusher client. 25 type Config struct { 26 Name string `yaml:"name,omitempty"` 27 URL flagext.URLValue 28 BatchWait time.Duration 29 BatchSize int 30 31 Client config.HTTPClientConfig `yaml:",inline"` 32 33 BackoffConfig backoff.Config `yaml:"backoff_config"` 34 // The labels to add to any time series or alerts when communicating with loki 35 ExternalLabels lokiflag.LabelSet `yaml:"external_labels,omitempty"` 36 Timeout time.Duration `yaml:"timeout"` 37 38 // The tenant ID to use when pushing logs to Loki (empty string means 39 // single tenant mode) 40 TenantID string `yaml:"tenant_id"` 41 42 // deprecated use StreamLagLabels from config.Config instead 43 StreamLagLabels flagext.StringSliceCSV `yaml:"stream_lag_labels"` 44 } 45 46 // RegisterFlags with prefix registers flags where every name is prefixed by 47 // prefix. If prefix is a non-empty string, prefix should end with a period. 48 func (c *Config) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet) { 49 f.Var(&c.URL, prefix+"client.url", "URL of log server (deprecated).") 50 f.DurationVar(&c.BatchWait, prefix+"client.batch-wait", BatchWait, "Maximum wait period before sending batch (deprecated).") 51 f.IntVar(&c.BatchSize, prefix+"client.batch-size-bytes", BatchSize, "Maximum batch size to accrue before sending (deprecated).") 52 // Default backoff schedule: 0.5s, 1s, 2s, 4s, 8s, 16s, 32s, 64s, 128s, 256s(4.267m) For a total time of 511.5s(8.5m) before logs are lost 53 f.IntVar(&c.BackoffConfig.MaxRetries, prefix+"client.max-retries", MaxRetries, "Maximum number of retires when sending batches (deprecated).") 54 f.DurationVar(&c.BackoffConfig.MinBackoff, prefix+"client.min-backoff", MinBackoff, "Initial backoff time between retries (deprecated).") 55 f.DurationVar(&c.BackoffConfig.MaxBackoff, prefix+"client.max-backoff", MaxBackoff, "Maximum backoff time between retries (deprecated).") 56 f.DurationVar(&c.Timeout, prefix+"client.timeout", Timeout, "Maximum time to wait for server to respond to a request (deprecated).") 57 f.Var(&c.ExternalLabels, prefix+"client.external-labels", "list of external labels to add to each log (e.g: --client.external-labels=lb1=v1,lb2=v2) (deprecated).") 58 59 f.StringVar(&c.TenantID, prefix+"client.tenant-id", "", "Tenant ID to use when pushing logs to Loki (deprecated).") 60 } 61 62 // RegisterFlags registers flags. 63 func (c *Config) RegisterFlags(flags *flag.FlagSet) { 64 c.RegisterFlagsWithPrefix("", flags) 65 } 66 67 // UnmarshalYAML implement Yaml Unmarshaler 68 func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error { 69 type raw Config 70 var cfg raw 71 if c.URL.URL != nil { 72 // we used flags to set that value, which already has sane default. 73 cfg = raw(*c) 74 } else { 75 // force sane defaults. 76 cfg = raw{ 77 BackoffConfig: backoff.Config{ 78 MaxBackoff: MaxBackoff, 79 MaxRetries: MaxRetries, 80 MinBackoff: MinBackoff, 81 }, 82 BatchSize: BatchSize, 83 BatchWait: BatchWait, 84 Timeout: Timeout, 85 } 86 } 87 88 if err := unmarshal(&cfg); err != nil { 89 return err 90 } 91 92 *c = Config(cfg) 93 return nil 94 }