Skip to content

modelindexer: fix flush-on-close timing issues#7352

Merged
axw merged 4 commits into
elastic:mainfrom
axw:modelindexer-close-flush
Feb 21, 2022
Merged

modelindexer: fix flush-on-close timing issues#7352
axw merged 4 commits into
elastic:mainfrom
axw:modelindexer-close-flush

Conversation

@axw

@axw axw commented Feb 21, 2022

Copy link
Copy Markdown
Member

Motivation/summary

If the background timer goroutine was started, but had not yet added to the errgroup, then Close could return before events enqueued by ProcessEvents were flushed.

We fix this by ensuring the errgroup.Go call is made before ProcessEvents returned. If the timer is stopped (e.g. because Close is called), then we signal to the timer goroutine to flush immediately, instead of calling flushActive(Locked) from multiple code paths.

This should fix the TestTransactionAggregationShutdown failures we occasionally see in CI.

Checklist

How to test these changes

This is not likely to happen in a real setup. Run TestTransactionAggregationShutdown a bunch of times?

Related issues

None

@axw axw added bug v8.0.0 v8.1.0 backport-8.0 Automated backport with mergify v8.2.0 backport-8.1 Automated backport with mergify v7.17.0 backport-7.17 Automated backport with mergify to the 7.17 branch labels Feb 21, 2022
@axw axw force-pushed the modelindexer-close-flush branch from 119d4f4 to cac05bf Compare February 21, 2022 06:11
axw added 2 commits February 21, 2022 14:11
Some tests may intentionally cause an error, which will
lead to Elasticsearch client backoff. Set a fast backoff
to not slow the tests.
If the background timer goroutine was started,
but had not yet added to the errgroup, then Close
could return before events enqueued by ProcessEvents
were flushed.

We fix this by ensuring the errgroup.Go call is
made before ProcessEvents returned. If the timer
is stopped (e.g. because Close is called), then
we signal to the timer goroutine to flush immediately,
instead of calling flushActive(Locked) from multiple
code paths.
@axw axw force-pushed the modelindexer-close-flush branch from cac05bf to dc3ae44 Compare February 21, 2022 06:11
@ghost

ghost commented Feb 21, 2022

Copy link
Copy Markdown

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2022-02-21T12:48:05.625+0000

  • Duration: 66 min 30 sec

Test stats 🧪

Test Results
Failed 0
Passed 5652
Skipped 19
Total 5671

🤖 GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

  • /hey-apm : Run the hey-apm benchmark.

  • /package : Generate and publish the docker images.

  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

@ghost

ghost commented Feb 21, 2022

Copy link
Copy Markdown

💔 Build Failed

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2022-02-21T06:10:10.828+0000

  • Duration: 8 min 4 sec

Steps errors 3

Expand to view the steps failures

Check out from version control
  • Took 0 min 15 sec . View more details here
  • Description: [2022-02-21T06:16:52.959Z] The recommended git tool is: git [2022-02-21T06:17:00.370Z] using creden
Check out from version control
  • Took 0 min 7 sec . View more details here
  • Description: [2022-02-21T06:17:28.114Z] The recommended git tool is: git [2022-02-21T06:17:28.128Z] using creden
Check out from version control
  • Took 0 min 7 sec . View more details here
  • Description: [2022-02-21T06:18:05.050Z] The recommended git tool is: git [2022-02-21T06:18:05.062Z] using creden

🤖 GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

@axw axw marked this pull request as ready for review February 21, 2022 06:24
@axw axw requested a review from a team February 21, 2022 06:24
@axw

axw commented Feb 21, 2022

Copy link
Copy Markdown
Member Author

[2022-02-21T06:41:43.797Z] Get "https://docker.elastic.co/v2/": dial tcp 34.68.230.202:443: connect: connection refused

@axw

axw commented Feb 21, 2022

Copy link
Copy Markdown
Member Author

/test

Comment thread model/modelindexer/indexer.go
@mergify

mergify Bot commented Feb 21, 2022

Copy link
Copy Markdown
Contributor

This pull request is now in conflicts. Could you fix it @axw? 🙏
To fixup this pull request, you can check out it locally. See documentation: https://help.github.com/articles/checking-out-pull-requests-locally/

