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

Fix for out of memory error with request body #806

Merged
merged 19 commits into from
Nov 16, 2023
Merged

Conversation

aayush-ap
Copy link
Contributor

Fix for out-of-memory error with request body

  • Consumes a lot of memory during large body size requests #795
  • Added new implementation to add a limit on request body size.
  • To configure body_limit on read request body use nrsecurityagent.ConfigSecurityRequestBodyLimit method or NEW_RELIC_SECURITY_REQUEST_BODY_LIMIT env. By default, this is "300kb"
  • Example :
    export NEW_RELIC_SECURITY_REQUEST_BODY_LIMIT=100
  • When the security agent is not active, the APM agent does not access the request body.
  • This change will required min v0.5.0 version of csec-go-agent

mirackara and others added 12 commits September 18, 2023 11:35
* minor fix for complete security disable flag

* Create FastHTTP Client Functions

* FastHTTP Request Integration

* FastHTTP example file

* FastHTTP Request Integration

* FastHTTP Response file

* mod file

* update security agent version

* supportability metric

* Created unit tests and removed extraneous file

* Moved FastHTTP to internal instrumentation

* Added testing for errors

* chore: add logs-in-context example with logrus

* chore: move example to specific folder

* FastHTTP external segments/Client example

* License for Server Example

* Added test for external segment/minor fixes

