Skip to content

Commit

Permalink
Don't use unknown for empty Host and PortPathOrID
Browse files Browse the repository at this point in the history
  • Loading branch information
will@newrelic.com committed Oct 18, 2016
1 parent 372845e commit 1c3938b
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 49 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,9 @@
## ChangeLog

* If [DatastoreSegment](https://godoc.org/github.com/newrelic/go-agent#DatastoreSegment)
fields `Host` and `PortPathOrID` are not provided, they will no longer appear
as `"unknown"` in transaction traces and slow query traces.

## 1.4.0

* Added support for slow query traces. Slow datastore segments will now
Expand Down
24 changes: 9 additions & 15 deletions internal/tracing.go
Expand Up @@ -53,8 +53,6 @@ type Tracer struct {
SlowQueriesEnabled bool
SlowQueryThreshold time.Duration
SlowQueries *slowQueries

InstanceReportingDisabled bool
}

const (
Expand Down Expand Up @@ -265,18 +263,14 @@ func EndDatastoreSegment(p EndDatastoreParams) {
if p.Product == "" {
p.Product = datastoreProductUnknown
}
if p.Tracer.InstanceReportingDisabled {
p.Host = ""
p.PortPathOrID = ""
} else {
if p.PortPathOrID == "" {
p.PortPathOrID = unknownDatastorePortPathOrID
}
if p.Host == "" {
p.Host = unknownDatastoreHost
} else if _, ok := hostsToReplace[p.Host]; ok {
p.Host = thisHost
}
if p.Host == "" && p.PortPathOrID != "" {
p.Host = unknownDatastoreHost
}
if p.PortPathOrID == "" && p.Host != "" {
p.PortPathOrID = unknownDatastorePortPathOrID
}
if _, ok := hostsToReplace[p.Host]; ok {
p.Host = thisHost
}

// We still want to create a slowQuery if the consumer has not provided
Expand Down Expand Up @@ -398,7 +392,7 @@ func MergeBreakdownMetrics(t *Tracer, metrics *metricTable, scope string, isWeb
metrics.add(product.Other, "", *data, forced)
}

if !t.InstanceReportingDisabled {
if key.Host != "" && key.PortPathOrID != "" {
instance := datastoreInstanceMetric(key)
metrics.add(instance, "", *data, unforced)
}
Expand Down
4 changes: 0 additions & 4 deletions internal/tracing_test.go
Expand Up @@ -429,8 +429,6 @@ func TestSegmentDatastore(t *testing.T) {
{"Datastore/operation/Unknown/other", scope, false, []float64{1, 1, 1, 1, 1, 1}},
{"Datastore/statement/MySQL/my_table/SELECT", "", false, []float64{1, 1, 1, 1, 1, 1}},
{"Datastore/statement/MySQL/my_table/SELECT", scope, false, []float64{1, 1, 1, 1, 1, 1}},
{"Datastore/instance/MySQL/unknown/unknown", "", false, []float64{3, 5, 4, 1, 3, 11}},
{"Datastore/instance/Unknown/unknown/unknown", "", false, []float64{1, 1, 1, 1, 1, 1}},
})

metrics = newMetricTable(100, time.Now())
Expand All @@ -449,8 +447,6 @@ func TestSegmentDatastore(t *testing.T) {
{"Datastore/operation/Unknown/other", scope, false, []float64{1, 1, 1, 1, 1, 1}},
{"Datastore/statement/MySQL/my_table/SELECT", "", false, []float64{1, 1, 1, 1, 1, 1}},
{"Datastore/statement/MySQL/my_table/SELECT", scope, false, []float64{1, 1, 1, 1, 1, 1}},
{"Datastore/instance/MySQL/unknown/unknown", "", false, []float64{3, 5, 4, 1, 3, 11}},
{"Datastore/instance/Unknown/unknown/unknown", "", false, []float64{1, 1, 1, 1, 1, 1}},
})
}

Expand Down
2 changes: 0 additions & 2 deletions internal/txn_trace_test.go
Expand Up @@ -81,8 +81,6 @@ func TestTxnTrace(t *testing.T) {
[9000,10000,"Custom/t6",{},[]]
]],
[12000,13000,"Datastore/operation/MySQL/SELECT",{
"host":"unknown",
"port_path_or_id":"unknown",
"query":"'SELECT' on 'unknown' using 'MySQL'"
},[]],
[14000,15000,"External/unknown/all",{},[]]
Expand Down
80 changes: 56 additions & 24 deletions internal_slow_queries_test.go
Expand Up @@ -31,8 +31,8 @@ func TestSlowQueryBasic(t *testing.T) {
TxnName: "WebTransaction/Go/myName",
TxnURL: "/hello",
DatabaseName: "",
Host: "unknown",
PortPathOrID: "unknown",
Host: "",
PortPathOrID: "",
}})
}