git fetch upstream
git checkout -b modelindexer-close-flush upstream/modelindexer-close-flush
git merge upstream/main
git push upstream modelindexer-close-flush

@axw axw requested a review from marclop February 21, 2022 12:47

@marclop marclop left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@axw axw enabled auto-merge (squash) February 21, 2022 13:06
@axw axw merged commit 2161ab2 into elastic:main Feb 21, 2022
mergify Bot pushed a commit that referenced this pull request Feb 21, 2022
* model/modelindexer: speed up tests

Some tests may intentionally cause an error, which will
lead to Elasticsearch client backoff. Set a fast backoff
to not slow the tests.

* model/modelindexer: fix flush-on-close

If the background timer goroutine was started,
but had not yet added to the errgroup, then Close
could return before events enqueued by ProcessEvents
were flushed.

We fix this by ensuring the errgroup.Go call is
made before ProcessEvents returned. If the timer
is stopped (e.g. because Close is called), then
we signal to the timer goroutine to flush immediately,
instead of calling flushActive(Locked) from multiple
code paths.

* model/modelindexer: fix goroutine leak

(cherry picked from commit 2161ab2)
mergify Bot pushed a commit that referenced this pull request Feb 21, 2022
* model/modelindexer: speed up tests

Some tests may intentionally cause an error, which will
lead to Elasticsearch client backoff. Set a fast backoff
to not slow the tests.

* model/modelindexer: fix flush-on-close

If the background timer goroutine was started,
but had not yet added to the errgroup, then Close
could return before events enqueued by ProcessEvents
were flushed.

We fix this by ensuring the errgroup.Go call is
made before ProcessEvents returned. If the timer
is stopped (e.g. because Close is called), then
we signal to the timer goroutine to flush immediately,
instead of calling flushActive(Locked) from multiple
code paths.

* model/modelindexer: fix goroutine leak

(cherry picked from commit 2161ab2)

# Conflicts:
#	changelogs/head.asciidoc
mergify Bot pushed a commit that referenced this pull request Feb 21, 2022
* model/modelindexer: speed up tests

Some tests may intentionally cause an error, which will
lead to Elasticsearch client backoff. Set a fast backoff
to not slow the tests.

* model/modelindexer: fix flush-on-close

If the background timer goroutine was started,
but had not yet added to the errgroup, then Close
could return before events enqueued by ProcessEvents
were flushed.

We fix this by ensuring the errgroup.Go call is
made before ProcessEvents returned. If the timer
is stopped (e.g. because Close is called), then
we signal to the timer goroutine to flush immediately,
instead of calling flushActive(Locked) from multiple
code paths.

* model/modelindexer: fix goroutine leak

(cherry picked from commit 2161ab2)

# Conflicts:
#	changelogs/head.asciidoc
#	model/modelindexer/indexer_test.go
axw added a commit that referenced this pull request Feb 22, 2022
…#7363)

