Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg/sink(ticdc): Update Kafka cluster every 30min #9287

Merged
merged 4 commits into from
Jun 26, 2023
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions pkg/sink/kafka/metrics_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,14 @@ type MetricsCollector interface {
Run(ctx context.Context)
}

// RefreshMetricsInterval specifies the interval of refresh kafka client metrics.
const RefreshMetricsInterval = 5 * time.Second
const (
// RefreshMetricsInterval specifies the interval of refresh kafka client metrics.
RefreshMetricsInterval = 5 * time.Second
// refreshClusterMetaInterval specifies the interval of refresh kafka cluster meta.
// Do not set it too small, because it will cause too many requests to kafka cluster.
// Every request will get all topics and all brokers information.
refreshClusterMetaInterval = 30 * time.Minute
)

// Sarama metrics names, see https://pkg.go.dev/github.com/Shopify/sarama#pkg-overview.
const (
Expand Down Expand Up @@ -71,9 +77,13 @@ func NewSaramaMetricsCollector(
}

func (m *saramaMetricsCollector) Run(ctx context.Context) {
ticker := time.NewTicker(RefreshMetricsInterval)
// Initialize brokers.
m.updateBrokers(ctx)

refreshMetricsTicker := time.NewTicker(RefreshMetricsInterval)
refreshClusterMetaTicker := time.NewTicker(refreshClusterMetaInterval)
defer func() {
ticker.Stop()
refreshMetricsTicker.Stop()
Rustin170506 marked this conversation as resolved.
Show resolved Hide resolved
m.cleanupMetrics()
}()

Expand All @@ -84,10 +94,11 @@ func (m *saramaMetricsCollector) Run(ctx context.Context) {
zap.String("namespace", m.changefeedID.Namespace),
zap.String("changefeed", m.changefeedID.ID))
return
case <-ticker.C:
m.updateBrokers(ctx)
case <-refreshMetricsTicker.C:
m.collectBrokerMetrics()
m.collectProducerMetrics()
case <-refreshClusterMetaTicker.C:
m.updateBrokers(ctx)
}
}
}
Expand Down