Expand Down Expand Up @@ -121,8 +121,8 @@ func TestSlowQueryDatabaseProvided(t *testing.T) {
TxnName: "WebTransaction/Go/myName",
TxnURL: "/hello",
DatabaseName: "my_database",
Host: "unknown",
PortPathOrID: "unknown",
Host: "",
PortPathOrID: "",
}})
}

Expand Down Expand Up @@ -153,6 +153,22 @@ func TestSlowQueryHostProvided(t *testing.T) {
Host: "db-server-1",
PortPathOrID: "unknown",
}})
scope := "WebTransaction/Go/myName"
app.ExpectMetrics(t, []internal.WantMetric{
{"WebTransaction/Go/myName", "", true, nil},
{"WebTransaction", "", true, nil},
{"HttpDispatcher", "", true, nil},
{"Apdex", "", true, nil},
{"Apdex/Go/myName", "", false, nil},
{"Datastore/all", "", true, nil},
{"Datastore/allWeb", "", true, nil},
{"Datastore/MySQL/all", "", true, nil},
{"Datastore/MySQL/allWeb", "", true, nil},
{"Datastore/operation/MySQL/INSERT", "", false, nil},
{"Datastore/statement/MySQL/users/INSERT", "", false, nil},
{"Datastore/statement/MySQL/users/INSERT", scope, false, nil},
{"Datastore/instance/MySQL/db-server-1/unknown", "", false, nil},
})
}

func TestSlowQueryPortProvided(t *testing.T) {
Expand Down Expand Up @@ -182,6 +198,22 @@ func TestSlowQueryPortProvided(t *testing.T) {
Host: "unknown",
PortPathOrID: "98021",
}})
scope := "WebTransaction/Go/myName"
app.ExpectMetrics(t, []internal.WantMetric{
{"WebTransaction/Go/myName", "", true, nil},
{"WebTransaction", "", true, nil},
{"HttpDispatcher", "", true, nil},
{"Apdex", "", true, nil},
{"Apdex/Go/myName", "", false, nil},
{"Datastore/all", "", true, nil},
{"Datastore/allWeb", "", true, nil},
{"Datastore/MySQL/all", "", true, nil},
{"Datastore/MySQL/allWeb", "", true, nil},
{"Datastore/operation/MySQL/INSERT", "", false, nil},
{"Datastore/statement/MySQL/users/INSERT", "", false, nil},
{"Datastore/statement/MySQL/users/INSERT", scope, false, nil},
{"Datastore/instance/MySQL/unknown/98021", "", false, nil},
})
}

func TestSlowQueryHostPortProvided(t *testing.T) {
Expand Down Expand Up @@ -266,17 +298,17 @@ func TestSlowQueryAggregation(t *testing.T) {
TxnName: "WebTransaction/Go/myName",
TxnURL: "/hello",
DatabaseName: "",
Host: "unknown",
PortPathOrID: "unknown",
Host: "",
PortPathOrID: "",
}, {
Count: 1,
MetricName: "Datastore/statement/Postgres/products/INSERT",
Query: "INSERT INTO products (name, price) VALUES ($1, $2)",
TxnName: "WebTransaction/Go/myName",
TxnURL: "/hello",
DatabaseName: "",
Host: "unknown",
PortPathOrID: "unknown",
Host: "",
PortPathOrID: "",
},
})
}
Expand All @@ -303,8 +335,8 @@ func TestSlowQueryMissingQuery(t *testing.T) {
TxnName: "WebTransaction/Go/myName",
TxnURL: "/hello",
DatabaseName: "",
Host: "unknown",
PortPathOrID: "unknown",
Host: "",
PortPathOrID: "",
}})
}

Expand All @@ -327,8 +359,8 @@ func TestSlowQueryMissingEverything(t *testing.T) {
TxnName: "WebTransaction/Go/myName",
TxnURL: "/hello",
DatabaseName: "",
Host: "unknown",
PortPathOrID: "unknown",
Host: "",
PortPathOrID: "",
}})
scope := "WebTransaction/Go/myName"
app.ExpectMetrics(t, []internal.WantMetric{
Expand All @@ -343,7 +375,6 @@ func TestSlowQueryMissingEverything(t *testing.T) {
{"Datastore/Unknown/allWeb", "", true, nil},
{"Datastore/operation/Unknown/other", "", false, nil},
{"Datastore/operation/Unknown/other", scope, false, nil},
{"Datastore/instance/Unknown/unknown/unknown", "", false, nil},
})
}

Expand Down Expand Up @@ -375,8 +406,8 @@ func TestSlowQueryWithQueryParameters(t *testing.T) {
TxnName: "WebTransaction/Go/myName",
TxnURL: "/hello",
DatabaseName: "",
Host: "unknown",
PortPathOrID: "unknown",
Host: "",
PortPathOrID: "",
Params: params,
}})
}
Expand Down Expand Up @@ -410,8 +441,8 @@ func TestSlowQueryHighSecurity(t *testing.T) {
TxnName: "WebTransaction/Go/myName",
TxnURL: "/hello",
DatabaseName: "",
Host: "unknown",
PortPathOrID: "unknown",
Host: "",
PortPathOrID: "",
Params: nil,
}})
}
Expand Down Expand Up @@ -447,8 +478,8 @@ func TestSlowQueryInvalidParameters(t *testing.T) {
TxnName: "WebTransaction/Go/myName",
TxnURL: "/hello",
DatabaseName: "",
Host: "unknown",
PortPathOrID: "unknown",
Host: "",
PortPathOrID: "",
Params: map[string]interface{}{
"str": "zap",
"int": 123,
Expand Down Expand Up @@ -486,13 +517,13 @@ func TestSlowQueryParametersDisabled(t *testing.T) {
TxnName: "WebTransaction/Go/myName",
TxnURL: "/hello",
DatabaseName: "",
Host: "unknown",
PortPathOrID: "unknown",
Host: "",
PortPathOrID: "",
Params: nil,
}})
}

func TestSlowQueryInstanceDisabledUnknown(t *testing.T) {
func TestSlowQueryInstanceDisabled(t *testing.T) {
cfgfn := func(cfg *Config) {
cfg.DatastoreTracer.SlowQuery.Threshold = 0
cfg.DatastoreTracer.InstanceReporting.Enabled = false
Expand All @@ -505,6 +536,7 @@ func TestSlowQueryInstanceDisabledUnknown(t *testing.T) {
Collection: "users",
Operation: "INSERT",
ParameterizedQuery: "INSERT INTO users (name, age) VALUES ($1, $2)",
Host: "db-server-1",
}
s1.End()
txn.End()
Expand Down Expand Up @@ -607,7 +639,7 @@ func TestSlowQueryDatabaseNameDisabled(t *testing.T) {
TxnName: "WebTransaction/Go/myName",
TxnURL: "/hello",
DatabaseName: "",
Host: "unknown",
PortPathOrID: "unknown",
Host: "",
PortPathOrID: "",
}})
}
3 changes: 0 additions & 3 deletions internal_test.go
Expand Up @@ -1108,7 +1108,6 @@ func TestTraceDatastore(t *testing.T) {
{"Datastore/operation/MySQL/SELECT", "", false, nil},
{"Datastore/statement/MySQL/my_table/SELECT", "", false, nil},
{"Datastore/statement/MySQL/my_table/SELECT", "WebTransaction/Go/myName", false, nil},
{"Datastore/instance/MySQL/unknown/unknown", "", false, nil},
})
app.ExpectErrorEvents(t, []internal.WantErrorEvent{{
TxnName: "WebTransaction/Go/myName",
Expand Down Expand Up @@ -1149,7 +1148,6 @@ func TestTraceDatastoreBackground(t *testing.T) {
{"Datastore/operation/MySQL/SELECT", "", false, nil},
{"Datastore/statement/MySQL/my_table/SELECT", "", false, nil},
{"Datastore/statement/MySQL/my_table/SELECT", "OtherTransaction/Go/myName", false, nil},
{"Datastore/instance/MySQL/unknown/unknown", "", false, nil},
})
app.ExpectErrorEvents(t, []internal.WantErrorEvent{{
TxnName: "OtherTransaction/Go/myName",
Expand Down Expand Up @@ -1189,7 +1187,6 @@ func TestTraceDatastoreMissingProductOperationCollection(t *testing.T) {
{"Datastore/Unknown/allWeb", "", true, nil},
{"Datastore/operation/Unknown/other", "", false, nil},
{"Datastore/operation/Unknown/other", "WebTransaction/Go/myName", false, nil},
{"Datastore/instance/Unknown/unknown/unknown", "", false, nil},
})
app.ExpectErrorEvents(t, []internal.WantErrorEvent{{
TxnName: "WebTransaction/Go/myName",
Expand Down
5 changes: 4 additions & 1 deletion internal_txn.go
Expand Up @@ -68,7 +68,6 @@ func newTxn(input txnInput, name string) *txn {
txn.tracer.StackTraceThreshold = txn.Config.TransactionTracer.StackTraceThreshold
txn.tracer.SlowQueriesEnabled = txn.slowQueriesEnabled()
txn.tracer.SlowQueryThreshold = txn.Config.DatastoreTracer.SlowQuery.Threshold
txn.tracer.InstanceReportingDisabled = !txn.Config.DatastoreTracer.InstanceReporting.Enabled

return txn
}
Expand Down Expand Up @@ -444,6 +443,10 @@ func endDatastore(s DatastoreSegment) {
if !txn.Config.DatastoreTracer.DatabaseNameReporting.Enabled {
s.DatabaseName = ""
}
if !txn.Config.DatastoreTracer.InstanceReporting.Enabled {
s.Host = ""
s.PortPathOrID = ""
}
internal.EndDatastoreSegment(internal.EndDatastoreParams{
Tracer: &txn.tracer,
Start: s.StartTime.start,
Expand Down

0 comments on commit 1c3938b

Please sign in to comment.