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

Add traffic size metrics #9208

Merged
merged 12 commits into from Sep 12, 2022
Merged

Conversation

tomMoulard
Copy link
Member

@tomMoulard tomMoulard commented Jul 25, 2022

What does this PR do?

This PR superseeds the PR #8432 from @OmarElawady by adding requests_bytes and responses_bytes metrics for all metric backend.

It refactors the access log middleware to use the new capture middleware.

This new capture middleware extracts request/response size and stores it in the request context.
There might be a memory leak introduced by using the http.Request contexts: golang/go#50798

As pilot is deprecated, this PR does not add support for this metric backend.

Motivation

This PR resolves #7804.

More

  • Added/updated tests
  • Added/updated documentation

Additional Notes

Benchmarks with and without metrics

The following output display benchmarks of the capture middleware were:

  • captured measure the response size
  • body measure the response and request size
$ go test -bench=. ./pkg/middlewares/capture/
goos: linux
goarch: amd64
pkg: github.com/traefik/traefik/v2/pkg/middlewares/capture
cpu: Intel(R) Core(TM) i7-10750H CPU @ 2.60GHz
BenchmarkCapture/2k-12				280507	 4015 ns/op	 510.03 MB/s 	 5072 B/op	14 allocs/op
BenchmarkCapture/20k-12				135726	 8301 ns/op	2467.26 MB/s 	41936 B/op	14 allocs/op
BenchmarkCapture/100k-12			 45494	26059 ns/op	3929.54 MB/s	213968 B/op	14 allocs/op
BenchmarkCapture/2k_captured-12			263713	 4356 ns/op	 470.20 MB/s	  5552 B/op	18 allocs/op
BenchmarkCapture/20k_captured-12		132243	 8790 ns/op	2329.98 MB/s	 42416 B/op	18 allocs/op
BenchmarkCapture/100k_captured-12	 	45650	26587 ns/op	3851.57 MB/s	214448 B/op	18 allocs/op
BenchmarkCapture/2k_body-12			274135	 7471 ns/op	 274.12 MB/s 	 5624 B/op	20 allocs/op
BenchmarkCapture/20k_body-12			130206	21149 ns/op	 968.36 MB/s	 42488 B/op	20 allocs/op
BenchmarkCapture/100k_body-12			 41600	51716 ns/op	1980.06 MB/s	214520 B/op	20 allocs/op

Co-authored-by: OmarElawady omarelawady1998@gmail.com
Co-authored-by: Mathieu Lonjaret mathieu.lonjaret@gmail.com
Co-authored-by: Romain rtribotte@users.noreply.github.com

pkg/metrics/prometheus.go Outdated Show resolved Hide resolved
tomMoulard and others added 12 commits September 12, 2022 16:20
This commit superseeds the PR from @OmarElawady by adding
`bytes_sent` and `bytes_received` metrics for all metric backend.

It refactors the access log middleware to use the new capture
middleware.

This new capture middleware extract request/response size and store it
in the request context.

As pilot is deprecated, this commit does not add support for this metric
backend.
Co-authored-by: Michael <mmatur@users.noreply.github.com>
Copy link
Member

@rtribotte rtribotte left a comment

Choose a reason for hiding this comment

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

LGTM 👌

Copy link
Member

@kevinpollet kevinpollet left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@traefiker traefiker merged commit d578ed7 into traefik:master Sep 12, 2022
v2 automation moved this from To review to Done Sep 12, 2022
@tomMoulard tomMoulard deleted the feat/traffic-size-metrics branch September 12, 2022 15:15
@rtribotte rtribotte mentioned this pull request Jun 15, 2023
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
v2
Done
Development

Successfully merging this pull request may close these issues.

Add metric for request size
7 participants