Skip to content

Commit e494243

Browse files
author
alessandro-grassi
committed
config/console: make cluster operation timeouts configurable
1 parent 534690f commit e494243

4 files changed

Lines changed: 56 additions & 4 deletions

File tree

backend/pkg/config/console.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ const DefaultMaxDeserializationPayloadSize = 20_480 // 20 KB
2222
type Console struct {
2323
TopicDocumentation ConsoleTopicDocumentation `yaml:"topicDocumentation"`
2424
API ConsoleAPI `yaml:"api"`
25+
OperationTimeouts OperationTimeouts `yaml:"operationTimeouts"`
2526
}
2627

2728
// SetDefaults for Console configs.
2829
func (c *Console) SetDefaults() {
2930
c.TopicDocumentation.SetDefaults()
3031
c.API.SetDefaults()
32+
c.OperationTimeouts.SetDefaults()
3133
}
3234

3335
// RegisterFlags for sensitive Console configurations.
@@ -45,5 +47,9 @@ func (c *Console) Validate() error {
4547
return fmt.Errorf("failed to validate API config: %w", err)
4648
}
4749

50+
if err := c.OperationTimeouts.Validate(); err != nil {
51+
return fmt.Errorf("failed to validate timeouts config: %w", err)
52+
}
53+
4854
return nil
4955
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright 2024 Redpanda Data, Inc.
2+
//
3+
// Use of this software is governed by the Business Source License
4+
// included in the file licenses/BSL.md
5+
//
6+
// As of the Change Date specified in that file, in accordance with
7+
// the Business Source License, use of this software will be governed
8+
// by the Apache License, Version 2.0
9+
10+
package config
11+
12+
import (
13+
"errors"
14+
"time"
15+
)
16+
17+
// OperationTimeouts contains timeout configurations for various Kafka operations
18+
// performed by the console service.
19+
type OperationTimeouts struct {
20+
// ClusterInfo is the timeout applied when fetching broker metadata and log dir
21+
// information to build the cluster overview. A shorter timeout avoids long
22+
// response times when a single broker is temporarily unreachable, but may
23+
// cause incomplete results on slow clusters.
24+
ClusterInfo time.Duration `yaml:"clusterInfo"`
25+
26+
// TopicsOverview is the timeout applied when fetching topic metadata and per-topic
27+
// log dir sizes to build the topics list. A shorter timeout avoids long response
28+
// times when a single broker is temporarily unreachable, but may cause incomplete
29+
// results on slow clusters.
30+
TopicsOverview time.Duration `yaml:"topicsOverview"`
31+
}
32+
33+
// SetDefaults for ConsoleTimeouts.
34+
func (c *OperationTimeouts) SetDefaults() {
35+
c.ClusterInfo = 6 * time.Second
36+
c.TopicsOverview = 5 * time.Second
37+
}
38+
39+
// Validate ConsoleTimeouts.
40+
func (c *OperationTimeouts) Validate() error {
41+
if c.ClusterInfo <= 0 {
42+
return errors.New("console.operationTimeouts.clusterInfo must be a positive duration")
43+
}
44+
if c.TopicsOverview <= 0 {
45+
return errors.New("console.operationTimeouts.topicsOverview must be a positive duration")
46+
}
47+
return nil
48+
}

backend/pkg/console/cluster_info.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"context"
1414
"log/slog"
1515
"sort"
16-
"time"
1716

1817
"github.com/twmb/franz-go/pkg/kmsg"
1918
"golang.org/x/sync/errgroup"
@@ -53,7 +52,7 @@ func (s *Service) GetClusterInfo(ctx context.Context) (*ClusterInfo, error) {
5352

5453
// We use a child context with a shorter timeout because otherwise we'll potentially have very long response
5554
// times in case of a single broker being down.
56-
childCtx, cancel := context.WithTimeout(egCtx, 6*time.Second)
55+
childCtx, cancel := context.WithTimeout(egCtx, s.cfg.Console.OperationTimeouts.ClusterInfo)
5756
defer cancel()
5857

5958
eg.Go(func() error {

backend/pkg/console/topic_overview.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
"log/slog"
1616
"sort"
1717
"sync"
18-
"time"
1918
)
2019

2120
// DocumentationState denotes whether topic documentation is available for a certain
@@ -77,7 +76,7 @@ func (s *Service) GetTopicsOverview(ctx context.Context) ([]*TopicSummary, error
7776

7877
// 3. Get log dir sizes & configs for each topic concurrently
7978
// Use a shorter ctx timeout so that we don't wait for too long if one broker is currently down.
80-
childCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
79+
childCtx, cancel := context.WithTimeout(ctx, s.cfg.Console.OperationTimeouts.TopicsOverview)
8180
defer cancel()
8281

8382
configs := make(map[string]*TopicConfig)

0 commit comments

Comments
 (0)