Skip to content

Commit

Permalink
systemtest: approve fields instead of _source
Browse files Browse the repository at this point in the history
  • Loading branch information
axw committed Nov 24, 2023
1 parent 5018b52 commit 5b22d96
Show file tree
Hide file tree
Showing 50 changed files with 2,496 additions and 1,871 deletions.
2 changes: 1 addition & 1 deletion systemtest/agentconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func TestAgentConfig(t *testing.T) {
require.Len(t, result.Hits.Hits, 2)
etag := gjson.GetBytes(result.Hits.Hits[0].RawSource, "labels.etag")
assert.Equal(t, etag1, strconv.Quote(etag.String()))
approvaltest.ApproveEvents(t, t.Name(), result.Hits.Hits, "@timestamp", "labels.etag")
approvaltest.ApproveFields(t, t.Name(), result.Hits.Hits, "@timestamp", "labels.etag")
}

func queryAgentConfig(t testing.TB, serverURL, serviceName, serviceEnvironment, etag string) (map[string]string, *http.Response, map[string]interface{}) {
Expand Down
30 changes: 24 additions & 6 deletions systemtest/aggregation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func TestTransactionAggregation(t *testing.T) {
result := estest.ExpectMinDocs(t, systemtest.Elasticsearch, 9, "metrics-apm.transaction*",
espoll.ExistsQuery{Field: "transaction.duration.histogram"},
)
approvaltest.ApproveEvents(t, t.Name(), result.Hits.Hits)
approvaltest.ApproveFields(t, t.Name(), result.Hits.Hits)

// Make sure the _doc_count field is added such that aggregations return
// the appropriate per-bucket doc_count values.
Expand Down Expand Up @@ -140,7 +140,7 @@ func TestTransactionAggregationShutdown(t *testing.T) {
result := estest.ExpectMinDocs(t, systemtest.Elasticsearch, 3, "metrics-apm.transaction*",
espoll.ExistsQuery{Field: "transaction.duration.histogram"},
)
approvaltest.ApproveEvents(t, t.Name(), result.Hits.Hits)
approvaltest.ApproveFields(t, t.Name(), result.Hits.Hits)
}

func TestServiceDestinationAggregation(t *testing.T) {
Expand Down Expand Up @@ -176,7 +176,16 @@ func TestServiceDestinationAggregation(t *testing.T) {
result := estest.ExpectDocs(t, systemtest.Elasticsearch, "metrics-apm.service_destination*",
espoll.ExistsQuery{Field: "span.destination.service.response_time.count"},
)
approvaltest.ApproveEvents(t, t.Name(), result.Hits.Hits)
approvaltest.ApproveFields(t, t.Name(), result.Hits.Hits)

// _doc_count is not returned in fields, it is only visible in _source and
// in the results of aggregations.
//
// TODO(axw) we should use an aggregation, and check the resturned doc_counts.
for _, hit := range result.Hits.Hits {
docCount := hit.Source["_doc_count"].(float64)
assert.Equal(t, 5.0, docCount)
}
}

func TestTransactionAggregationLabels(t *testing.T) {
Expand Down Expand Up @@ -252,7 +261,16 @@ func TestServiceTransactionMetricsAggregation(t *testing.T) {
result := estest.ExpectMinDocs(t, systemtest.Elasticsearch, 2, "metrics-apm.service_transaction*",
espoll.TermQuery{Field: "metricset.name", Value: "service_transaction"},
)
approvaltest.ApproveEvents(t, t.Name(), result.Hits.Hits)
approvaltest.ApproveFields(t, t.Name(), result.Hits.Hits)

// _doc_count is not returned in fields, it is only visible in _source and
// in the results of aggregations.
//
// TODO(axw) we should use an aggregation, and check the resturned doc_counts.
for _, hit := range result.Hits.Hits {
docCount := hit.Source["_doc_count"].(float64)
assert.Equal(t, 2.0, docCount)
}
}

func TestServiceTransactionMetricsAggregationLabels(t *testing.T) {
Expand Down Expand Up @@ -371,7 +389,7 @@ func TestServiceSummaryMetricsAggregation(t *testing.T) {
result := estest.ExpectDocs(t, systemtest.Elasticsearch, "metrics-apm.service_summary*",
espoll.TermQuery{Field: "metricset.name", Value: "service_summary"},
)
approvaltest.ApproveEvents(t, t.Name(), result.Hits.Hits)
approvaltest.ApproveFields(t, t.Name(), result.Hits.Hits)
}

func TestServiceSummaryMetricsAggregationOverflow(t *testing.T) {
Expand Down Expand Up @@ -416,7 +434,7 @@ func TestServiceSummaryMetricsAggregationOverflow(t *testing.T) {
espoll.TermQuery{Field: "metricset.name", Value: "service_summary"},
)
// Ignore timestamp because overflow bucket uses time.Now()
approvaltest.ApproveEvents(t, t.Name(), result.Hits.Hits, "@timestamp")
approvaltest.ApproveFields(t, t.Name(), result.Hits.Hits, "@timestamp")
}

func TestNonDefaultRollupIntervalHiddenDataStream(t *testing.T) {
Expand Down
40 changes: 31 additions & 9 deletions systemtest/approvals/TestApprovedMetrics.approved.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@
],
"user.name": [
"logged-in-user"
],
"user.name.text": [
"logged-in-user"
]
},
{
Expand Down Expand Up @@ -142,6 +145,9 @@
],
"user.name": [
"logged-in-user"
],
"user.name.text": [
"logged-in-user"
]
},
{
Expand Down Expand Up @@ -234,6 +240,9 @@
],
"user.name": [
"logged-in-user"
],
"user.name.text": [
"logged-in-user"
]
},
{
Expand Down Expand Up @@ -264,15 +273,19 @@
"labels.tag1": [
"one"
],
"latency_distribution.counts": [
1,
2,
3
],
"latency_distribution.values": [
1.1,
2.2,
3.3
"latency_distribution": [
{
"counts": [
1,
2,
3
],
"values": [
1.1,
2.2,
3.3
]
}
],
"metricset.name": [
"app"
Expand Down Expand Up @@ -312,6 +325,9 @@
],
"user.name": [
"logged-in-user"
],
"user.name.text": [
"logged-in-user"
]
},
{
Expand Down Expand Up @@ -407,6 +423,9 @@
],
"user.name": [
"logged-in-user"
],
"user.name.text": [
"logged-in-user"
]
},
{
Expand Down Expand Up @@ -502,6 +521,9 @@
],
"user.name": [
"logged-in-user"
],
"user.name.text": [
"logged-in-user"
]
}
]
6 changes: 6 additions & 0 deletions systemtest/approvals/TestCompressedSpans.approved.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
"process.title": [
"systemtest.test"
],
"process.title.text": [
"systemtest.test"
],
"processor.event": [
"span"
],
Expand Down Expand Up @@ -179,6 +182,9 @@
"process.title": [
"systemtest.test"
],
"process.title.text": [
"systemtest.test"
],
"processor.event": [
"span"
],
Expand Down
9 changes: 9 additions & 0 deletions systemtest/approvals/TestDropUnsampled.approved.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
"process.title": [
"systemtest.test"
],
"process.title.text": [
"systemtest.test"
],
"processor.event": [
"transaction"
],
Expand Down Expand Up @@ -90,6 +93,9 @@
"transaction.name": [
"sampled"
],
"transaction.name.text": [
"sampled"
],
"transaction.representative_count": [
1
],
Expand Down Expand Up @@ -185,6 +191,9 @@
"user_agent.original": [
"Go-http-client/1.1"
],
"user_agent.original.text": [
"Go-http-client/1.1"
],
"user_agent.version": [
"1.1"
]
Expand Down
9 changes: 9 additions & 0 deletions systemtest/approvals/TestErrorIngest.approved.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@
"process.title": [
"node"
],
"process.title.text": [
"node"
],
"processor.event": [
"error"
],
"service.environment": [
"staging"
],
Expand Down Expand Up @@ -192,6 +198,9 @@
],
"user.name": [
"bar"
],
"user.name.text": [
"bar"
]
}
]
Loading

0 comments on commit 5b22d96

Please sign in to comment.