Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

systemtest: compare fields instead of _source in approvals #12098

Merged
merged 4 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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