Report correct transport connection type in telemetry (#2599)
Fixes #2324
This commit is contained in:
@ -287,7 +287,14 @@ export default class Client extends API {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (options.enableMetaHeader) {
|
if (options.enableMetaHeader) {
|
||||||
options.headers['x-elastic-client-meta'] = `es=${clientVersion},js=${nodeVersion},t=${transportVersion},hc=${nodeVersion}`
|
let clientMeta = `es=${clientVersion},js=${nodeVersion},t=${transportVersion}`
|
||||||
|
if (options.Connection === UndiciConnection) {
|
||||||
|
clientMeta += `,un=${nodeVersion}`
|
||||||
|
} else {
|
||||||
|
// assumes HttpConnection
|
||||||
|
clientMeta += `,hc=${nodeVersion}`
|
||||||
|
}
|
||||||
|
options.headers['x-elastic-client-meta'] = clientMeta
|
||||||
}
|
}
|
||||||
|
|
||||||
this.name = options.name
|
this.name = options.name
|
||||||
|
|||||||
@ -25,7 +25,7 @@ import FakeTimers from '@sinonjs/fake-timers'
|
|||||||
import { buildServer, connection } from '../utils'
|
import { buildServer, connection } from '../utils'
|
||||||
import { Client, errors } from '../..'
|
import { Client, errors } from '../..'
|
||||||
import * as symbols from '@elastic/transport/lib/symbols'
|
import * as symbols from '@elastic/transport/lib/symbols'
|
||||||
import { BaseConnectionPool, CloudConnectionPool, WeightedConnectionPool } from '@elastic/transport'
|
import { BaseConnectionPool, CloudConnectionPool, WeightedConnectionPool, HttpConnection } from '@elastic/transport'
|
||||||
|
|
||||||
let clientVersion: string = require('../../package.json').version // eslint-disable-line
|
let clientVersion: string = require('../../package.json').version // eslint-disable-line
|
||||||
if (clientVersion.includes('-')) {
|
if (clientVersion.includes('-')) {
|
||||||
@ -404,6 +404,44 @@ test('Meta header disabled', async t => {
|
|||||||
await client.transport.request({ method: 'GET', path: '/' })
|
await client.transport.request({ method: 'GET', path: '/' })
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('Meta header indicates when UndiciConnection is used', async t => {
|
||||||
|
t.plan(1)
|
||||||
|
|
||||||
|
function handler (req: http.IncomingMessage, res: http.ServerResponse) {
|
||||||
|
t.equal(req.headers['x-elastic-client-meta'], `es=${clientVersion},js=${nodeVersion},t=${transportVersion},un=${nodeVersion}`)
|
||||||
|
res.end('ok')
|
||||||
|
}
|
||||||
|
|
||||||
|
const [{ port }, server] = await buildServer(handler)
|
||||||
|
|
||||||
|
const client = new Client({
|
||||||
|
node: `http://localhost:${port}`,
|
||||||
|
// Connection: UndiciConnection is the default
|
||||||
|
})
|
||||||
|
|
||||||
|
await client.transport.request({ method: 'GET', path: '/' })
|
||||||
|
server.stop()
|
||||||
|
})
|
||||||
|
|
||||||
|
test('Meta header indicates when HttpConnection is used', async t => {
|
||||||
|
t.plan(1)
|
||||||
|
|
||||||
|
function handler (req: http.IncomingMessage, res: http.ServerResponse) {
|
||||||
|
t.equal(req.headers['x-elastic-client-meta'], `es=${clientVersion},js=${nodeVersion},t=${transportVersion},hc=${nodeVersion}`)
|
||||||
|
res.end('ok')
|
||||||
|
}
|
||||||
|
|
||||||
|
const [{ port }, server] = await buildServer(handler)
|
||||||
|
|
||||||
|
const client = new Client({
|
||||||
|
node: `http://localhost:${port}`,
|
||||||
|
Connection: HttpConnection,
|
||||||
|
})
|
||||||
|
|
||||||
|
await client.transport.request({ method: 'GET', path: '/' })
|
||||||
|
server.stop()
|
||||||
|
})
|
||||||
|
|
||||||
test('caFingerprint', t => {
|
test('caFingerprint', t => {
|
||||||
const client = new Client({
|
const client = new Client({
|
||||||
node: 'https://localhost:9200',
|
node: 'https://localhost:9200',
|
||||||
|
|||||||
Reference in New Issue
Block a user