Skip to content

Commit

Permalink
systemtest: compare fields instead of _source in approvals (#12098)
Browse files Browse the repository at this point in the history
* go.mod: update apm-tools

Update apm-tools to bring in the newer version of opentelemetry-go,
which affects approvals.

* Fix flaky test

(Unrelated to other changes.)

* Mechanically flatten approvals

find -name '*.approved.json' -exec go run path/to/apm-tools/cmd/flatten-approvals -i {} \;

* systemtest: approve fields instead of _source
  • Loading branch information
axw authored Nov 28, 2023
1 parent 46c0967 commit 2e1d98f
Show file tree
Hide file tree
Showing 61 changed files with 19,347 additions and 14,007 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
122 changes: 72 additions & 50 deletions systemtest/approvals/TestAgentConfig.approved.json
Original file line number Diff line number Diff line change
@@ -1,50 +1,72 @@
{
"events": [
{
"@timestamp": "dynamic",
"agent_config_applied": 1,
"data_stream": {
"dataset": "apm.internal",
"namespace": "default",
"type": "metrics"
},
"labels": {
"etag": "dynamic"
},
"metricset": {
"name": "agent_config"
},
"observer": {
"hostname": "dynamic",
"type": "apm-server",
"version": "dynamic"
},
"processor": {
"event": "metric"
}
},
{
"@timestamp": "dynamic",
"agent_config_applied": 1,
"data_stream": {
"dataset": "apm.internal",
"namespace": "default",
"type": "metrics"
},
"labels": {
"etag": "dynamic"
},
"metricset": {
"name": "agent_config"
},
"observer": {
"hostname": "dynamic",
"type": "apm-server",
"version": "dynamic"
},
"processor": {
"event": "metric"
}
}
]
}
[
{
"@timestamp": [
"dynamic"
],
"agent_config_applied": [
1
],
"data_stream.dataset": [
"apm.internal"
],
"data_stream.namespace": [
"default"
],
"data_stream.type": [
"metrics"
],
"labels.etag": [
"dynamic"
],
"metricset.name": [
"agent_config"
],
"observer.hostname": [
"dynamic"
],
"observer.type": [
"apm-server"
],
"observer.version": [
"dynamic"
],
"processor.event": [
"metric"
]
},
{
"@timestamp": [
"dynamic"
],
"agent_config_applied": [
1
],
"data_stream.dataset": [
"apm.internal"
],
"data_stream.namespace": [
"default"
],
"data_stream.type": [
"metrics"
],
"labels.etag": [
"dynamic"
],
"metricset.name": [
"agent_config"
],
"observer.hostname": [
"dynamic"
],
"observer.type": [
"apm-server"
],
"observer.version": [
"dynamic"
],
"processor.event": [
"metric"
]
}
]
Loading

0 comments on commit 2e1d98f

Please sign in to comment.