mirror of
https://github.com/grafana/grafana.git
synced 2025-08-02 05:46:28 +08:00
Live: make maximum WebSocket message size configurable (#99770)
Co-authored-by: Chris Marchbanks <chris.marchbanks@grafana.com>
This commit is contained in:
@ -1803,6 +1803,10 @@ preinstall_disabled = false
|
|||||||
# tuning. 0 disables Live, -1 means unlimited connections.
|
# tuning. 0 disables Live, -1 means unlimited connections.
|
||||||
max_connections = 100
|
max_connections = 100
|
||||||
|
|
||||||
|
# message_size_limit is the maximum size in bytes of Websocket messages from clients. Defaults to 64KB.
|
||||||
|
# The limit can be disabled by setting it to -1.
|
||||||
|
message_size_limit = 65536
|
||||||
|
|
||||||
# allowed_origins is a comma-separated list of origins that can establish connection with Grafana Live.
|
# allowed_origins is a comma-separated list of origins that can establish connection with Grafana Live.
|
||||||
# If not set then origin will be matched over root_url. Supports wildcard symbol "*".
|
# If not set then origin will be matched over root_url. Supports wildcard symbol "*".
|
||||||
allowed_origins =
|
allowed_origins =
|
||||||
|
@ -269,12 +269,14 @@ func ProvideService(plugCtxProvider *plugincontext.Provider, cfg *setting.Cfg, r
|
|||||||
originGlobs, _ := setting.GetAllowedOriginGlobs(originPatterns) // error already checked on config load.
|
originGlobs, _ := setting.GetAllowedOriginGlobs(originPatterns) // error already checked on config load.
|
||||||
checkOrigin := getCheckOriginFunc(appURL, originPatterns, originGlobs)
|
checkOrigin := getCheckOriginFunc(appURL, originPatterns, originGlobs)
|
||||||
|
|
||||||
|
wsCfg := centrifuge.WebsocketConfig{
|
||||||
|
ReadBufferSize: 1024,
|
||||||
|
WriteBufferSize: 1024,
|
||||||
|
CheckOrigin: checkOrigin,
|
||||||
|
MessageSizeLimit: cfg.LiveMessageSizeLimit,
|
||||||
|
}
|
||||||
// Use a pure websocket transport.
|
// Use a pure websocket transport.
|
||||||
wsHandler := centrifuge.NewWebsocketHandler(node, centrifuge.WebsocketConfig{
|
wsHandler := centrifuge.NewWebsocketHandler(node, wsCfg)
|
||||||
ReadBufferSize: 1024,
|
|
||||||
WriteBufferSize: 1024,
|
|
||||||
CheckOrigin: checkOrigin,
|
|
||||||
})
|
|
||||||
|
|
||||||
pushWSHandler := pushws.NewHandler(g.ManagedStreamRunner, pushws.Config{
|
pushWSHandler := pushws.NewHandler(g.ManagedStreamRunner, pushws.Config{
|
||||||
ReadBufferSize: 1024,
|
ReadBufferSize: 1024,
|
||||||
|
@ -435,6 +435,9 @@ type Cfg struct {
|
|||||||
// LiveAllowedOrigins is a set of origins accepted by Live. If not provided
|
// LiveAllowedOrigins is a set of origins accepted by Live. If not provided
|
||||||
// then Live uses AppURL as the only allowed origin.
|
// then Live uses AppURL as the only allowed origin.
|
||||||
LiveAllowedOrigins []string
|
LiveAllowedOrigins []string
|
||||||
|
// LiveMessageSizeLimit is the maximum size in bytes of Websocket messages
|
||||||
|
// from clients. Defaults to 64KB.
|
||||||
|
LiveMessageSizeLimit int
|
||||||
|
|
||||||
// Grafana.com URL, used for OAuth redirect.
|
// Grafana.com URL, used for OAuth redirect.
|
||||||
GrafanaComURL string
|
GrafanaComURL string
|
||||||
@ -1974,6 +1977,10 @@ func (cfg *Cfg) readLiveSettings(iniFile *ini.File) error {
|
|||||||
if cfg.LiveMaxConnections < -1 {
|
if cfg.LiveMaxConnections < -1 {
|
||||||
return fmt.Errorf("unexpected value %d for [live] max_connections", cfg.LiveMaxConnections)
|
return fmt.Errorf("unexpected value %d for [live] max_connections", cfg.LiveMaxConnections)
|
||||||
}
|
}
|
||||||
|
cfg.LiveMessageSizeLimit = section.Key("message_size_limit").MustInt(65536)
|
||||||
|
if cfg.LiveMessageSizeLimit < -1 {
|
||||||
|
return fmt.Errorf("unexpected value %d for [live] message_size_limit", cfg.LiveMaxConnections)
|
||||||
|
}
|
||||||
cfg.LiveHAEngine = section.Key("ha_engine").MustString("")
|
cfg.LiveHAEngine = section.Key("ha_engine").MustString("")
|
||||||
switch cfg.LiveHAEngine {
|
switch cfg.LiveHAEngine {
|
||||||
case "", "redis":
|
case "", "redis":
|
||||||
|
Reference in New Issue
Block a user