* modelindexer: fix flush-on-close timing issues (#7352)

* model/modelindexer: speed up tests

Some tests may intentionally cause an error, which will
lead to Elasticsearch client backoff. Set a fast backoff
to not slow the tests.

* model/modelindexer: fix flush-on-close

If the background timer goroutine was started,
but had not yet added to the errgroup, then Close
could return before events enqueued by ProcessEvents
were flushed.

We fix this by ensuring the errgroup.Go call is
made before ProcessEvents returned. If the timer
is stopped (e.g. because Close is called), then
we signal to the timer goroutine to flush immediately,
instead of calling flushActive(Locked) from multiple
code paths.

* model/modelindexer: fix goroutine leak

(cherry picked from commit 2161ab2)

# Conflicts:
#	changelogs/head.asciidoc

* Delete head.asciidoc

Co-authored-by: Andrew Wilkins <axw@elastic.co>
@axw axw deleted the modelindexer-close-flush branch February 22, 2022 02:27
axw added a commit that referenced this pull request Feb 22, 2022
* model/modelindexer: speed up tests

Some tests may intentionally cause an error, which will
lead to Elasticsearch client backoff. Set a fast backoff
to not slow the tests.

* model/modelindexer: fix flush-on-close

If the background timer goroutine was started,
but had not yet added to the errgroup, then Close
could return before events enqueued by ProcessEvents
were flushed.

We fix this by ensuring the errgroup.Go call is
made before ProcessEvents returned. If the timer
is stopped (e.g. because Close is called), then
we signal to the timer goroutine to flush immediately,
instead of calling flushActive(Locked) from multiple
code paths.

* model/modelindexer: fix goroutine leak

(cherry picked from commit 2161ab2)

Co-authored-by: Andrew Wilkins <axw@elastic.co>
axw added a commit that referenced this pull request Feb 22, 2022
#7364)

* modelindexer: fix flush-on-close timing issues (#7352)

* model/modelindexer: speed up tests

Some tests may intentionally cause an error, which will
lead to Elasticsearch client backoff. Set a fast backoff
to not slow the tests.

* model/modelindexer: fix flush-on-close

If the background timer goroutine was started,
but had not yet added to the errgroup, then Close
could return before events enqueued by ProcessEvents
were flushed.

We fix this by ensuring the errgroup.Go call is
made before ProcessEvents returned. If the timer
is stopped (e.g. because Close is called), then
we signal to the timer goroutine to flush immediately,
instead of calling flushActive(Locked) from multiple
code paths.

* model/modelindexer: fix goroutine leak

(cherry picked from commit 2161ab2)

# Conflicts:
#	changelogs/head.asciidoc
#	model/modelindexer/indexer_test.go

* Fix merge conflicts

Co-authored-by: Andrew Wilkins <axw@elastic.co>
marclop added a commit to marclop/apm-server that referenced this pull request Mar 24, 2022
This patch unlocks the `i.activeMu` mutex in flushActive as soon as the
`i.active` reference has been set to `nil`. This severely minimizes the
lock contention and achives similar or higher indexing throughput when
comparing the benchmarks before elastic#7352 was introduced.

These are the results:

```console
$ go test -bench ... # Current main
goos: darwin
goarch: arm64
pkg: github.com/elastic/apm-server/model/modelindexer
BenchmarkModelIndexer/NoCompression-8        4653790    2527 ns/op
BenchmarkModelIndexer/BestSpeed-8            2909288	4051 ns/op
BenchmarkModelIndexer/DefaultCompression-8   1691677	6674 ns/op
BenchmarkModelIndexer/BestCompression-8      1234953    8334 ns/op
PASS
ok  	github.com/elastic/apm-server/model/modelindexer	70.585s
```

```console
$ go test -bench ... # This patch
goos: darwin
goarch: arm64
pkg: github.com/elastic/apm-server/model/modelindexer
BenchmarkModelIndexer/NoCompression-8         	 8702388	  1344 ns/op
BenchmarkModelIndexer/BestSpeed-8             	 5097385	  2238 ns/op
BenchmarkModelIndexer/DefaultCompression-8    	 2639126	  4821 ns/op
BenchmarkModelIndexer/BestCompression-8       	 1586126	  7350 ns/op
PASS
ok  	github.com/elastic/apm-server/model/modelindexer	64.933s
```

The contention is much worse when the APM Server is actually running and
indexing against an Elasticsearch cluster since the lock is held for the
entire `bulkIndexer.Flush` operation, which includes network latency.

Signed-off-by: Marc Lopez Rubio <marc5.12@outlook.com>
marclop added a commit that referenced this pull request Mar 24, 2022
This patch unlocks the `i.activeMu` mutex in flushActive as soon as the
`i.active` reference has been set to `nil`. This severely minimizes the
lock contention and achives similar or higher indexing throughput when
comparing the benchmarks before #7352 was introduced.

The microbenchmark results seem to indicate that we're back to the
previous indexing performance with this change:

```console
$ go test -bench ... # Current main
goos: darwin
goarch: arm64
pkg: github.com/elastic/apm-server/model/modelindexer
BenchmarkModelIndexer/NoCompression-8        4653790    2527 ns/op
BenchmarkModelIndexer/BestSpeed-8            2909288	4051 ns/op
BenchmarkModelIndexer/DefaultCompression-8   1691677	6674 ns/op
BenchmarkModelIndexer/BestCompression-8      1234953    8334 ns/op
PASS
ok  	github.com/elastic/apm-server/model/modelindexer	70.585s
```

```console
$ go test -bench ... # This patch
goos: darwin
goarch: arm64
pkg: github.com/elastic/apm-server/model/modelindexer
BenchmarkModelIndexer/NoCompression-8         	 8702388	  1344 ns/op
BenchmarkModelIndexer/BestSpeed-8             	 5097385	  2238 ns/op
BenchmarkModelIndexer/DefaultCompression-8    	 2639126	  4821 ns/op
BenchmarkModelIndexer/BestCompression-8       	 1586126	  7350 ns/op
PASS
ok  	github.com/elastic/apm-server/model/modelindexer	64.933s
```

The contention is much worse when the APM Server is actually running and
indexing against an Elasticsearch cluster since the lock is held for the
entire `bulkIndexer.Flush` operation, which includes network latency.

Signed-off-by: Marc Lopez Rubio <marc5.12@outlook.com>
mergify Bot pushed a commit that referenced this pull request Mar 24, 2022
This patch unlocks the `i.activeMu` mutex in flushActive as soon as the
`i.active` reference has been set to `nil`. This severely minimizes the
lock contention and achives similar or higher indexing throughput when
comparing the benchmarks before #7352 was introduced.

The microbenchmark results seem to indicate that we're back to the
previous indexing performance with this change:

```console
$ go test -bench ... # Current main
goos: darwin
goarch: arm64
pkg: github.com/elastic/apm-server/model/modelindexer
BenchmarkModelIndexer/NoCompression-8        4653790    2527 ns/op
BenchmarkModelIndexer/BestSpeed-8            2909288	4051 ns/op
BenchmarkModelIndexer/DefaultCompression-8   1691677	6674 ns/op
BenchmarkModelIndexer/BestCompression-8      1234953    8334 ns/op
PASS
ok  	github.com/elastic/apm-server/model/modelindexer	70.585s
```

```console
$ go test -bench ... # This patch
goos: darwin
goarch: arm64
pkg: github.com/elastic/apm-server/model/modelindexer
BenchmarkModelIndexer/NoCompression-8         	 8702388	  1344 ns/op
BenchmarkModelIndexer/BestSpeed-8             	 5097385	  2238 ns/op
BenchmarkModelIndexer/DefaultCompression-8    	 2639126	  4821 ns/op
BenchmarkModelIndexer/BestCompression-8       	 1586126	  7350 ns/op
PASS
ok  	github.com/elastic/apm-server/model/modelindexer	64.933s
```

The contention is much worse when the APM Server is actually running and
indexing against an Elasticsearch cluster since the lock is held for the
entire `bulkIndexer.Flush` operation, which includes network latency.

Signed-off-by: Marc Lopez Rubio <marc5.12@outlook.com>
(cherry picked from commit b951097)
mergify Bot pushed a commit that referenced this pull request Mar 24, 2022
This patch unlocks the `i.activeMu` mutex in flushActive as soon as the
`i.active` reference has been set to `nil`. This severely minimizes the
lock contention and achives similar or higher indexing throughput when
comparing the benchmarks before #7352 was introduced.

The microbenchmark results seem to indicate that we're back to the
previous indexing performance with this change:

```console
$ go test -bench ... # Current main
goos: darwin
goarch: arm64
pkg: github.com/elastic/apm-server/model/modelindexer
BenchmarkModelIndexer/NoCompression-8        4653790    2527 ns/op
BenchmarkModelIndexer/BestSpeed-8            2909288	4051 ns/op
BenchmarkModelIndexer/DefaultCompression-8   1691677	6674 ns/op
BenchmarkModelIndexer/BestCompression-8      1234953    8334 ns/op
PASS
ok  	github.com/elastic/apm-server/model/modelindexer	70.585s
```

```console
$ go test -bench ... # This patch
goos: darwin
goarch: arm64
pkg: github.com/elastic/apm-server/model/modelindexer
BenchmarkModelIndexer/NoCompression-8         	 8702388	  1344 ns/op
BenchmarkModelIndexer/BestSpeed-8             	 5097385	  2238 ns/op
BenchmarkModelIndexer/DefaultCompression-8    	 2639126	  4821 ns/op
BenchmarkModelIndexer/BestCompression-8       	 1586126	  7350 ns/op
PASS
ok  	github.com/elastic/apm-server/model/modelindexer	64.933s
```

The contention is much worse when the APM Server is actually running and
indexing against an Elasticsearch cluster since the lock is held for the
entire `bulkIndexer.Flush` operation, which includes network latency.

Signed-off-by: Marc Lopez Rubio <marc5.12@outlook.com>
(cherry picked from commit b951097)

# Conflicts:
#	changelogs/head.asciidoc
mergify Bot pushed a commit that referenced this pull request Mar 24, 2022
This patch unlocks the `i.activeMu` mutex in flushActive as soon as the
`i.active` reference has been set to `nil`. This severely minimizes the
lock contention and achives similar or higher indexing throughput when
comparing the benchmarks before #7352 was introduced.

The microbenchmark results seem to indicate that we're back to the
previous indexing performance with this change:

```console
$ go test -bench ... # Current main
goos: darwin
goarch: arm64
pkg: github.com/elastic/apm-server/model/modelindexer
BenchmarkModelIndexer/NoCompression-8        4653790    2527 ns/op
BenchmarkModelIndexer/BestSpeed-8            2909288	4051 ns/op
BenchmarkModelIndexer/DefaultCompression-8   1691677	6674 ns/op
BenchmarkModelIndexer/BestCompression-8      1234953    8334 ns/op
PASS
ok  	github.com/elastic/apm-server/model/modelindexer	70.585s
```

```console
$ go test -bench ... # This patch
goos: darwin
goarch: arm64
pkg: github.com/elastic/apm-server/model/modelindexer
BenchmarkModelIndexer/NoCompression-8         	 8702388	  1344 ns/op
BenchmarkModelIndexer/BestSpeed-8             	 5097385	  2238 ns/op
BenchmarkModelIndexer/DefaultCompression-8    	 2639126	  4821 ns/op
BenchmarkModelIndexer/BestCompression-8       	 1586126	  7350 ns/op
PASS
ok  	github.com/elastic/apm-server/model/modelindexer	64.933s
```

The contention is much worse when the APM Server is actually running and
indexing against an Elasticsearch cluster since the lock is held for the
entire `bulkIndexer.Flush` operation, which includes network latency.

Signed-off-by: Marc Lopez Rubio <marc5.12@outlook.com>
(cherry picked from commit b951097)

# Conflicts:
#	changelogs/head.asciidoc
marclop added a commit that referenced this pull request Mar 24, 2022
This patch unlocks the `i.activeMu` mutex in flushActive as soon as the
`i.active` reference has been set to `nil`. This severely minimizes the
lock contention and achives similar or higher indexing throughput when
comparing the benchmarks before #7352 was introduced.

The microbenchmark results seem to indicate that we're back to the
previous indexing performance with this change:

```console
$ go test -bench ... # Current main
goos: darwin
goarch: arm64
pkg: github.com/elastic/apm-server/model/modelindexer
BenchmarkModelIndexer/NoCompression-8        4653790    2527 ns/op
BenchmarkModelIndexer/BestSpeed-8            2909288	4051 ns/op
BenchmarkModelIndexer/DefaultCompression-8   1691677	6674 ns/op
BenchmarkModelIndexer/BestCompression-8      1234953    8334 ns/op
PASS
ok  	github.com/elastic/apm-server/model/modelindexer	70.585s
```

```console
$ go test -bench ... # This patch
goos: darwin
goarch: arm64
pkg: github.com/elastic/apm-server/model/modelindexer
BenchmarkModelIndexer/NoCompression-8         	 8702388	  1344 ns/op
BenchmarkModelIndexer/BestSpeed-8             	 5097385	  2238 ns/op
BenchmarkModelIndexer/DefaultCompression-8    	 2639126	  4821 ns/op
BenchmarkModelIndexer/BestCompression-8       	 1586126	  7350 ns/op
PASS
ok  	github.com/elastic/apm-server/model/modelindexer	64.933s
```

The contention is much worse when the APM Server is actually running and
indexing against an Elasticsearch cluster since the lock is held for the
entire `bulkIndexer.Flush` operation, which includes network latency.

Signed-off-by: Marc Lopez Rubio <marc5.12@outlook.com>
(cherry picked from commit b951097)

Co-authored-by: Marc Lopez Rubio <marc5.12@outlook.com>
marclop added a commit that referenced this pull request Mar 24, 2022
This patch unlocks the `i.activeMu` mutex in flushActive as soon as the
`i.active` reference has been set to `nil`. This severely minimizes the
lock contention and achives similar or higher indexing throughput when
comparing the benchmarks before #7352 was introduced.

The microbenchmark results seem to indicate that we're back to the
previous indexing performance with this change:

```console
$ go test -bench ... # Current main
goos: darwin
goarch: arm64
pkg: github.com/elastic/apm-server/model/modelindexer
BenchmarkModelIndexer/NoCompression-8        4653790    2527 ns/op
BenchmarkModelIndexer/BestSpeed-8            2909288	4051 ns/op
BenchmarkModelIndexer/DefaultCompression-8   1691677	6674 ns/op
BenchmarkModelIndexer/BestCompression-8      1234953    8334 ns/op
PASS
ok  	github.com/elastic/apm-server/model/modelindexer	70.585s
```

```console
$ go test -bench ... # This patch
goos: darwin
goarch: arm64
pkg: github.com/elastic/apm-server/model/modelindexer
BenchmarkModelIndexer/NoCompression-8         	 8702388	  1344 ns/op
BenchmarkModelIndexer/BestSpeed-8             	 5097385	  2238 ns/op
BenchmarkModelIndexer/DefaultCompression-8    	 2639126	  4821 ns/op
BenchmarkModelIndexer/BestCompression-8       	 1586126	  7350 ns/op
PASS
ok  	github.com/elastic/apm-server/model/modelindexer	64.933s
```

The contention is much worse when the APM Server is actually running and
indexing against an Elasticsearch cluster since the lock is held for the
entire `bulkIndexer.Flush` operation, which includes network latency.

Signed-off-by: Marc Lopez Rubio <marc5.12@outlook.com>
(cherry picked from commit b951097)

# Conflicts:
#	changelogs/head.asciidoc

Co-authored-by: Marc Lopez Rubio <marc5.12@outlook.com>
marclop added a commit that referenced this pull request Mar 24, 2022
This patch unlocks the `i.activeMu` mutex in flushActive as soon as the
`i.active` reference has been set to `nil`. This severely minimizes the
lock contention and achives similar or higher indexing throughput when
comparing the benchmarks before #7352 was introduced.

The microbenchmark results seem to indicate that we're back to the
previous indexing performance with this change:

```console
$ go test -bench ... # Current main
goos: darwin
goarch: arm64
pkg: github.com/elastic/apm-server/model/modelindexer
BenchmarkModelIndexer/NoCompression-8        4653790    2527 ns/op
BenchmarkModelIndexer/BestSpeed-8            2909288	4051 ns/op
BenchmarkModelIndexer/DefaultCompression-8   1691677	6674 ns/op
BenchmarkModelIndexer/BestCompression-8      1234953    8334 ns/op
PASS
ok  	github.com/elastic/apm-server/model/modelindexer	70.585s
```

```console
$ go test -bench ... # This patch
goos: darwin
goarch: arm64
pkg: github.com/elastic/apm-server/model/modelindexer
BenchmarkModelIndexer/NoCompression-8         	 8702388	  1344 ns/op
BenchmarkModelIndexer/BestSpeed-8             	 5097385	  2238 ns/op
BenchmarkModelIndexer/DefaultCompression-8    	 2639126	  4821 ns/op
BenchmarkModelIndexer/BestCompression-8       	 1586126	  7350 ns/op
PASS
ok  	github.com/elastic/apm-server/model/modelindexer	64.933s
```

The contention is much worse when the APM Server is actually running and
indexing against an Elasticsearch cluster since the lock is held for the
entire `bulkIndexer.Flush` operation, which includes network latency.

Signed-off-by: Marc Lopez Rubio <marc5.12@outlook.com>
(cherry picked from commit b951097)

# Conflicts:
#	changelogs/head.asciidoc

Co-authored-by: Marc Lopez Rubio <marc5.12@outlook.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-7.17 Automated backport with mergify to the 7.17 branch backport-8.0 Automated backport with mergify backport-8.1 Automated backport with mergify bug test-plan-skip v7.17.0 v8.0.0 v8.1.0 v8.2.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants