-
Notifications
You must be signed in to change notification settings - Fork 22
/
config.go
106 lines (92 loc) · 3.27 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Copyright 2023 The Cockroach Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// SPDX-License-Identifier: Apache-2.0
package cdc
import (
"bufio"
"time"
"github.com/cockroachdb/cdc-sink/internal/conveyor"
"github.com/cockroachdb/cdc-sink/internal/script"
"github.com/cockroachdb/cdc-sink/internal/sequencer"
"github.com/cockroachdb/cdc-sink/internal/target/dlq"
log "github.com/sirupsen/logrus"
"github.com/spf13/pflag"
)
const (
defaultBackfillWindow = time.Hour
defaultNDJsonBuffer = bufio.MaxScanTokenSize // 64k
defaultResponseTimeout = 2 * time.Minute
)
// Config adds CDC-specific configuration to the core logical loop.
type Config struct {
ConveyorConfig conveyor.Config
DLQConfig dlq.Config
SequencerConfig sequencer.Config
ScriptConfig script.Config
// Discard all incoming HTTP payloads. This is useful for tuning
// changefeed throughput without considering cdc-sink performance.
Discard bool
// If non-zero, wait half before and after consuming the payload.
DiscardDelay time.Duration
// The maximum amount of data to buffer when reading a single line
// of ndjson input. This can be increased if the source cluster
// has large blob values.
NDJsonBuffer int
// The maximum amount of time that we want to allow an HTTP handler
// to run for.
ResponseTimeout time.Duration
}
// Bind adds configuration flags to the set.
func (c *Config) Bind(f *pflag.FlagSet) {
c.ConveyorConfig.Bind(f)
c.DLQConfig.Bind(f)
c.SequencerConfig.Bind(f)
c.ScriptConfig.Bind(f)
f.BoolVar(&c.Discard, "discard", false,
"(dangerous) discard all incoming HTTP requests; useful for changefeed throughput testing")
f.DurationVar(&c.DiscardDelay, "discardDelay", 0,
"adds additional delay in discard mode; useful for gauging the impact of changefeed RTT")
f.IntVar(&c.NDJsonBuffer, "ndjsonBufferSize", defaultNDJsonBuffer,
"the maximum amount of data to buffer while reading a single line of ndjson input; "+
"increase when source cluster has large blob values")
f.DurationVar(&c.ResponseTimeout, "httpResponseTimeout", defaultResponseTimeout,
"the maximum amount of time to allow an HTTP handler to execute for")
}
// Preflight implements logical.Config.
func (c *Config) Preflight() error {
if err := c.ConveyorConfig.Preflight(); err != nil {
return err
}
if err := c.DLQConfig.Preflight(); err != nil {
return err
}
if err := c.SequencerConfig.Preflight(); err != nil {
return err
}
if err := c.ScriptConfig.Preflight(); err != nil {
return err
}
// Backfill mode may be zero to disable BestEffort.
if c.Discard {
log.Warn("⚠️ HTTP server is discarding incoming payloads ⚠️")
}
if c.NDJsonBuffer == 0 {
c.NDJsonBuffer = defaultNDJsonBuffer
}
if c.ResponseTimeout == 0 {
c.ResponseTimeout = defaultResponseTimeout
}
return nil
}