Debian Codegraph @

processor/batchprocessor/config.go

raw
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3
4 package batchprocessor // import "go.opentelemetry.io/collector/processor/batchprocessor"
5
6 import (
7 "errors"
8 "fmt"
9 "strings"
10 "time"
11
12 "go.opentelemetry.io/collector/component"
13 )
14
15 // Config defines configuration for batch processor.
16 type Config struct {
17 // Timeout sets the time after which a batch will be sent regardless of size.
18 // When this is set to zero, batched data will be sent immediately.
19 Timeout time.Duration `mapstructure:"timeout"`
20
21 // SendBatchSize is the size of a batch which after hit, will trigger it to be sent.
22 // When this is set to zero, the batch size is ignored and data will be sent immediately
23 // subject to only send_batch_max_size.
24 SendBatchSize uint32 `mapstructure:"send_batch_size"`
25
26 // SendBatchMaxSize is the maximum size of a batch. It must be larger than SendBatchSize.
27 // Larger batches are split into smaller units.
28 // Default value is 0, that means no maximum size.
29 SendBatchMaxSize uint32 `mapstructure:"send_batch_max_size"`
30
31 // MetadataKeys is a list of client.Metadata keys that will be
32 // used to form distinct batchers. If this setting is empty,
33 // a single batcher instance will be used. When this setting
34 // is not empty, one batcher will be used per distinct
35 // combination of values for the listed metadata keys.
36 //
37 // Empty value and unset metadata are treated as distinct cases.
38 //
39 // Entries are case-insensitive. Duplicated entries will
40 // trigger a validation error.
41 MetadataKeys []string `mapstructure:"metadata_keys"`
42
43 // MetadataCardinalityLimit indicates the maximum number of
44 // batcher instances that will be created through a distinct
45 // combination of MetadataKeys.
46 MetadataCardinalityLimit uint32 `mapstructure:"metadata_cardinality_limit"`
47 // prevent unkeyed literal initialization
48 _ struct{}
49 }
50
51 var _ component.Config = (*Config)(nil)
52
53 // Validate checks if the processor configuration is valid
54 func (cfg *Config) Validate() error {
55 if cfg.SendBatchMaxSize > 0 && cfg.SendBatchMaxSize < cfg.SendBatchSize {
56 return errors.New("send_batch_max_size must be greater or equal to send_batch_size")
57 }
58 uniq := map[string]bool{}
59 for _, k := range cfg.MetadataKeys {
60 l := strings.ToLower(k)
61 if _, has := uniq[l]; has {
62 return fmt.Errorf("duplicate entry in metadata_keys: %q (case-insensitive)", l)
63 }
64 uniq[l] = true
65 }
66 if cfg.Timeout < 0 {
67 return errors.New("timeout must be greater or equal to 0")
68 }
69 return nil
70 }