* FastHTTP Integration (newrelic#774)

Added Support For FastHTTP

* V3.25.0 Changelog (newrelic#781)

* V3.25.0

* update version

* corrected changelog for 3.25 release

* Fixed test not passing

* Update segments.go

Removed extra function

---------

Co-authored-by: aayush-ap <agarg@newrelic.com>
Co-authored-by: Steve Willoughby <76975199+nr-swilloughby@users.noreply.github.com>
Co-authored-by: Julien Erard <jerard@newrelic.com>
Co-authored-by: Emilio Garcia <iamemilio@users.noreply.github.com>
Co-authored-by: Steve Willoughby <swilloughby@newrelic.com>
@codecov-commenter
Copy link

codecov-commenter commented Oct 23, 2023

Codecov Report

Attention: 86 lines in your changes are missing coverage. Please review.

Comparison is base (a1142ca) 81.10% compared to head (9cfa052) 80.27%.
Report is 5 commits behind head on develop.

Files Patch % Lines
v3/integrations/nrmicro/nrmicro.go 7.31% 36 Missing and 2 partials ⚠️
v3/newrelic/secure_agent.go 0.00% 34 Missing ⚠️
v3/newrelic/transaction.go 12.50% 13 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #806      +/-   ##
===========================================
- Coverage    81.10%   80.27%   -0.83%     
===========================================
  Files          136      134       -2     
  Lines        12393    12328      -65     
===========================================
- Hits         10051     9896     -155     
- Misses        2062     2150      +88     
- Partials       280      282       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mirackara mirackara self-requested a review October 26, 2023 16:30
@mirackara
Copy link
Contributor

@aayush-ap It looks like this change also breaks the nrmicro and nrgrpc integrations (You can see more details in the GHA test suite for those two tests respectively. Once these are fixed, this looks good to merge :)

@aayush-ap
Copy link
Contributor Author

@mirackara
Please verify with latest changes

mirackara
mirackara previously approved these changes Oct 30, 2023
Copy link
Contributor

@mirackara mirackara left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you

@@ -633,7 +626,7 @@ func (webrequest WebRequest) GetHost() string {
return webrequest.Host
}

func (webrequest WebRequest) GetBody() []byte {
func (webrequest WebRequest) GetBody() any {
Copy link
Contributor

Choose a reason for hiding this comment

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

Hello @aayush-ap, is there a specific reason why this is an any type? Is this function to be used only for the security agent? If there is a specific type we want to make sure any external usage has an expected return value.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes,getBody is only used by the cses-go-agent(security agent).
https://github.com/newrelic/csec-go-agent/blob/main/security_intercept/intercept.go#L748

Copy link
Contributor

Choose a reason for hiding this comment

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

If thats the case it would be best practices to have GetBody return a type and have the cses-go-agent convert it as it needs be. Once this is fixed, we can merge this :)

Copy link
Contributor Author

@aayush-ap aayush-ap Nov 15, 2023

Choose a reason for hiding this comment

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

For now, this is not possible because csec-go-agent has already been released we can make this change in the next release of both agents.
According to me, this will not make any issue because GetBody is only used by the csec agent.

Copy link
Contributor

Choose a reason for hiding this comment

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

Alright. I think we're going to put this on ice for now until the changes to the csec-go-agent are in place. We just want to make sure that any public facing API's remain the same so customer who may be using the function in their code bases aren't affected by this change

@mirackara mirackara merged commit b3ce5df into newrelic:develop Nov 16, 2023
43 of 47 checks passed
mirackara added a commit that referenced this pull request Nov 16, 2023
* Error Expected Bug

The attribute error.expected should be a boolean, not a string. It
is also good practice to use a constant value for the key.

* Bump google.golang.org/grpc from 1.54.0 to 1.56.3 in /v3/integrations/nrgraphqlgo/example (#811)

---------


* Bump google.golang.org/grpc in /v3/integrations/nrgraphqlgo/example

Bumps [google.golang.org/grpc](https://github.com/grpc/grpc-go) from 1.54.0 to 1.56.3.
- [Release notes](https://github.com/grpc/grpc-go/releases)
- [Commits](grpc/grpc-go@v1.54.0...v1.56.3)

---
updated-dependencies:
- dependency-name: google.golang.org/grpc
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

---------

* Bump google.golang.org/grpc from 1.54.0 to 1.56.3 in /v3/integrations/nrgrpc (#810)

---------

* Bump google.golang.org/grpc in /v3/integrations/nrgrpc

Bumps [google.golang.org/grpc](https://github.com/grpc/grpc-go) from 1.54.0 to 1.56.3.
- [Release notes](https://github.com/grpc/grpc-go/releases)
- [Commits](grpc/grpc-go@v1.54.0...v1.56.3)

---
updated-dependencies:
- dependency-name: google.golang.org/grpc
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>

---------

* Bump google.golang.org/grpc from 1.54.0 to 1.56.3 in /v3 (#809)


---------

* Bump google.golang.org/grpc from 1.54.0 to 1.56.3 in /v3

Bumps [google.golang.org/grpc](https://github.com/grpc/grpc-go) from 1.54.0 to 1.56.3.
- [Release notes](https://github.com/grpc/grpc-go/releases)
- [Commits](grpc/grpc-go@v1.54.0...v1.56.3)

---
updated-dependencies:
- dependency-name: google.golang.org/grpc
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>

---------

* Bump golang.org/x/net from 0.8.0 to 0.17.0 in /v3/integrations/nrgraphqlgo/example (#804)



---------

* Bump golang.org/x/net in /v3/integrations/nrgraphqlgo/example

Bumps [golang.org/x/net](https://github.com/golang/net) from 0.8.0 to 0.17.0.
- [Commits](golang/net@v0.8.0...v0.17.0)

---
updated-dependencies:
- dependency-name: golang.org/x/net
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

---------

* Fix for out of memory error with request body (#806)

* Release 3.25.0 (#782)

* minor fix for complete security disable flag

* Create FastHTTP Client Functions

* FastHTTP Request Integration

* FastHTTP example file

* FastHTTP Request Integration

* FastHTTP Response file

* mod file

* update security agent version

* supportability metric

* Created unit tests and removed extraneous file

* Moved FastHTTP to internal instrumentation

* Added testing for errors

* chore: add logs-in-context example with logrus

* chore: move example to specific folder

* FastHTTP external segments/Client example

* License for Server Example

* Added test for external segment/minor fixes

* FastHTTP Integration (#774)

Added Support For FastHTTP

* V3.25.0 Changelog (#781)

* V3.25.0

* update version

* corrected changelog for 3.25 release

* Fixed test not passing

* Update segments.go

Removed extra function

---------

Co-authored-by: aayush-ap <agarg@newrelic.com>
Co-authored-by: Steve Willoughby <76975199+nr-swilloughby@users.noreply.github.com>
Co-authored-by: Julien Erard <jerard@newrelic.com>
Co-authored-by: Emilio Garcia <iamemilio@users.noreply.github.com>
Co-authored-by: Steve Willoughby <swilloughby@newrelic.com>

* fix out of memory issue for req body

* Added new config parameter for read request body

* update request body buffer

* minor fix for dataTruncated

* Update readme file

* Update csec-go-agent  version

* Added new wrapper for go-micro stream server

* minor fix for GHA

* Fix for cpu overhead

* backward compatibility

* update agent version

* minor fix

---------

Co-authored-by: Mirac Kara <55501260+mirackara@users.noreply.github.com>
Co-authored-by: Steve Willoughby <76975199+nr-swilloughby@users.noreply.github.com>
Co-authored-by: Julien Erard <jerard@newrelic.com>
Co-authored-by: Emilio Garcia <iamemilio@users.noreply.github.com>
Co-authored-by: Steve Willoughby <swilloughby@newrelic.com>

* move fasthttp out of core library, and into integration package (#808)

* move fasthttp out of core library, and into integration package

* move examples over

* add security agent headers to fasthttp object

* fix examples and external segment

* add fasthttp tests

* cleanup of go mods

* fix segment collection

* add security agent inbound write capture to wrapped handle func

* Update go.mod

* Update Changelog

* update version.go

---------

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: aayush-ap <59004877+aayush-ap@users.noreply.github.com>
Co-authored-by: Mirac Kara <55501260+mirackara@users.noreply.github.com>
Co-authored-by: Steve Willoughby <76975199+nr-swilloughby@users.noreply.github.com>
Co-authored-by: Julien Erard <jerard@newrelic.com>
Co-authored-by: Steve Willoughby <swilloughby@newrelic.com>
Co-authored-by: mirackara <mirackara2000@outlook.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants