Skip to content

Commit

Permalink
Merge branch 'develop' into customeventslimiter
Browse files Browse the repository at this point in the history
  • Loading branch information
mirackara committed Jun 29, 2022
2 parents 9dc794d + e6316bc commit d5919d5
Show file tree
Hide file tree
Showing 16 changed files with 230 additions and 104 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/ci.yaml
Expand Up @@ -124,9 +124,10 @@ jobs:
dirs: v3/integrations/nrecho-v3
# Test against the latest v3 Echo:
extratesting: go get -u github.com/labstack/echo@v3
- go-version: 1.15.x
# go/new/http no longer stable under go 1.17.x
- go-version: 1.17.x
dirs: v3/integrations/nrecho-v4
extratesting: go get -u github.com/labstack/echo@master
extratesting: go get -u github.com/labstack/echo/v4@master
- go-version: 1.15.x
dirs: v3/integrations/nrelasticsearch-v7
extratesting: go get -u github.com/elastic/go-elasticsearch/v7@7.x
Expand Down
7 changes: 7 additions & 0 deletions build-script.sh
Expand Up @@ -35,6 +35,10 @@ pin_go_dependency() {
fi
}

go_mod_tidy() {
go mod tidy
}

IFS=","
for dir in $DIRS; do
cd "$pwd/$dir"
Expand All @@ -43,6 +47,9 @@ for dir in $DIRS; do
go mod edit -replace github.com/newrelic/go-agent/v3="$pwd"/v3
fi

# Do tidy if we can
go_mod_tidy || true

pin_go_dependency "$PIN"

# avoid testing v3 code when testing v2 newrelic package
Expand Down
1 change: 0 additions & 1 deletion internal/harvest.go
Expand Up @@ -183,7 +183,6 @@ type HarvestConfigurer interface {
MaxCustomEvents() int
// MaxErrorEvents returns the maximum number of Error Events that should be reported per period
MaxErrorEvents() int

MaxTxnEventer
}

Expand Down
23 changes: 20 additions & 3 deletions v3/integrations/nrecho-v4/go.mod
@@ -1,10 +1,27 @@
module github.com/newrelic/go-agent/v3/integrations/nrecho-v4

// As of Dec 2019, the echo go.mod file uses 1.12:
// As of Jun 2022, the echo go.mod file uses 1.17:
// https://github.com/labstack/echo/blob/master/go.mod
go 1.12
go 1.17


require (
github.com/labstack/echo/v4 v4.5.0
github.com/newrelic/go-agent/v3 v3.15.0
github.com/newrelic/go-agent/v3 v3.16.1
)

require (
github.com/golang/protobuf v1.4.3 // indirect
github.com/labstack/gommon v0.3.0 // indirect
github.com/mattn/go-colorable v0.1.8 // indirect
github.com/mattn/go-isatty v0.0.12 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.1 // indirect
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 // indirect
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4 // indirect
golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57 // indirect
golang.org/x/text v0.3.6 // indirect
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 // indirect
google.golang.org/grpc v1.39.0 // indirect
google.golang.org/protobuf v1.25.0 // indirect
)
75 changes: 52 additions & 23 deletions v3/integrations/nrecho-v4/nrecho_test.go
Expand Up @@ -5,13 +5,12 @@ package nrecho

import (
"errors"
"net/http"
"net/http/httptest"
"testing"

"github.com/labstack/echo/v4"
"github.com/newrelic/go-agent/v3/internal"
"github.com/newrelic/go-agent/v3/internal/integrationsupport"
"net/http"
"net/http/httptest"
"testing"
)

