Skip to content

Commit

Permalink
Merge pull request #497 from newrelic/develop
Browse files Browse the repository at this point in the history
Release v3.16.0
  • Loading branch information
nr-swilloughby authored May 19, 2022
2 parents 4b46fc5 + beddbb2 commit 41d47c0
Show file tree
Hide file tree
Showing 53 changed files with 728 additions and 360 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,12 @@ jobs:

# v2 integrations
- go-version: 1.13.x
# only versions up to 0.24.0 of awssdkv2 are supported by this code
pin: github.com/aws/[email protected]
dirs: _integrations/nrawssdk
- go-version: 1.13.x
dirs: _integrations/nrecho
pin: github.com/labstack/[email protected]
- go-version: 1.13.x
dirs: _integrations/nrgin/v1
- go-version: 1.13.x
Expand Down Expand Up @@ -231,6 +234,7 @@ jobs:
env:
DIRS: ${{ matrix.dirs }}
EXTRATESTING: ${{ matrix.extratesting }}
PIN: ${{ matrix.pin }}

go-agent-arm64:
# Run all unit tests on aarch64 emulator to ensure compatibility with AWS
Expand Down Expand Up @@ -271,7 +275,7 @@ jobs:
go version
cd v3/newrelic
go mod download github.com/golang/protobuf
go get
go get -t
echo ==== v3/newrelic tests ====
go test ./...
cd ../internal
Expand Down
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,25 @@
# ChangeLog
## 3.16.0
### Added
* Distributed Tracing is now the default mode of operation. It may be disabled by user configuration if so desired. [PR #495](https://github.com/newrelic/go-agent/pull/495)
* To disable DT, add `newrelic.ConfigDistributedTracerEnabled(false)` to your application configuration.
* To change the reservoir limit for how many span events are to be collected per harvest cycle from the default, add `newrelic.ConfigDistributedTracerReservoirLimit(`*newlimit*`)` to your application configuration.
* The reservoir limit's default was increased from 1000 to 2000.
* The maximum reservoir limit supported is 10,000.
* Note that Cross Application Tracing is now deprecated.
* Added support for gathering memory statistics via `PhysicalMemoryBytes` functions for OpenBSD.

### Fixed
* Corrected some example code to be cleaner.
* Updated version of nats-streaming-server. [PR #458](https://github.com/newrelic/go-agent/pull/458)
* Correction to nrpkgerrors so that `nrpkgerrors.Wrap` now checks if the error it is passed has attributes, and if it does, copies them into the New Relic error it creates.
This fixes [issue #409](https://github.com/newrelic/go-agent/issues/409) via [PR #441](https://github.com/newrelic/go-agent/pull/441).
* This increments the `nrpkgerrors` version to v1.1.0.

### Support Statement
New Relic recommends that you upgrade the agent regularly to ensure that you’re getting the latest features and performance benefits. Additionally, older releases will no longer be supported when they reach end-of-life.


## 3.15.2
### Added
* Strings logged via the Go Agent's built-in logger will have strings of the form `license_key=`*hex-string* changed to `license_key=[redacted]` before they are output, regardless of severity level, where *hex-string* means a sequence of upper- or lower-case hexadecimal digits and dots ('.'). This incorporates [PR #415](https://github.com/newrelic/go-agent/pull/415).
Expand Down
53 changes: 32 additions & 21 deletions build-script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,34 @@ fi

pwd=$(pwd)

# inputs
# 1: repo pin; example: github.com/rewrelic/[email protected]
pin_go_dependency() {
if [[ ! -z "$1" ]]; then
echo "Pinning: $1"
repo=$(echo "$1" | cut -d '@' -f1)
pinTo=$(echo "$1" | cut -d '@' -f2)
set +e
go get -u "$repo" # this go get will fail to build
set -e
cd "$GOPATH"/src/"$repo"
git checkout "$pinTo"
cd -
fi
}

IFS=","
for dir in $DIRS; do
cd "$pwd/$dir"

if [ -f "go.mod" ]; then
go mod edit -replace github.com/newrelic/go-agent/v3=$pwd/v3
go mod edit -replace github.com/newrelic/go-agent/v3="$pwd"/v3
fi

# go get is necessary for testing v2 integrations since they do not have
# a go.mod file.
if [[ $dir =~ "_integrations" ]]; then
go get -t ./...
fi
pin_go_dependency "$PIN"

# avoid testing v3 code when testing v2 newrelic package
if [ $dir == "." ]; then
if [ "$dir" == "." ]; then
rm -rf v3/
else
# Only v3 code version 1.9+ needs GRPC dependencies
Expand All @@ -44,31 +57,29 @@ for dir in $DIRS; do
V1_10="1.10"
V1_11="1.11"
V1_12="1.12"
V1_13="1.13"
V1_14="1.14"
if [[ "$VERSION" =~ .*"$V1_7".* || "$VERSION" =~ .*"$V1_8".* ]]; then
echo "Not installing GRPC for old versions"
elif [[ "$VERSION" =~ .*"$V1_9" || "$VERSION" =~ .*"$V1_10" || "$VERSION" =~ .*"$V1_11" || "$VERSION" =~ .*"$V1_12" ]]; then
elif [[ "$VERSION" =~ .*"$V1_9" || "$VERSION" =~ .*"$V1_10" || "$VERSION" =~ .*"$V1_11" || "$VERSION" =~ .*"$V1_12" || "$VERSION" =~ .*"$V1_13" || "$VERSION" =~ .*"$V1_14" ]]; then
# install v3 dependencies that support this go version
set +e
go get -u google.golang.org/grpc # this go get will fail to build
set -e
cd $GOPATH/src/google.golang.org/grpc
git checkout v1.31.0
cd -

set +e
go get -u golang.org/x/net/http2 # this go get will fail to build
set -e
cd $GOPATH/src/golang.org/x/net/http2
git checkout 7fd8e65b642006927f6cec5cb4241df7f98a2210
cd -
pin_go_dependency "google.golang.org/[email protected]"
pin_go_dependency "golang.org/x/net/http2@7fd8e65b642006927f6cec5cb4241df7f98a2210"

# install protobuf once dependencies are resolved
go get -u github.com/golang/protobuf/protoc-gen-go
else
go get -u github.com/golang/protobuf/protoc-gen-go
go get -u google.golang.org/grpc
fi
fi

# go get is necessary for testing v2 integrations since they do not have
# a go.mod file.
if [[ $dir =~ "_integrations" ]]; then
go get -t ./...
fi

go test -race -benchtime=1ms -bench=. ./...
go vet ./...

Expand Down
10 changes: 7 additions & 3 deletions internal/expect.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@ type Validator interface {
Error(...interface{})
}

func validateStringField(v Validator, fieldName, v1, v2 string) {
if v1 != v2 {
v.Error(fieldName, v1, v2)
func validateStringField(v Validator, fieldName, expect, actual string) {
// If an expected value is not set, we assume the user does not want to validate it
if expect == "" {
return
}
if expect != actual {
v.Error(fieldName, "incorrect: Expected:", expect, " Got:", actual)
}
}

Expand Down
35 changes: 35 additions & 0 deletions internal/sysinfo/memtotal_openbsd_amd64.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2020 New Relic Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

package sysinfo

import (
"syscall"
"unsafe"
)

// PhysicalMemoryBytes returns the total amount of host memory.
func PhysicalMemoryBytes() (uint64, error) {
mib := []int32{6 /* CTL_HW */, 19 /* HW_PHYSMEM64 */}

buf := make([]byte, 8)
bufLen := uintptr(8)

_, _, e1 := syscall.Syscall6(syscall.SYS___SYSCTL,
uintptr(unsafe.Pointer(&mib[0])), uintptr(len(mib)),
uintptr(unsafe.Pointer(&buf[0])), uintptr(unsafe.Pointer(&bufLen)),
uintptr(0), uintptr(0))

if e1 != 0 {
return 0, e1
}

switch bufLen {
case 4:
return uint64(*(*uint32)(unsafe.Pointer(&buf[0]))), nil
case 8:
return *(*uint64)(unsafe.Pointer(&buf[0])), nil
default:
return 0, syscall.EIO
}
}
49 changes: 49 additions & 0 deletions internal/sysinfo/memtotal_openbsd_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright 2020 New Relic Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

package sysinfo

import (
"errors"
"os/exec"
"regexp"
"strconv"
"testing"
)

var re = regexp.MustCompile(`hw\.physmem=(\d+)`)

func openbsdSysctlMemoryBytes() (uint64, error) {
out, err := exec.Command("/sbin/sysctl", "hw.physmem").Output()
if err != nil {
return 0, err
}

match := re.FindSubmatch(out)
if match == nil {
return 0, errors.New("memory size not found in sysctl output")
}

bts, err := strconv.ParseUint(string(match[1]), 10, 64)
if err != nil {
return 0, err
}

return bts, nil
}

func TestPhysicalMemoryBytes(t *testing.T) {
mem, err := PhysicalMemoryBytes()
if err != nil {
t.Fatal(err)
}

mem2, err := openbsdSysctlMemoryBytes()
if nil != err {
t.Fatal(err)
}

if mem != mem2 {
t.Errorf("Expected %d, got %d\n", mem2, mem)
}
}
22 changes: 0 additions & 22 deletions internal/tools/utilization/Dockerfile

This file was deleted.

31 changes: 0 additions & 31 deletions internal/tools/utilization/main.go

This file was deleted.

15 changes: 5 additions & 10 deletions v3/examples/client/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2020 New Relic Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

//
package main

import (
Expand All @@ -14,14 +14,14 @@ import (

func doRequest(txn *newrelic.Transaction) error {
req, err := http.NewRequest("GET", "http://localhost:8000/segments", nil)
if nil != err {
if err != nil {
return err
}
client := &http.Client{}
seg := newrelic.StartExternalSegment(txn, req)
defer seg.End()
resp, err := client.Do(req)
if nil != err {
if err != nil {
return err
}
fmt.Println("response code is", resp.StatusCode)
Expand All @@ -35,19 +35,14 @@ func main() {
newrelic.ConfigDebugLogger(os.Stdout),
newrelic.ConfigDistributedTracerEnabled(true),
)
if nil != err {
if err != nil {
fmt.Println(err)
os.Exit(1)
}

// Wait for the application to connect.
if err = app.WaitForConnection(5 * time.Second); nil != err {
fmt.Println(err)
}

txn := app.StartTransaction("client-txn")
err = doRequest(txn)
if nil != err {
if err != nil {
txn.NoticeError(err)
}
txn.End()
Expand Down
6 changes: 3 additions & 3 deletions v3/examples/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func external(w http.ResponseWriter, r *http.Request) {
resp, err := http.DefaultClient.Do(req)
es.End()

if nil != err {
if err != nil {
io.WriteString(w, err.Error())
return
}
Expand Down Expand Up @@ -199,7 +199,7 @@ func roundtripper(w http.ResponseWriter, r *http.Request) {
// request = newrelic.RequestWithTransactionContext(request, txn)

resp, err := client.Do(request)
if nil != err {
if err != nil {
io.WriteString(w, err.Error())
return
}
Expand Down Expand Up @@ -252,7 +252,7 @@ func main() {
newrelic.ConfigFromEnvironment(),
newrelic.ConfigDebugLogger(os.Stdout),
)
if nil != err {
if err != nil {
fmt.Println(err)
os.Exit(1)
}
Expand Down
11 changes: 1 addition & 10 deletions v3/integrations/nrawssdk-v1/nrawssdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
package nrawssdk

import (
"net/http"

"github.com/aws/aws-sdk-go/aws/request"
"github.com/newrelic/go-agent/v3/internal"
"github.com/newrelic/go-agent/v3/internal/awssupport"
Expand All @@ -26,14 +24,7 @@ func startSegment(req *request.Request) {
}

func endSegment(req *request.Request) {
ctx := req.HTTPRequest.Context()

hdr := http.Header{}
if req.HTTPRequest != nil {
hdr = req.HTTPRequest.Header
}

awssupport.EndSegment(ctx, hdr)
awssupport.EndSegment(req.HTTPRequest.Context(), req.HTTPResponse)
}

// InstrumentHandlers will add instrumentation to the given *request.Handlers.
Expand Down
Loading

0 comments on commit 41d47c0

Please sign in to comment.