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

[8.4](backport #32712) [Filebeat] gcp-pubsub: Restart Pub/Sub client on errors #32717

Merged
merged 2 commits into from
Aug 17, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ https://github.com/elastic/beats/compare/v8.2.0\...main[Check the HEAD diff]

- Fix counter for number of events published in `httpjson` input. {pull}31993[31993]
- Fix handling of Checkpoint event for R81. {issue}32380[32380] {pull}32458[32458]
- gcp-pubsub input: Restart Pub/Sub client on all errors. {issue}32550[32550] {pull}32712[32712]

*Heartbeat*

Expand Down
2 changes: 1 addition & 1 deletion x-pack/filebeat/input/gcppubsub/_meta/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ RUN \
RUN \
mkdir /data

HEALTHCHECK --interval=1s --retries=90 CMD curl -s -f http://localhost:8432/
HEALTHCHECK --interval=1s --retries=90 CMD curl -s -f --http2 http://localhost:8432/

CMD gcloud beta emulators pubsub start --data-dir /data --host-port "0.0.0.0:8432"
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
variants:
- SDK_VERSION: 293.0.0-0
- SDK_VERSION: 398.0.0-0
6 changes: 3 additions & 3 deletions x-pack/filebeat/input/gcppubsub/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ version: '2.3'

services:
googlepubsub:
image: docker.elastic.co/integrations-ci/beats-googlepubsub:emulator-${SDK_VERSION:-293.0.0-0}-1
image: docker.elastic.co/integrations-ci/beats-googlepubsub:emulator-${SDK_VERSION:-398.0.0-0}-1
build:
context: ./_meta
args:
SDK_VERSION: ${SDK_VERSION:-293.0.0-0}
SDK_VERSION: ${SDK_VERSION:-398.0.0-0}
ports:
- 8432
- '127.0.0.1:8432:8432'
29 changes: 26 additions & 3 deletions x-pack/filebeat/input/gcppubsub/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

"cloud.google.com/go/pubsub"
"github.com/pkg/errors"
"golang.org/x/time/rate"
"google.golang.org/api/option"
"google.golang.org/grpc"

Expand All @@ -32,6 +33,9 @@ import (
const (
inputName = "gcp-pubsub"
oldInputName = "google-pubsub"

// retryInterval is the minimum duration between pub/sub client retries.
retryInterval = 30 * time.Second
)

func init() {
Expand Down Expand Up @@ -139,9 +143,28 @@ func (in *pubsubInput) Run() {
defer in.log.Info("Pub/Sub input worker has stopped.")
defer in.workerWg.Done()
defer in.workerCancel()
if err := in.run(); err != nil {
in.log.Error(err)
return

// Throttle pubsub client restarts.
rt := rate.NewLimiter(rate.Every(retryInterval), 1)

// Watchdog to keep the worker operating after an error.
for in.workerCtx.Err() == nil {
// Rate limit.
if err := rt.Wait(in.workerCtx); err != nil {
continue
}

if err := in.run(); err != nil {
if in.workerCtx.Err() == nil {
in.log.Warnw("Restarting failed Pub/Sub input worker.", "error", err)
continue
}

// Log any non-cancellation error before stopping.
if !errors.Is(err, context.Canceled) {
in.log.Errorw("Pub/Sub input worker failed.", "error", err)
}
}
}
}()
})
Expand Down