func TestBasicRoute(t *testing.T) {
Expand All @@ -34,13 +33,20 @@ func TestBasicRoute(t *testing.T) {
t.Error("wrong response body", respBody)
}
app.ExpectTxnMetrics(t, internal.WantTxn{
Name: "GET /hello",
IsWeb: true,
Name: "GET /hello",
IsWeb: true,
UnknownCaller: true,
})

app.ExpectTxnEvents(t, []internal.WantEvent{{
Intrinsics: map[string]interface{}{
"name": "WebTransaction/Go/GET /hello",
"nr.apdexPerfZone": "S",
"sampled": false,
// Note: "*" is a wildcard value
"guid": "*",
"traceId": "*",
"priority": "*",
},
AgentAttributes: map[string]interface{}{
"httpResponseCode": "200",
Expand Down Expand Up @@ -94,9 +100,11 @@ func TestTransactionContext(t *testing.T) {
t.Error("wrong response body", respBody)
}
app.ExpectTxnMetrics(t, internal.WantTxn{
Name: "GET /hello",
IsWeb: true,
NumErrors: 1,
Name: "GET /hello",
IsWeb: true,
NumErrors: 1,
UnknownCaller: true,
ErrorByCaller: true,
})
}

Expand All @@ -114,8 +122,9 @@ func TestNotFoundHandler(t *testing.T) {

e.ServeHTTP(response, req)
app.ExpectTxnMetrics(t, internal.WantTxn{
Name: "NotFoundHandler",
IsWeb: true,
Name: "NotFoundHandler",
IsWeb: true,
UnknownCaller: true,
})
}

Expand All @@ -136,9 +145,11 @@ func TestMethodNotAllowedHandler(t *testing.T) {

e.ServeHTTP(response, req)
app.ExpectTxnMetrics(t, internal.WantTxn{
Name: "MethodNotAllowedHandler",
IsWeb: true,
NumErrors: 1,
Name: "MethodNotAllowedHandler",
IsWeb: true,
NumErrors: 1,
UnknownCaller: true,
ErrorByCaller: true,
})
}

Expand All @@ -159,14 +170,20 @@ func TestReturnsHTTPError(t *testing.T) {

e.ServeHTTP(response, req)
app.ExpectTxnMetrics(t, internal.WantTxn{
Name: "GET /hello",
IsWeb: true,
NumErrors: 1,
Name: "GET /hello",
IsWeb: true,
NumErrors: 1,
UnknownCaller: true,
ErrorByCaller: true,
})
app.ExpectTxnEvents(t, []internal.WantEvent{{
Intrinsics: map[string]interface{}{
"name": "WebTransaction/Go/GET /hello",
"nr.apdexPerfZone": "F",
"sampled": false,
"guid": "*",
"traceId": "*",
"priority": "*",
},
AgentAttributes: map[string]interface{}{
"httpResponseCode": "418",
Expand Down Expand Up @@ -195,14 +212,20 @@ func TestReturnsError(t *testing.T) {

e.ServeHTTP(response, req)
app.ExpectTxnMetrics(t, internal.WantTxn{
Name: "GET /hello",
IsWeb: true,
NumErrors: 1,
Name: "GET /hello",
IsWeb: true,
NumErrors: 1,
UnknownCaller: true,
ErrorByCaller: true,
})
app.ExpectTxnEvents(t, []internal.WantEvent{{
Intrinsics: map[string]interface{}{
"name": "WebTransaction/Go/GET /hello",
"nr.apdexPerfZone": "F",
"sampled": false,
"guid": "*",
"traceId": "*",
"priority": "*",
},
AgentAttributes: map[string]interface{}{
"httpResponseCode": "500",
Expand Down Expand Up @@ -231,14 +254,20 @@ func TestResponseCode(t *testing.T) {

e.ServeHTTP(response, req)
app.ExpectTxnMetrics(t, internal.WantTxn{
Name: "GET /hello",
IsWeb: true,
NumErrors: 1,
Name: "GET /hello",
IsWeb: true,
NumErrors: 1,
UnknownCaller: true,
ErrorByCaller: true,
})
app.ExpectTxnEvents(t, []internal.WantEvent{{
Intrinsics: map[string]interface{}{
"name": "WebTransaction/Go/GET /hello",
"nr.apdexPerfZone": "F",
"sampled": false,
"guid": "*",
"traceId": "*",
"priority": "*",
},
AgentAttributes: map[string]interface{}{
"httpResponseCode": "418",
Expand Down
18 changes: 9 additions & 9 deletions v3/integrations/nrgrpc/nrgrpc_server.go
Expand Up @@ -198,9 +198,9 @@ func ErrorInterceptorStatusHandler(ctx context.Context, txn *newrelic.Transactio
Message: s.Message(),
Class: "gRPC Status: " + s.Code().String(),
})
txn.AddAttribute("GrpcStatusLevel", "error")
txn.AddAttribute("GrpcStatusMessage", s.Message())
txn.AddAttribute("GrpcStatusCode", s.Code().String())
txn.AddAttribute("grpcStatusLevel", "error")
txn.AddAttribute("grpcStatusMessage", s.Message())
txn.AddAttribute("grpcStatusCode", s.Code().String())
}

//
Expand All @@ -212,9 +212,9 @@ func ErrorInterceptorStatusHandler(ctx context.Context, txn *newrelic.Transactio
//
func WarningInterceptorStatusHandler(ctx context.Context, txn *newrelic.Transaction, s *status.Status) {
txn.SetWebResponse(nil).WriteHeader(int(codes.OK))
txn.AddAttribute("GrpcStatusLevel", "warning")
txn.AddAttribute("GrpcStatusMessage", s.Message())
txn.AddAttribute("GrpcStatusCode", s.Code().String())
txn.AddAttribute("grpcStatusLevel", "warning")
txn.AddAttribute("grpcStatusMessage", s.Message())
txn.AddAttribute("grpcStatusCode", s.Code().String())
}

//
Expand All @@ -226,9 +226,9 @@ func WarningInterceptorStatusHandler(ctx context.Context, txn *newrelic.Transact
//
func InfoInterceptorStatusHandler(ctx context.Context, txn *newrelic.Transaction, s *status.Status) {
txn.SetWebResponse(nil).WriteHeader(int(codes.OK))
txn.AddAttribute("GrpcStatusLevel", "info")
txn.AddAttribute("GrpcStatusMessage", s.Message())
txn.AddAttribute("GrpcStatusCode", s.Code().String())
txn.AddAttribute("grpcStatusLevel", "info")
txn.AddAttribute("grpcStatusMessage", s.Message())
txn.AddAttribute("grpcStatusCode", s.Code().String())
}

//
Expand Down
24 changes: 12 additions & 12 deletions v3/integrations/nrgrpc/nrgrpc_server_test.go
Expand Up @@ -182,9 +182,9 @@ func TestUnaryServerInterceptorError(t *testing.T) {
"traceId": internal.MatchAnything,
},
UserAttributes: map[string]interface{}{
"GrpcStatusMessage": "oooooops!",
"GrpcStatusCode": "DataLoss",
"GrpcStatusLevel": "error",
"grpcStatusMessage": "oooooops!",
"grpcStatusCode": "DataLoss",
"grpcStatusLevel": "error",
},
AgentAttributes: map[string]interface{}{
"httpResponseCode": 0,
Expand Down Expand Up @@ -215,9 +215,9 @@ func TestUnaryServerInterceptorError(t *testing.T) {
"request.uri": "grpc://bufnet/TestApplication/DoUnaryUnaryError",
},
UserAttributes: map[string]interface{}{
"GrpcStatusMessage": "oooooops!",
"GrpcStatusCode": "DataLoss",
"GrpcStatusLevel": "error",
"grpcStatusMessage": "oooooops!",
"grpcStatusCode": "DataLoss",
"grpcStatusLevel": "error",
},
}})
}
Expand Down Expand Up @@ -592,9 +592,9 @@ func TestStreamServerInterceptorError(t *testing.T) {
"traceId": internal.MatchAnything,
},
UserAttributes: map[string]interface{}{
"GrpcStatusLevel": "error",
"GrpcStatusMessage": "oooooops!",
"GrpcStatusCode": "DataLoss",
"grpcStatusLevel": "error",
"grpcStatusMessage": "oooooops!",
"grpcStatusCode": "DataLoss",
},
AgentAttributes: map[string]interface{}{
"httpResponseCode": 0,
Expand Down Expand Up @@ -625,9 +625,9 @@ func TestStreamServerInterceptorError(t *testing.T) {
"request.uri": "grpc://bufnet/TestApplication/DoUnaryStreamError",
},
UserAttributes: map[string]interface{}{
"GrpcStatusLevel": "error",
"GrpcStatusMessage": "oooooops!",
"GrpcStatusCode": "DataLoss",
"grpcStatusLevel": "error",
"grpcStatusMessage": "oooooops!",
"grpcStatusCode": "DataLoss",
},
}})
}
Expand Down
8 changes: 4 additions & 4 deletions v3/internal/connect_reply.go
Expand Up @@ -136,19 +136,19 @@ func (r *ConnectReply) ConfigurablePeriod() time.Duration {
func uintPtr(x uint) *uint { return &x }

// DefaultEventHarvestConfig provides faster event harvest defaults.
func DefaultEventHarvestConfig(maxTxnEvents int, maxCustomEvents int) EventHarvestConfig {
func DefaultEventHarvestConfig(maxTxnEvents int) EventHarvestConfig {
cfg := EventHarvestConfig{}
cfg.ReportPeriodMs = DefaultConfigurableEventHarvestMs
cfg.Limits.TxnEvents = uintPtr(uint(maxTxnEvents))
cfg.Limits.CustomEvents = uintPtr(uint(maxCustomEvents))
cfg.Limits.CustomEvents = uintPtr(uint(MaxCustomEvents))
cfg.Limits.ErrorEvents = uintPtr(uint(MaxErrorEvents))
return cfg
}

// DefaultEventHarvestConfigWithDT is an extended version of DefaultEventHarvestConfig,
// with the addition that it takes into account distributed tracer span event harvest limits.
func DefaultEventHarvestConfigWithDT(maxTxnEvents int, dtEnabled bool, spanEventLimit int, maxCustomEvents int) EventHarvestConfig {
cfg := DefaultEventHarvestConfig(maxTxnEvents,maxCustomEvents)
func DefaultEventHarvestConfigWithDT(maxTxnEvents int, dtEnabled bool, spanEventLimit int) EventHarvestConfig {
cfg := DefaultEventHarvestConfig(maxTxnEvents)
if dtEnabled {
cfg.Limits.SpanEvents = uintPtr(uint(spanEventLimit))
}
Expand Down
8 changes: 5 additions & 3 deletions v3/internal/expect.go
Expand Up @@ -101,9 +101,11 @@ func HarvestTesting(app interface{}, replyfn func(*ConnectReply)) {

// WantTxn provides the expectation parameters to ExpectTxnMetrics.
type WantTxn struct {
Name string
IsWeb bool
NumErrors int
Name string
IsWeb bool
NumErrors int
UnknownCaller bool
ErrorByCaller bool
}

// Expect exposes methods that allow for testing whether the correct data was
Expand Down
15 changes: 15 additions & 0 deletions v3/internal/jsonx/encode.go
Expand Up @@ -118,6 +118,21 @@ func AppendFloat(buf *bytes.Buffer, x float64) error {
return nil
}

func AppendFloat32(buf *bytes.Buffer, x float32) error {
var scratch [64]byte
x64 := float64(x)

if math.IsInf(x64, 0) || math.IsNaN(x64) {
return &json.UnsupportedValueError{
Value: reflect.ValueOf(x64),
Str: strconv.FormatFloat(x64, 'g', -1, 32),
}
}

buf.Write(strconv.AppendFloat(scratch[:0], x64, 'g', -1, 32))
return nil
}

// AppendFloatArray appends an array of numeric literals to buf.
func AppendFloatArray(buf *bytes.Buffer, a ...float64) error {
buf.WriteByte('[')
Expand Down

0 comments on commit d5919d5

Please sign in to comment.