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

feat: support @elastic/elasticsearch@8 #2385

Merged
merged 15 commits into from
Oct 25, 2021
Merged

feat: support @elastic/elasticsearch@8 #2385

merged 15 commits into from
Oct 25, 2021

Conversation

trentm
Copy link
Member

@trentm trentm commented Oct 22, 2021

This adds support for the still pre-release version 8.x of the ES client. We are testing canary releases via the @elastic/elasticsearch-canary package. Kibana v8 is working to use v8 of the ES client and part of that is the self-APM integration in Kibana supporting instrumenting it.

Fixes: #2355

Checklist

  • Implement code
  • Add tests
  • Update documentation
  • Add CHANGELOG.asciidoc entry
  • Commit message follows commit guidelines

This is a first incomplete crack at it. TAV is probably wrong. There
are some XXXs to complete in the tests for a change in the 'request'
diagnostic data.
@trentm trentm self-assigned this Oct 22, 2021
@github-actions github-actions bot added the agent-nodejs Make available for APM Agents project planning. label Oct 22, 2021
@apmmachine
Copy link
Contributor

apmmachine commented Oct 22, 2021

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2021-10-25T18:48:19.053+0000

  • Duration: 20 min 24 sec

  • Commit: ecbb6a1

Test stats 🧪

Test Results
Failed 0
Passed 22
Skipped 0
Total 22

🤖 GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

  • run module tests for <modules> : Run TAV tests for one or more modules, where <modules> can be either a comma separated list of modules (e.g. memcached,redis) or the string literal ALL to test all modules

  • run benchmark tests : Run the benchmark test only.

@trentm
Copy link
Member Author

trentm commented Oct 25, 2021

Local TAV test run pass FWIW:

[18:01:49 trentm@pink:~/el/apm-agent-nodejs5 (n:16 git:trentm/esclient8)]
% TAV=@elastic/elasticsearch-canary npm run test:tav

> [email protected] test:tav
> tav --quiet

-- required packages ["@elastic/[email protected]"]
-- installing ["@elastic/[email protected]"]
-- running test "node test/instrumentation/modules/@elastic/elasticsearch.test.js" with @elastic/elasticsearch-canary
-- required packages ["@elastic/[email protected]"]
-- installing ["@elastic/[email protected]"]
-- running test "node test/instrumentation/modules/@elastic/elasticsearch.test.js" with @elastic/elasticsearch-canary
-- required packages ["@elastic/[email protected]"]
-- installing ["@elastic/[email protected]"]
-- running test "node test/instrumentation/modules/@elastic/elasticsearch.test.js" with @elastic/elasticsearch-canary
-- required packages ["@elastic/[email protected]"]
-- installing ["@elastic/[email protected]"]
-- running test "node test/instrumentation/modules/@elastic/elasticsearch.test.js" with @elastic/elasticsearch-canary
-- ok

@trentm
Copy link
Member Author

trentm commented Oct 25, 2021

See also #2389 and #2388 for follow up work.

@trentm trentm marked this pull request as ready for review October 25, 2021 02:44
@trentm trentm requested a review from astorm October 25, 2021 02:44
    running (cwd: ./): node --unhandled-rejections=strict test/instrumentation/modules/@elastic/elasticsearch-canary.test.js
    TAP version 13
    # client.ping with promise
    not ok 1 ProductNotSupportedError: The client noticed that the server is not Elasticsearch and we do not support this unknown product.
      ---
        operator: error
        stack: |-
          ProductNotSupportedError: The client noticed that the server is not Elasticsearch and we do not support this unknown product.
              at SniffingTransport.request (/home/runner/work/apm-agent-nodejs/apm-agent-nodejs/node_modules/@elastic/transport/lib/Transport.js:405:27)
              at processTicksAndRejections (internal/process/task_queues.js:97:5)
              at async ApmClient.PingApi [as ping] (/home/runner/work/apm-agent-nodejs/apm-agent-nodejs/node_modules/@elastic/elasticsearch-canary/lib/api/api/ping.js:37:12)
…differ enough, esp. while v8 is still pre-release
I believe this is (a) safer and (b) doesn't lose any functionality.

"Safer" because, a recent change in elastic/elasticsearch-js to the
types for this "body" field on the "request" diagnostic event shows
these possible types for version 8 of the ES client:
     body?: string | Buffer | ReadableStream | null
That "body" can be a Buffer or a ReadableStream. JSON.stringify-ing
those for span.context.db.statement could possibly result in a HUGE
object. This isn't the intent.

No loss in functionality because we have tests for most of the ES
queries that we support:
  const pathIsAQuery = /\/(_search|_msearch|_count|_async_search|_sql|_eql)(\/|$)/
or we should, and a TAV test run shows no test failures with this
change.

