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

fix configuring an ipv6 agent hostname #2486

Merged
merged 1 commit into from
Nov 1, 2022
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
8 changes: 6 additions & 2 deletions packages/dd-trace/src/exporters/agent/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
'use strict'

const URL = require('url').URL
const { URL, format } = require('url')
const log = require('../../log')
const Writer = require('./writer')

class AgentExporter {
constructor (config, prioritySampler) {
this._config = config
const { url, hostname, port, lookup, protocolVersion, stats = {} } = config
this._url = url || new URL(`http://${hostname || 'localhost'}:${port}`)
this._url = url || new URL(format({
protocol: 'http:',
hostname: hostname || 'localhost',
port
}))

const headers = {}
if (stats.enabled) {
Expand Down
8 changes: 6 additions & 2 deletions packages/dd-trace/src/exporters/span-stats/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
const { URL } = require('url')
const { URL, format } = require('url')

const { Writer } = require('./writer')

class SpanStatsExporter {
constructor (config) {
const { hostname = '127.0.0.1', port = 8126, tags, url } = config
this._url = url || new URL(`http://${hostname || 'localhost'}:${port}`)
this._url = url || new URL(format({
protocol: 'http:',
hostname: hostname || 'localhost',
port
}))
this._writer = new Writer({ url: this._url, tags })
}

Expand Down
7 changes: 6 additions & 1 deletion packages/dd-trace/src/metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

// TODO: capture every second and flush every 10 seconds

const { URL, format } = require('url')
const v8 = require('v8')
const os = require('os')
const Client = require('./dogstatsd')
Expand Down Expand Up @@ -57,7 +58,11 @@ module.exports = {
if (config.url) {
clientConfig.metricsProxyUrl = config.url
} else if (config.port) {
clientConfig.metricsProxyUrl = new URL(`http://${config.hostname || 'localhost'}:${config.port}`)
clientConfig.metricsProxyUrl = new URL(format({
protocol: 'http:',
hostname: config.hostname || 'localhost',
port: config.port
}))
}

client = new Client(clientConfig)
Expand Down
13 changes: 8 additions & 5 deletions packages/dd-trace/src/profiling/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const coalesce = require('koalas')
const os = require('os')
const { URL } = require('url')
const { URL, format } = require('url')
const { AgentExporter } = require('./exporters/agent')
const { FileExporter } = require('./exporters/file')
const { ConsoleLogger } = require('./loggers/console')
Expand Down Expand Up @@ -59,10 +59,13 @@ class Config {
this.sourceMap = sourceMap
this.endpointCollection = endpointCollection

const hostname = coalesce(options.hostname, DD_AGENT_HOST, 'localhost')
const port = coalesce(options.port, DD_TRACE_AGENT_PORT, 8126)
this.url = new URL(coalesce(options.url, DD_TRACE_AGENT_URL,
`http://${hostname || 'localhost'}:${port || 8126}`))
const hostname = coalesce(options.hostname, DD_AGENT_HOST) || 'localhost'
const port = coalesce(options.port, DD_TRACE_AGENT_PORT) || 8126
this.url = new URL(coalesce(options.url, DD_TRACE_AGENT_URL, format({
protocol: 'http:',
hostname,
port
})))

this.exporters = ensureExporters(options.exporters || [
new AgentExporter(this)
Expand Down
8 changes: 8 additions & 0 deletions packages/dd-trace/test/exporters/agent/exporter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ describe('Exporter', () => {
})
})

it('should support IPv6', () => {
const stats = { enabled: true }
exporter = new Exporter({ hostname: '::1', flushInterval, stats }, prioritySampler)
expect(Writer).to.have.been.calledWithMatch({
url: new URL('http://[::1]')
})
})

describe('when interval is set to a positive number', () => {
beforeEach(() => {
exporter = new Exporter({ url, flushInterval }, prioritySampler)
Expand Down
Loading