code.vegaprotocol.io/vega@v0.79.0/datanode/broker/config.go (about)

     1  // Copyright (C) 2023 Gobalsky Labs Limited
     2  //
     3  // This program is free software: you can redistribute it and/or modify
     4  // it under the terms of the GNU Affero General Public License as
     5  // published by the Free Software Foundation, either version 3 of the
     6  // License, or (at your option) any later version.
     7  //
     8  // This program is distributed in the hope that it will be useful,
     9  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    10  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    11  // GNU Affero General Public License for more details.
    12  //
    13  // You should have received a copy of the GNU Affero General Public License
    14  // along with this program.  If not, see <http://www.gnu.org/licenses/>.
    15  
    16  package broker
    17  
    18  import (
    19  	"time"
    20  
    21  	"code.vegaprotocol.io/vega/datanode/config/encoding"
    22  	"code.vegaprotocol.io/vega/logging"
    23  )
    24  
    25  const namedLogger = "broker"
    26  
    27  // Config represents the configuration of the broker.
    28  type Config struct {
    29  	Level                          encoding.LogLevel         `long:"log-level"`
    30  	SocketConfig                   SocketConfig              `group:"Socket"                                                                           namespace:"socket"`
    31  	SocketServerInboundBufferSize  int                       `long:"socket-server-inbound-buffer-size"`
    32  	SocketServerOutboundBufferSize int                       `long:"socket-server-outbound-buffer-size"`
    33  	FileEventSourceConfig          FileEventSourceConfig     `group:"FileEventSourceConfig"                                                            namespace:"fileeventsource"`
    34  	UseEventFile                   encoding.Bool             `description:"set to true to source events from a file"                                   long:"use-event-file"`
    35  	PanicOnError                   encoding.Bool             `description:"if an error occurs on event push the broker will panic, else log the error" long:"panic-on-error"`
    36  	UseBufferedEventSource         encoding.Bool             `description:"if true datanode will buffer events"                                        long:"use-buffered-event-source"`
    37  	BufferedEventSourceConfig      BufferedEventSourceConfig `group:"BufferedEventSource"                                                              namespace:"bufferedeventsource"`
    38  	EventBusClientBufferSize       int                       `long:"event-bus-client-buffer-size"`
    39  }
    40  
    41  // NewDefaultConfig creates an instance of config with default values.
    42  func NewDefaultConfig() Config {
    43  	return Config{
    44  		Level: encoding.LogLevel{Level: logging.InfoLevel},
    45  		SocketConfig: SocketConfig{
    46  			IP:                 "0.0.0.0",
    47  			Port:               3005,
    48  			MaxReceiveTimeouts: 3,
    49  			TransportType:      "tcp",
    50  		},
    51  		SocketServerInboundBufferSize:  10000,
    52  		SocketServerOutboundBufferSize: 10000,
    53  		FileEventSourceConfig: FileEventSourceConfig{
    54  			Directory:             "events",
    55  			TimeBetweenBlocks:     encoding.Duration{Duration: 1 * time.Second},
    56  			SendChannelBufferSize: 1000,
    57  		},
    58  		UseEventFile:           false,
    59  		PanicOnError:           false,
    60  		UseBufferedEventSource: true,
    61  		BufferedEventSourceConfig: BufferedEventSourceConfig{
    62  			EventsPerFile:           10_000_000,
    63  			SendChannelBufferSize:   10_000,
    64  			Archive:                 true,
    65  			ArchiveMaximumSizeBytes: 1_000_000_000,
    66  		},
    67  		EventBusClientBufferSize: 100000,
    68  	}
    69  }
    70  
    71  type FileEventSourceConfig struct {
    72  	Directory             string            `description:"the directory container the event files"               long:"directory"`
    73  	TimeBetweenBlocks     encoding.Duration `description:"the time between sending blocks"                       string:"time-between-blocks"`
    74  	SendChannelBufferSize int               `description:"size of channel buffer used to send events to broker " long:"send-buffer-size"`
    75  }
    76  
    77  type SocketConfig struct {
    78  	IP                 string `description:" "             long:"ip"`
    79  	Port               int    `description:" "             long:"port"`
    80  	MaxReceiveTimeouts int    `long:"max-receive-timeouts"`
    81  	TransportType      string `long:"transport-type"`
    82  }
    83  
    84  type BufferedEventSourceConfig struct {
    85  	EventsPerFile           int   `description:"the number of events to store in a file buffer, set to 0 to disable the buffer" long:"events-per-file"`
    86  	SendChannelBufferSize   int   `description:"sink event channel buffer size"                                                 long:"send-buffer-size"`
    87  	Archive                 bool  `description:"archives event buffer files after they have been read, default false"           long:"archive"`
    88  	ArchiveMaximumSizeBytes int64 `description:"the maximum size of the archive directory"                                      long:"archive-maximum-size"`
    89  }