Better safe for possible future additions to `pathIsAQuery` than a
theoretical regression in the value captured for
span.context.db.statement.
Comment on lines 50 to 51
if (body) {
if (typeof (body) === 'string') {
parts.push(body)
} else if (Array.isArray(body)) {
parts.push(body.map(JSON.stringify).join('\n')) // ndjson
} else if (typeof (body) === 'object') {
parts.push(JSON.stringify(body))
}
if (typeof (body) === 'string') {
parts.push(body)
Copy link
Member Author

Choose a reason for hiding this comment

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

REVIEW NOTE: The acc97e5 commit message explains the reasoning for this change.

@trentm
Copy link
Member Author

trentm commented Oct 25, 2021

Tests all passed, I'm running a TAV test run now. From the TAV test run I only care about elasticsearch client tests. I expect there may be failures in fastify and hapi tests (see #2387 for a later fix for those).

Copy link
Contributor

@astorm astorm left a comment

Choose a reason for hiding this comment

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

👍 approving. It does the thing, splitting the new example makes sense with the API changes in 8, and adding the canary repo should help us be ahead of the curve when it comes to changes.

name: '@elastic/elasticsearch'
versions: '>=7.12.0 <8.0.0'
node: '>=10.0.0'
commands: node test/instrumentation/modules/@elastic/elasticsearch.test.js
'@elastic/elasticsearch-canary':
name: '@elastic/elasticsearch-canary'
versions: '^8.0.0-canary.35'
Copy link
Contributor

Choose a reason for hiding this comment

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

TIL: semver canary conventions 👍

Also -- it looks like canary release are coming fast and furious, with multiples in a day. We may wan to revisit testing every release greater than -canary.35 in the future and adopt an approach similar to what we do for AWS modules with a large number of releases. What we have here now though should be fine.

Copy link
Member Author

Choose a reason for hiding this comment

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

Right now I am trying to (manually) track what the Kibana 8.0 PR is using.

Potentially after the 8.0 release of the ES client settles down we should remove testing of the canary package.

@@ -11,7 +11,7 @@ var shimmer = require('./shimmer')
var Transaction = require('./transaction')

var MODULES = [
'@elastic/elasticsearch',
['@elastic/elasticsearch', '@elastic/elasticsearch-canary'],
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 tested this manually (in addition to the automated test changes below), and both a require('@elastic/elasticsearch') and require('@elastic/elasticsearch-canary') result in the agent loading the instrumentation module.

@trentm
Copy link
Member Author

trentm commented Oct 25, 2021

Something in the Jenkins run for the TAV tests is ridiculously slow/stuck: https://apm-ci.elastic.co/job/apm-agent-nodejs/job/apm-agent-nodejs-mbp/job/PR-2385/14/
I'm not waiting for those to get going or complete.

@trentm trentm merged commit d23e9e2 into master Oct 25, 2021
@trentm trentm deleted the trentm/esclient8 branch October 25, 2021 20:14
@apmmachine
Copy link
Contributor

💔 Build Failed

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2021-10-25T19:41:12.577+0000

  • Duration: 71 min 46 sec

  • Commit: ecbb6a1

Steps errors 18

Expand to view the steps failures

Show only the first 10 steps failures

Run Tests
  • Took 6 min 53 sec . View more details here
  • Description: .ci/scripts/test.sh -b "release" -t "hapi" "14"
Run Tests
  • Took 9 min 34 sec . View more details here
  • Description: .ci/scripts/test.sh -b "release" -t "hapi" "12"
Run Tests
  • Took 7 min 0 sec . View more details here
  • Description: .ci/scripts/test.sh -b "release" -t "hapi" "12"
Run Tests
  • Took 11 min 24 sec . View more details here
  • Description: .ci/scripts/test.sh -b "release" -t "hapi" "10"
Run Tests
  • Took 6 min 31 sec . View more details here
  • Description: .ci/scripts/test.sh -b "release" -t "hapi" "10"
Run Tests
  • Took 12 min 10 sec . View more details here
  • Description: .ci/scripts/test.sh -b "release" -t "@elastic/elasticsearch" "8"
Run Tests
  • Took 0 min 21 sec . View more details here
  • Description: .ci/scripts/test.sh -b "release" -t "@elastic/elasticsearch" "8"
Run Tests
  • Took 13 min 7 sec . View more details here
  • Description: .ci/scripts/test.sh -b "release" -t "hapi" "8"
Run Tests
  • Took 6 min 16 sec . View more details here
  • Description: .ci/scripts/test.sh -b "release" -t "hapi" "8"
Error signal
  • Took 0 min 0 sec . View more details here
  • Description: hudson.AbortException: script returned exit code 217

🤖 GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

  • run module tests for <modules> : Run TAV tests for one or more modules, where <modules> can be either a comma separated list of modules (e.g. memcached,redis) or the string literal ALL to test all modules

  • run benchmark tests : Run the benchmark test only.

trentm added a commit that referenced this pull request Oct 27, 2021
When `npm test` is run outside of CI, then "test/docker-compose.yml" is
used to setup required services (redis, ES, etc.). This is a separate
compose file than is used in CI. To test @elastic/elasticsearch@8
instrumentation requires an ES server at least 7.14 for its product
check to work. The test ES service had been updated for Jenkins and GH
CI, but this one was missed.

Refs: #2385
trentm added a commit that referenced this pull request Oct 29, 2021
When `npm test` is run outside of CI, then "test/docker-compose.yml" is
used to setup required services (redis, ES, etc.). This is a separate
compose file than is used in CI. To test @elastic/elasticsearch@8
instrumentation requires an ES server at least 7.14 for its product
check to work. The test ES service had been updated for Jenkins and GH
CI, but this one was missed.

Refs: #2385
astorm pushed a commit that referenced this pull request Oct 30, 2021
When `npm test` is run outside of CI, then "test/docker-compose.yml" is
used to setup required services (redis, ES, etc.). This is a separate
compose file than is used in CI. To test @elastic/elasticsearch@8
instrumentation requires an ES server at least 7.14 for its product
check to work. The test ES service had been updated for Jenkins and GH
CI, but this one was missed.

Refs: #2385
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
agent-nodejs Make available for APM Agents project planning.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

support v8.x of @elastic/elasticsearch
4 participants