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

Introduce approvaltest module #4112

Merged
merged 3 commits into from
Aug 31, 2020
Merged

Introduce approvaltest module #4112

merged 3 commits into from
Aug 31, 2020

Conversation

axw
Copy link
Member

@axw axw commented Aug 29, 2020

Motivation/summary

Move tests/approvals and tests/scripts/approvals.go into a new module,
github.com/elastic/apm-server/approvaltest. This new module will be used
by both apm-server (in integration tests) and the systemtest module,
enabling us to have those two modules not import from one another.

We also reduce the approvals API surface area to two functions: ApproveJSON,
and ApproveEventDocs. The ApproveJSON function can be used for approving
arbitrary JSON-encoded values, while ApproveEventDocs is specifically intended
for approving JSON-encoded Elasticsearch event documents.

To enable the API reduction, we introduce beatertest.EncodeEventDoc(s), which
encode events using the libbeat Elasticsearch output. In some tests we previously
used the libbeat JSON codec directly, which led to @metadata being included in
diffs. The output removes @metadata, hence it no longer features in our approval
diffs.

For dynamic fields like profile.id, we now replace the value with a known string
("dynamic") rather than ignoring the field completely. This minimises the diffs of
.approved.json files, and also allows us to detect added/removed fields.

Checklist

I have considered changes for:
- [ ] documentation
- [ ] logging (add log lines, choose appropriate log selector, etc.)
- [ ] metrics and monitoring (create issue for Kibana team to add metrics to visualizations, e.g. Kibana#44001)

How to test these changes

make test

Related issues

See #4084 (comment)

@apmmachine
Copy link
Contributor

apmmachine commented Aug 29, 2020

💔 Tests Failed

Pipeline View Test View Changes Artifacts preview

Expand to view the summary

Build stats

  • Build Cause: [Branch indexing]

  • Start Time: 2020-08-31T02:50:10.053+0000

  • Duration: 45 min 43 sec

Test stats 🧪

Test Results
Failed 2
Passed 2864
Skipped 139
Total 3005

Test errors

Expand to view the tests failures

  • Name: Build and Test / OSX build-test / TestAggregatorRun – spanmetrics

    • Age: 1
    • Duration: 0.13
    • Error Details: Failed
  • Name: Build and Test / Unit Test / TestAggregatorRun – spanmetrics

    • Age: 1
    • Duration: 0.12
    • Error Details: Failed

Steps errors

Expand to view the steps failures

  • Name: Compress

    • Description: tar --exclude=coverage-files.tgz -czf coverage-files.tgz coverage

    • Duration: 0 min 0 sec

    • Start Time: 2020-08-31T03:05:21.078+0000

    • log

  • Name: Run Linux tests

    • Description: ./script/jenkins/linux-test.sh

    • Duration: 2 min 53 sec

    • Start Time: 2020-08-31T02:59:57.897+0000

    • log

  • Name: Compress

    • Description: tar --exclude=system-tests-linux-files.tgz -czf system-tests-linux-files.tgz system-tests

    • Duration: 0 min 0 sec

    • Start Time: 2020-08-31T03:01:52.868+0000

    • log

  • Name: Test Sync

    • Description: ./script/jenkins/sync.sh

    • Duration: 3 min 46 sec

    • Start Time: 2020-08-31T03:00:05.685+0000

    • log

Log output

Expand to view the last 100 lines of log output

[2020-08-31T03:23:46.779Z] >> package: Building apm-server type=deb for platform=linux/arm64
[2020-08-31T03:23:56.814Z] Doing `require 'backports'` is deprecated and will not load any backport in the next major release.
[2020-08-31T03:23:56.815Z] Require just the needed backports instead, or 'backports/latest'.
[2020-08-31T03:24:06.847Z] >> package: Building apm-server-oss type=tar.gz for platform=linux/arm64
[2020-08-31T03:24:07.811Z] >> package: Building apm-server-oss type=deb for platform=linux/arm64
[2020-08-31T03:24:13.120Z] >> package: Building apm-server type=zip for platform=windows/386
[2020-08-31T03:24:16.439Z] Doing `require 'backports'` is deprecated and will not load any backport in the next major release.
[2020-08-31T03:24:16.439Z] Require just the needed backports instead, or 'backports/latest'.
[2020-08-31T03:24:16.439Z] >> package: Building apm-server-oss type=zip for platform=windows/386
[2020-08-31T03:24:20.658Z] >> package: Building apm-server-oss type=zip for platform=windows/amd64
[2020-08-31T03:24:35.586Z] >> Testing package contents
[2020-08-31T03:25:02.181Z] package ran for 21m35.07800948s
[2020-08-31T03:25:02.479Z] + ./script/jenkins/test-install-packages.sh
[2020-08-31T03:25:02.479Z] + export MAGEFILE_VERBOSE=1
[2020-08-31T03:25:02.479Z] + MAGEFILE_VERBOSE=1
[2020-08-31T03:25:02.479Z] + ./build/linux/mage -v testPackagesInstall
[2020-08-31T03:25:02.479Z] 2020/08/31 03:25:02 exec: go list -m
[2020-08-31T03:25:02.742Z] Running target: TestPackagesInstall
[2020-08-31T03:25:02.742Z] exec: go test -v tests/packaging/package_test.go -timeout 20m -files /var/lib/jenkins/workspace/pm-server_apm-server-mbp_PR-4112/src/github.com/elastic/apm-server/build/distributions/* -tags=package
[2020-08-31T03:29:54.718Z] [INFO] getVaultSecret: Getting secrets
[2020-08-31T03:29:54.834Z] Masking supported pattern matches of $VAULT_ADDR or $VAULT_ROLE_ID or $VAULT_SECRET_ID
[2020-08-31T03:29:55.817Z] + set +x
[2020-08-31T03:29:56.398Z] Login Succeeded
[2020-08-31T03:29:56.855Z] + ./script/jenkins/package-docker-snapshot.sh 4e80b8aadf926f007163a4189fe41434fbd54628 docker.elastic.co/observability-ci/apm-server
[2020-08-31T03:29:56.855Z] INFO: Build docker images
[2020-08-31T03:29:57.118Z] ./build/linux/mage package
[2020-08-31T03:29:57.118Z] 2020/08/31 03:29:57 exec: go list -m
[2020-08-31T03:29:57.694Z] >> Building apm-server.yml for linux/amd64
[2020-08-31T03:29:57.694Z] >> Building apm-server.docker.yml for linux/amd64
[2020-08-31T03:29:58.268Z] Generated fields.yml for apm-server to /var/lib/jenkins/workspace/pm-server_apm-server-mbp_PR-4112/src/github.com/elastic/apm-server/build/fields/fields.yml
[2020-08-31T03:29:59.654Z] Generated fields.yml for apm-server to /var/lib/jenkins/workspace/pm-server_apm-server-mbp_PR-4112/src/github.com/elastic/apm-server/build/fields/fields.all.yml
[2020-08-31T03:30:03.859Z] >> buildGoDaemon: Building for linux/amd64
[2020-08-31T03:30:03.859Z] >> golangCrossBuild: Building for linux/amd64
[2020-08-31T03:30:03.859Z] >> golangCrossBuild: Building for linux/amd64
[2020-08-31T03:30:04.436Z] >> Building using: cmd='../../build/mage-linux-amd64 golangCrossBuild', env=[CC=gcc, CXX=g++, GOARCH=amd64, GOARM=, GOOS=linux, PLATFORM_ID=linux-amd64]
[2020-08-31T03:30:04.436Z] 2020/08/31 03:30:04 exec: go list -m
[2020-08-31T03:30:04.436Z] >> Building using: cmd='build/mage-linux-amd64 buildGoDaemon', env=[CC=gcc, CXX=g++, GOARCH=amd64, GOARM=, GOOS=linux, PLATFORM_ID=linux-amd64]
[2020-08-31T03:30:04.698Z] 2020/08/31 03:30:04 exec: go list -m
[2020-08-31T03:30:04.698Z] >> Building using: cmd='build/mage-linux-amd64 golangCrossBuild', env=[CC=gcc, CXX=g++, GOARCH=amd64, GOARM=, GOOS=linux, PLATFORM_ID=linux-amd64]
[2020-08-31T03:30:04.698Z] 2020/08/31 03:30:04 exec: go list -m
[2020-08-31T03:32:56.296Z] >> package: Building apm-server type=docker for platform=linux/amd64
[2020-08-31T03:32:56.296Z] >> package: Building apm-server-oss type=docker for platform=linux/amd64
[2020-08-31T03:32:56.296Z] >> package: Building apm-server-oss type=deb for platform=linux/amd64
[2020-08-31T03:32:56.296Z] >> package: Building apm-server-oss type=tar.gz for platform=linux/amd64
[2020-08-31T03:32:56.296Z] >> package: Building apm-server type=deb for platform=linux/amd64
[2020-08-31T03:32:58.878Z] Doing `require 'backports'` is deprecated and will not load any backport in the next major release.
[2020-08-31T03:32:58.878Z] Require just the needed backports instead, or 'backports/latest'.
[2020-08-31T03:33:08.907Z] Doing `require 'backports'` is deprecated and will not load any backport in the next major release.
[2020-08-31T03:33:08.908Z] Require just the needed backports instead, or 'backports/latest'.
[2020-08-31T03:33:08.908Z] >> package: Building apm-server type=tar.gz for platform=linux/amd64
[2020-08-31T03:33:19.014Z] >> package: Building apm-server type=rpm for platform=linux/amd64
[2020-08-31T03:33:20.929Z] >> package: Building apm-server-oss type=rpm for platform=linux/amd64
[2020-08-31T03:33:27.522Z] Doing `require 'backports'` is deprecated and will not load any backport in the next major release.
[2020-08-31T03:33:27.522Z] Require just the needed backports instead, or 'backports/latest'.
[2020-08-31T03:33:30.834Z] Doing `require 'backports'` is deprecated and will not load any backport in the next major release.
[2020-08-31T03:33:30.834Z] Require just the needed backports instead, or 'backports/latest'.
[2020-08-31T03:33:40.836Z] >> package: Building apm-server type=docker for platform=linux/amd64
[2020-08-31T03:34:19.640Z] >> Testing package contents
[2020-08-31T03:34:37.744Z] package ran for 4m39.773416165s
[2020-08-31T03:34:37.744Z] INFO: Get the just built docker image
[2020-08-31T03:34:37.744Z] INFO: Retag docker image (docker.elastic.co/apm/apm-server:8.0.0-SNAPSHOT)
[2020-08-31T03:34:37.744Z] INFO: Push docker image (docker.elastic.co/observability-ci/apm-server:4e80b8aadf926f007163a4189fe41434fbd54628)
[2020-08-31T03:34:37.744Z] The push refers to repository [docker.elastic.co/observability-ci/apm-server]
[2020-08-31T03:34:37.744Z] 020d14d87132: Preparing
[2020-08-31T03:34:37.744Z] a6764a6966d1: Preparing
[2020-08-31T03:34:37.744Z] 41b58183759d: Preparing
[2020-08-31T03:34:37.744Z] 0ed6c9cfd314: Preparing
[2020-08-31T03:34:37.744Z] e2c9995e6ea8: Preparing
[2020-08-31T03:34:37.744Z] 31f32e3c750b: Preparing
[2020-08-31T03:34:37.744Z] 525953051937: Preparing
[2020-08-31T03:34:37.744Z] aeecf411116c: Preparing
[2020-08-31T03:34:37.744Z] 8f93f760de1e: Preparing
[2020-08-31T03:34:37.744Z] 613be09ab3c0: Preparing
[2020-08-31T03:34:37.744Z] 31f32e3c750b: Waiting
[2020-08-31T03:34:37.744Z] 525953051937: Waiting
[2020-08-31T03:34:37.744Z] aeecf411116c: Waiting
[2020-08-31T03:34:37.744Z] 8f93f760de1e: Waiting
[2020-08-31T03:34:37.744Z] 613be09ab3c0: Waiting
[2020-08-31T03:34:39.652Z] 0ed6c9cfd314: Pushed
[2020-08-31T03:34:39.652Z] 020d14d87132: Pushed
[2020-08-31T03:34:39.652Z] e2c9995e6ea8: Pushed
[2020-08-31T03:34:39.652Z] a6764a6966d1: Pushed
[2020-08-31T03:34:39.652Z] 41b58183759d: Pushed
[2020-08-31T03:34:39.652Z] 613be09ab3c0: Layer already exists
[2020-08-31T03:34:41.033Z] 525953051937: Pushed
[2020-08-31T03:34:41.033Z] aeecf411116c: Pushed
[2020-08-31T03:34:42.416Z] 8f93f760de1e: Pushed
[2020-08-31T03:34:47.697Z] 31f32e3c750b: Pushed
[2020-08-31T03:34:49.604Z] 4e80b8aadf926f007163a4189fe41434fbd54628: digest: sha256:ac829f045381f1c74d3a10228fac7b5684f0b75ac286dd175dae2eb2c3ef41f1 size: 2405
[2020-08-31T03:34:49.654Z] $ docker stop --time=1 911d42f9a907b9487a8e1788e302444b54741013e8157f4c091d8d8013635aec
[2020-08-31T03:34:51.011Z] $ docker rm -f 911d42f9a907b9487a8e1788e302444b54741013e8157f4c091d8d8013635aec
[2020-08-31T03:34:52.138Z] Stage "Publish" skipped due to when conditional
[2020-08-31T03:34:52.567Z] Running on Jenkins in /var/lib/jenkins/workspace/pm-server_apm-server-mbp_PR-4112
[2020-08-31T03:34:52.630Z] [INFO] getVaultSecret: Getting secrets
[2020-08-31T03:34:52.718Z] Masking supported pattern matches of $VAULT_ADDR or $VAULT_ROLE_ID or $VAULT_SECRET_ID
[2020-08-31T03:34:53.486Z] + chmod 755 generate-build-data.sh
[2020-08-31T03:34:53.487Z] + ./generate-build-data.sh https://apm-ci.elastic.co/blue/rest/organizations/jenkins/pipelines/apm-server/apm-server-mbp/PR-4112/ https://apm-ci.elastic.co/blue/rest/organizations/jenkins/pipelines/apm-server/apm-server-mbp/PR-4112/runs/5 FAILURE 2683172
[2020-08-31T03:34:54.038Z] INFO: curl https://apm-ci.elastic.co/blue/rest/organizations/jenkins/pipelines/apm-server/apm-server-mbp/PR-4112/runs/5/steps/?limit=10000 -o steps-info.json
[2020-08-31T03:34:54.588Z] INFO: curl https://apm-ci.elastic.co/blue/rest/organizations/jenkins/pipelines/apm-server/apm-server-mbp/PR-4112/runs/5/tests/?status=FAILED -o tests-errors.json
[2020-08-31T03:34:55.139Z] INFO: curl https://apm-ci.elastic.co/blue/rest/organizations/jenkins/pipelines/apm-server/apm-server-mbp/PR-4112/runs/5/log/ -o pipeline-log.txt

@axw axw changed the title approvaltest: Introduce approvaltest module Aug 29, 2020
@axw axw force-pushed the approvaltest branch 2 times, most recently from 22fdef6 to 875f630 Compare August 29, 2020 04:51
We move tests/approvals and tests/scripts/approvals.go intoa new module,
github.com/elastic/apm-server/approvaltest. This new module will be used
by both apm-server (integration tests) and the systemtest module.

We also reduce the API surface area to two functions: ApproveJSON, and
ApproveEventDocs. The ApproveJSON function can be used for approving
arbitrary JSON-encoded values, while ApproveEventDocs is specifically
intended for approving JSON-encoded Elasticsearch event documents.

To enable the API reduction, we introduce beatertest.EncodeEventDoc(s),
which encode events using the libbeat Elasticsearch output. In some
tests we previously used the libbeat JSON codec directly, which led to
@metadata being included in diffs. The output removes @metadata, hence
it no longer features in our approval diffs.
- Since we now use the Elasticsearch output, rather than directly
  using the libbeat JSON codec, `@metadata` is no longer part of the
  diff, and `@timestamp` is encoded slightly differently.

- For dynamic fields like `profile.id`, we now replace the value
  with a known string ("dynamic") rather than ignoring the field.
@axw axw marked this pull request as ready for review August 30, 2020 03:03
@axw axw requested a review from simitt August 30, 2020 03:04
Copy link
Contributor

@simitt simitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thank you for pulling out in a dedicated module.

I can confirm that the bug, that led to not removing .received files, is also fixed with these improvements.

@axw axw merged commit ac65b7b into elastic:master Aug 31, 2020
@axw axw deleted the approvaltest branch August 31, 2020 07:22
jalvz pushed a commit to jalvz/apm-server that referenced this pull request Sep 4, 2020
* Introduce new approvaltest module

We move tests/approvals and tests/scripts/approvals.go intoa new module,
github.com/elastic/apm-server/approvaltest. This new module will be used
by both apm-server (integration tests) and the systemtest module.

We also reduce the API surface area to two functions: ApproveJSON, and
ApproveEventDocs. The ApproveJSON function can be used for approving
arbitrary JSON-encoded values, while ApproveEventDocs is specifically
intended for approving JSON-encoded Elasticsearch event documents.

To enable the API reduction, we introduce beatertest.EncodeEventDoc(s),
which encode events using the libbeat Elasticsearch output. In some
tests we previously used the libbeat JSON codec directly, which led to
@metadata being included in diffs. The output removes @metadata, hence
it no longer features in our approval diffs.

* Update approved files

- Since we now use the Elasticsearch output, rather than directly
  using the libbeat JSON codec, `@metadata` is no longer part of the
  diff, and `@timestamp` is encoded slightly differently.

- For dynamic fields like `profile.id`, we now replace the value
  with a known string ("dynamic") rather than ignoring the field.

* .ci/docker/golang-mage: support multiple modules
axw added a commit to axw/apm-server that referenced this pull request Sep 7, 2020
* Introduce new approvaltest module

We move tests/approvals and tests/scripts/approvals.go intoa new module,
github.com/elastic/apm-server/approvaltest. This new module will be used
by both apm-server (integration tests) and the systemtest module.

We also reduce the API surface area to two functions: ApproveJSON, and
ApproveEventDocs. The ApproveJSON function can be used for approving
arbitrary JSON-encoded values, while ApproveEventDocs is specifically
intended for approving JSON-encoded Elasticsearch event documents.

To enable the API reduction, we introduce beatertest.EncodeEventDoc(s),
which encode events using the libbeat Elasticsearch output. In some
tests we previously used the libbeat JSON codec directly, which led to
@metadata being included in diffs. The output removes @metadata, hence
it no longer features in our approval diffs.

* Update approved files

- Since we now use the Elasticsearch output, rather than directly
  using the libbeat JSON codec, `@metadata` is no longer part of the
  diff, and `@timestamp` is encoded slightly differently.

- For dynamic fields like `profile.id`, we now replace the value
  with a known string ("dynamic") rather than ignoring the field.

* .ci/docker/golang-mage: support multiple modules
axw added a commit that referenced this pull request Sep 8, 2020
* Introduce approvaltest module (#4112)

* Introduce new approvaltest module

We move tests/approvals and tests/scripts/approvals.go intoa new module,
github.com/elastic/apm-server/approvaltest. This new module will be used
by both apm-server (integration tests) and the systemtest module.

We also reduce the API surface area to two functions: ApproveJSON, and
ApproveEventDocs. The ApproveJSON function can be used for approving
arbitrary JSON-encoded values, while ApproveEventDocs is specifically
intended for approving JSON-encoded Elasticsearch event documents.

To enable the API reduction, we introduce beatertest.EncodeEventDoc(s),
which encode events using the libbeat Elasticsearch output. In some
tests we previously used the libbeat JSON codec directly, which led to
@metadata being included in diffs. The output removes @metadata, hence
it no longer features in our approval diffs.

* Update approved files

- Since we now use the Elasticsearch output, rather than directly
  using the libbeat JSON codec, `@metadata` is no longer part of the
  diff, and `@timestamp` is encoded slightly differently.

- For dynamic fields like `profile.id`, we now replace the value
  with a known string ("dynamic") rather than ignoring the field.

* .ci/docker/golang-mage: support multiple modules

* tests: fix docker-system-tests (#4123)

Copy in approvaltest/go.mod (and systemtest/go.mod for good measure)
to fix `go mod download` at the top level. Also run `go mod download`
for the sub-modules, to speed up repeat runs of docker-system-tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants