diff --git a/.github/workflows/repolinter.yml b/.github/workflows/repolinter.yml new file mode 100644 index 000000000..e52a97661 --- /dev/null +++ b/.github/workflows/repolinter.yml @@ -0,0 +1,32 @@ +# NOTE: This file should always be named `repolinter.yml` to allow +# workflow_dispatch to work properly +name: Repolinter Action + +# NOTE: This workflow will ONLY check the default branch! +# Currently there is no elegant way to specify the default +# branch in the event filtering, so branches are instead +# filtered in the "Test Default Branch" step. +on: [push, workflow_dispatch] + +jobs: + repolint: + name: Run Repolinter + runs-on: ubuntu-latest + steps: + - name: Test Default Branch + id: default-branch + uses: actions/github-script@v2 + with: + script: | + const data = await github.repos.get(context.repo) + return data.data && data.data.default_branch === context.ref.split('/').slice(-1)[0] + - name: Checkout Self + if: ${{ steps.default-branch.outputs.result == 'true' }} + uses: actions/checkout@v2 + - name: Run Repolinter + if: ${{ steps.default-branch.outputs.result == 'true' }} + uses: newrelic/repolinter-action@v1 + with: + config_url: https://raw.githubusercontent.com/newrelic/.github/main/repolinter-rulesets/community-plus.yml + output_type: issue + diff --git a/CHANGELOG.md b/CHANGELOG.md index c732e93f2..b78333682 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,25 @@ # ChangeLog +## Unreleased + +## 3.10.0 + +### New Features +* To keep up with the latest security protocols implemented by Amazon Web + Services, the agent now uses [AWS + IMDSv2](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/configuring-instance-metadata-service.html) + to find utilization data. [#249](https://github.com/newrelic/go-agent/pull/249) + +### Changes +* Updated the locations of our license files so that Go docs https://pkg.go.dev + will display our agent. Thanks @tydavis for your PR to fix this! [#254](https://github.com/newrelic/go-agent/pull/254) +* Added an Open Source repo linter GitHub action that runs on push. [#262](https://github.com/newrelic/go-agent/pull/262) +* Updated the README.md file to correctly show the support resources from New Relic. [#255](https://github.com/newrelic/go-agent/pull/255) + +### Support statement +* New Relic recommends that you upgrade the agent regularly and at a minimum every 3 months. +As of this release, the oldest supported version is [2.2.0](https://docs.newrelic.com/docs/release-notes/agent-release-notes/go-release-notes/go-agent-22). + ## 3.9.0 ### Changes diff --git a/README.md b/README.md index a3090fdb0..2555e66cf 100644 --- a/README.md +++ b/README.md @@ -1,48 +1,61 @@ -[![Community Project header](https://github.com/newrelic/opensource-website/raw/master/src/images/categories/Community_Project.png)](https://opensource.newrelic.com/oss-category/#community-project) +[![Community Plus header](https://github.com/newrelic/opensource-website/raw/master/src/images/categories/Community_Plus.png)](https://opensource.newrelic.com/oss-category/#community-plus) # New Relic Go Agent [![GoDoc](https://godoc.org/github.com/newrelic/go-agent?status.svg)](https://godoc.org/github.com/newrelic/go-agent/v3/newrelic/) [![Go Report Card](https://goreportcard.com/badge/github.com/newrelic/go-agent)](https://goreportcard.com/report/github.com/newrelic/go-agent) The New Relic Go Agent allows you to monitor your Go applications with New -Relic. It helps you track transactions, outbound requests, database calls, and +Relic. It helps you track transactions, outbound requests, database calls, and other parts of your Go application's behavior and provides a running overview of garbage collection, goroutine activity, and memory use. -Go is a compiled language, and doesn’t use a virtual machine. This means that setting up New Relic for your Golang app requires you to use our Go agent API and manually add New Relic methods to your source code. Our API provides exceptional flexibility and control over what gets instrumented. +Go is a compiled language, and doesn’t use a virtual machine. This means that setting up New Relic for your Golang app requires you to use our Go agent API and manually add New Relic methods to your source code. Our API provides exceptional flexibility and control over what gets instrumented. +## Installation -## Compatibility and Requirements +### Compatibility and Requirements For the latest version of the agent, Go 1.7+ is required, due to the use of `context.Context`. (For versions 2.X and earlier of the Go agent, Go 1.3+ is required.) Linux, OS X, and Windows (Vista, Server 2008 and later) are supported. +### Installing and using the Go agent -## Installing and using the Go agent +To install the agent, follow the instructions in our [GETTING_STARTED](https://github.com/newrelic/go-agent/blob/master/GETTING_STARTED.md) +document or our [GUIDE](https://github.com/newrelic/go-agent/blob/master/GUIDE.md). -To install the agent, follow the instructions in our [GETTING_STARTED](https://github.com/newrelic/go-agent/blob/master/GETTING_STARTED.md) -document or our [GUIDE](https://github.com/newrelic/go-agent/blob/master/GUIDE.md). - -We recommend instrumenting your Go code to get the maximum benefits from the +We recommend instrumenting your Go code to get the maximum benefits from the New Relic Go agent. But we make it easy to get great data in couple of ways: -* Even without adding instrumentation, just importing the agent and creating an -application will provide useful runtime information about your number of goroutines, +* Even without adding instrumentation, just importing the agent and creating an +application will provide useful runtime information about your number of goroutines, garbage collection statistics, and memory and CPU usage. -* You can use our many [INTEGRATION packages](https://github.com/newrelic/go-agent/tree/master/v3/integrations) -for out-of-the box support for many popular Go web frameworks and libraries. We -continue to add integration packages based on your feedback. You can weigh in on +* You can use our many [INTEGRATION packages](https://github.com/newrelic/go-agent/tree/master/v3/integrations) +for out-of-the box support for many popular Go web frameworks and libraries. We +continue to add integration packages based on your feedback. You can weigh in on potential integrations by opening an `Issue` here in our New Relic Go agent GitHub project. - -## Upgrading +### Upgrading If you have already been using version 2.X of the agent and are upgrading to version 3.0, see our [MIGRATION guide](MIGRATION.md) for details. +## Getting Started + +[v3/examples/server/main.go](v3/examples/server/main.go) is an example that +will appear as "Example App" in your New Relic applications list. To run it: + +``` +env NEW_RELIC_LICENSE_KEY=__YOUR_NEW_RELIC_LICENSE_KEY__LICENSE__ \ + go run v3/examples/server/main.go +``` + +Some endpoints exposed are [http://localhost:8000/](http://localhost:8000/) +and [http://localhost:8000/notice_error](http://localhost:8000/notice_error) + +## Usage -## Integration Packages +### Integration Packages The following [integration packages](https://godoc.org/github.com/newrelic/go-agent/v3/integrations) extend the base [newrelic](https://godoc.org/github.com/newrelic/go-agent/v3/newrelic/) package @@ -52,11 +65,11 @@ instrumented using the [newrelic](https://godoc.org/github.com/newrelic/go-agent package primitives. -### Service Frameworks +#### Service Frameworks | Project | Integration Package | | | ------------- | ------------- | - | @@ -68,7 +81,7 @@ https://docs.newrelic.com/docs/agents/go-agent/get-started/go-agent-compatibilit | [julienschmidt/httprouter](https://github.com/julienschmidt/httprouter) | [v3/integrations/nrhttprouter](https://godoc.org/github.com/newrelic/go-agent/v3/integrations/nrhttprouter) | Instrument inbound requests through the HttpRouter framework | | [micro/go-micro](https://github.com/micro/go-micro) | [v3/integrations/nrmicro](https://godoc.org/github.com/newrelic/go-agent/v3/integrations/nrmicro) | Instrument servers, clients, publishers, and subscribers through the Micro framework | -### Datastores +#### Datastores More information about instrumenting databases without an integration package using [newrelic](https://godoc.org/github.com/newrelic/go-agent/v3/newrelic/) @@ -86,7 +99,7 @@ package primitives can be found [here](GUIDE.md#datastore-segments). | [snowflakedb/gosnowflake](https://github.com/snowflakedb/gosnowflake) | [v3/integrations/nrsnowflake](https://godoc.org/github.com/newrelic/go-agent/v3/integrations/nrsnowflake) | Instrument Snowflake driver | | [mongodb/mongo-go-driver](https://github.com/mongodb/mongo-go-driver) | [v3/integrations/nrmongo](https://godoc.org/github.com/newrelic/go-agent/v3/integrations/nrmongo) | Instrument MongoDB calls | -### Logging +#### Logging | Project | Integration Package | | | ------------- | ------------- | - | @@ -94,7 +107,7 @@ package primitives can be found [here](GUIDE.md#datastore-segments). | [mgutz/logxi](https://github.com/mgutz/logxi) | [v3/integrations/nrlogxi](https://godoc.org/github.com/newrelic/go-agent/v3/integrations/nrlogxi) | Send agent log messages to Logxi | | [uber-go/zap](https://github.com/uber-go/zap) | [v3/integrations/nrzap](https://godoc.org/github.com/newrelic/go-agent/v3/integrations/nrzap) | Send agent log messages to Zap | -### AWS +#### AWS | Project | Integration Package | | | ------------- | ------------- | - | @@ -102,14 +115,14 @@ package primitives can be found [here](GUIDE.md#datastore-segments). | [aws/aws-sdk-go-v2](https://github.com/aws/aws-sdk-go-v2) | [v3/integrations/nrawssdk-v2](https://godoc.org/github.com/newrelic/go-agent/v3/integrations/nrawssdk-v2) | Instrument outbound calls made using Go AWS SDK v2 | | [aws/aws-lambda-go](https://github.com/aws/aws-lambda-go) | [v3/integrations/nrlambda](https://godoc.org/github.com/newrelic/go-agent/v3/integrations/nrlambda) | Instrument AWS Lambda applications | -### GraphQL +#### GraphQL | Project | Integration Package | | | ------------- | ------------- | - | | [graph-gophers/graphql-go](https://github.com/graph-gophers/graphql-go) | [v3/integrations/nrgraphgophers](https://godoc.org/github.com/newrelic/go-agent/v3/integrations/nrgraphgophers) | Instrument inbound requests using graph-gophers/graphql-go | | [graphql-go/graphql](https://github.com/graphql-go/graphql) | [v3/integrations/nrgraphqlgo](https://godoc.org/github.com/newrelic/go-agent/v3/integrations/nrgraphqlgo) | Instrument inbound requests using graphql-go/graphql | -### Misc +#### Misc | Project | Integration Package | | | ------------- | ------------- | - | @@ -123,22 +136,7 @@ These integration packages must be imported along with the [newrelic](https://godoc.org/github.com/newrelic/go-agent/v3/newrelic/) package, as shown in this [nrgin example](https://github.com/newrelic/go-agent/blob/master/v3/integrations/nrgin/example/main.go). - -## Runnable Example - -[v3/examples/server/main.go](v3/examples/server/main.go) is an example that -will appear as "Example App" in your New Relic applications list. To run it: - -``` -env NEW_RELIC_LICENSE_KEY=__YOUR_NEW_RELIC_LICENSE_KEY__LICENSE__ \ - go run v3/examples/server/main.go -``` - -Some endpoints exposed are [http://localhost:8000/](http://localhost:8000/) -and [http://localhost:8000/notice_error](http://localhost:8000/notice_error) - - -## Alternatives +### Alternatives If you are already using another open source solution to gather telemetry data, you may find it easier to use one of our open source exporters to send this data to New Relic: @@ -151,7 +149,10 @@ If you are already using another open source solution to gather telemetry data, ## Support -Should you need assistance with New Relic products, you are in good hands with several support channels. If the issue has been confirmed as a bug or is a Feature request, please file a Github issue. +Should you need assistance with New Relic products, you are in good hands with several support channels. + +If the issue has been confirmed as a bug or is a Feature request, please file a Github issue. + * [Go Agent GUIDE](GUIDE.md): Step by step how-to for key agent features * [New Relic Documentation](https://docs.newrelic.com/docs/agents/go-agent): Comprehensive guidance for using our platform @@ -162,25 +163,28 @@ Should you need assistance with New Relic products, you are in good hands with s ## Privacy -At New Relic we take your privacy and the security of your information seriously, and are committed to protecting your information. We must emphasize the importance of not sharing personal data in public forums, and ask all users to scrub logs and diagnostic information for sensitive information, whether personal, proprietary, or otherwise. +At New Relic we take your privacy and the security of your information seriously, and are committed to protecting your information. We must emphasize the importance of not sharing personal data in public forums, and ask all users to scrub logs and diagnostic information for sensitive information, whether personal, proprietary, or otherwise. We define "Personal Data" as any information relating to an identified or identifiable individual, including, for example, your name, phone number, post code or zip code, Device ID, IP address and email address. -Please review [New Relic’s General Data Privacy Notice](https://newrelic.com/termsandconditions/privacy) for more information. +For more information, review [New Relic’s General Data Privacy Notice](https://newrelic.com/termsandconditions/privacy). + +## Contribute + +We encourage your contributions to improve the Go Agent! Keep in mind when you submit your pull request, you'll need to sign the CLA via the click-through using CLA-Assistant. You only have to sign the CLA one time per project. -## Contributing +If you have any questions, or to execute our corporate CLA, required if your contribution is on behalf of a company, please drop us an email at opensource@newrelic.com. -We encourage your contributions to improve the Go Agent! Keep in mind when you submit your pull request, you'll need to sign the CLA via the click-through using CLA-Assistant. You only have to sign the CLA one time per project. If you have any questions, or to execute our corporate CLA, required if your contribution is on behalf of a company, please drop us an email at opensource@newrelic.com. **A note about vulnerabilities** -As noted in our [security policy](https://github.com/newrelic/.github/blob/master/security.md), New Relic is committed to the privacy and security of our customers and their data. We believe that providing coordinated disclosure by security researchers and engaging with the security community are important means to achieve our security goals. +As noted in our [security policy](https://github.com/newrelic/.github/blob/master/security.md), New Relic is committed to the privacy and security of our customers and their data. We believe that providing coordinated disclosure by security researchers and engaging with the security community are important means to achieve our security goals. If you believe you have found a security vulnerability in this project or any of New Relic's products or websites, we welcome and greatly appreciate you reporting it to New Relic through [HackerOne](https://hackerone.com/newrelic). If you would like to contribute to this project, please review [these guidelines](./CONTRIBUTING.md). -To all contributors, we thank you! Without your contribution, this project would not be what it is today. We also host a community project page dedicated to +To [all contributors](https://github.com/newrelic/go-agent/graphs/contributors), we thank you! Without your contribution, this project would not be what it is today. We also host a community project page dedicated to the [Go Agent](https://opensource.newrelic.com/projects/newrelic/go-agent). ## License diff --git a/v3/LICENSE.txt b/v3/LICENSE.txt new file mode 100644 index 000000000..cee548c2d --- /dev/null +++ b/v3/LICENSE.txt @@ -0,0 +1,206 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + +Versions 3.8.0 and above for this project are licensed under Apache 2.0. For +prior versions of this project, please see the LICENCE.txt file in the root +directory of that version for more information. diff --git a/v3/internal/utilization/aws.go b/v3/internal/utilization/aws.go index e18f66ade..d7fd10493 100644 --- a/v3/internal/utilization/aws.go +++ b/v3/internal/utilization/aws.go @@ -12,9 +12,12 @@ import ( ) const ( - awsHostname = "169.254.169.254" - awsEndpointPath = "/2016-09-02/dynamic/instance-identity/document" - awsEndpoint = "http://" + awsHostname + awsEndpointPath + awsHostname = "169.254.169.254" + awsEndpointPath = "/2016-09-02/dynamic/instance-identity/document" + awsTokenEndpointPath = "/latest/api/token" + awsEndpoint = "http://" + awsHostname + awsEndpointPath + awsTokenEndpoint = "http://" + awsHostname + awsTokenEndpointPath + awsTokenTTL = "60" // seconds this AWS utilization session will last ) type aws struct { @@ -44,6 +47,24 @@ func (e unexpectedAWSErr) Error() string { return fmt.Sprintf("unexpected AWS error: %v", e.e) } +// getAWSToken attempts to get the IMDSv2 token within the providerTimeout set +// provider.go. +func getAWSToken(client *http.Client) (token string, err error) { + request, err := http.NewRequest("PUT", awsTokenEndpoint, nil) + request.Header.Add("X-aws-ec2-metadata-token-ttl-seconds", awsTokenTTL) + response, err := client.Do(request) + if err != nil { + return "", err + } + defer response.Body.Close() + body, err := ioutil.ReadAll(response.Body) + if err != nil { + return "", err + } + + return string(body), nil +} + func getAWS(client *http.Client) (ret *aws, err error) { // In some cases, 3rd party providers might block requests to metadata // endpoints in such a way that causes a panic in the underlying @@ -56,7 +77,19 @@ func getAWS(client *http.Client) (ret *aws, err error) { } }() - response, err := client.Get(awsEndpoint) + // AWS' IMDSv2 requires us to get a token before requesting metadata. + awsToken, err := getAWSToken(client) + if err != nil { + // No unexpectedAWSErr here: A timeout is usually going to + // happen. + return nil, err + } + + //Add the header to the outbound request. + request, err := http.NewRequest("GET", awsEndpoint, nil) + request.Header.Add("X-aws-ec2-metadata-token", awsToken) + + response, err := client.Do(request) if err != nil { // No unexpectedAWSErr here: A timeout is usually going to // happen. diff --git a/v3/internal/utilization/provider.go b/v3/internal/utilization/provider.go index 03bcb64e0..a15bfef2b 100644 --- a/v3/internal/utilization/provider.go +++ b/v3/internal/utilization/provider.go @@ -14,8 +14,8 @@ import ( // Constants from the spec. const ( - maxFieldValueSize = 255 // The maximum value size, in bytes. - providerTimeout = 1 * time.Second // The maximum time a HTTP provider may block. + maxFieldValueSize = 255 // The maximum value size, in bytes. + providerTimeout = 500 * time.Millisecond // The maximum time a HTTP provider may block. lookupAddrTimeout = 500 * time.Millisecond ) diff --git a/v3/internal/utilization/provider_test.go b/v3/internal/utilization/provider_test.go index 1b5c1fbcc..7b57b9b67 100644 --- a/v3/internal/utilization/provider_test.go +++ b/v3/internal/utilization/provider_test.go @@ -48,8 +48,12 @@ type mockBody struct { } func (m *mockTransport) RoundTrip(r *http.Request) (*http.Response, error) { + + // Half the requests are going to the test's endpoint, while the other half + // are going to the AWS IMDSv2 token endpoint. Accept both. for match, response := range m.responses { - if r.URL.String() == match { + if (r.URL.String() == match) || + (r.URL.String() == awsTokenEndpoint) { return m.respond(response) } } diff --git a/v3/newrelic/LICENSE.txt b/v3/newrelic/LICENSE.txt new file mode 100644 index 000000000..cee548c2d --- /dev/null +++ b/v3/newrelic/LICENSE.txt @@ -0,0 +1,206 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + +Versions 3.8.0 and above for this project are licensed under Apache 2.0. For +prior versions of this project, please see the LICENCE.txt file in the root +directory of that version for more information. diff --git a/v3/newrelic/version.go b/v3/newrelic/version.go index c8a9dc39f..8fbd8be93 100644 --- a/v3/newrelic/version.go +++ b/v3/newrelic/version.go @@ -11,7 +11,7 @@ import ( const ( // Version is the full string version of this Go Agent. - Version = "3.9.0" + Version = "3.10.0" ) var (