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

Added workload and client_os_hostname connection parameters #124

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 8 additions & 2 deletions packages/vertica-nodejs/lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
'use strict'

var dns = require('dns')
var os = require('os')
jonathanl-bq marked this conversation as resolved.
Show resolved Hide resolved
var EventEmitter = require('events').EventEmitter
var util = require('util')
var utils = require('./utils')
Expand Down Expand Up @@ -76,12 +77,13 @@ class Client extends EventEmitter {
this.tls_config = this.connectionParameters.tls_config
this.tls_mode = this.connectionParameters.tls_mode || 'disable'
this.tls_trusted_certs = this.connectionParameters.tls_trusted_certs
this._connectionTimeoutMillis = c.connectionTimeoutMillis || 0
this.workload = this.connectionParameters.workload

delete this.connectionParameters.tls_config
delete this.connectionParameters.tls_mode
delete this.connectionParameters.tls_trusted_certs

this._connectionTimeoutMillis = c.connectionTimeoutMillis || 0
}

_errorAllQueries(err) {
Expand Down Expand Up @@ -496,6 +498,7 @@ class Client extends EventEmitter {
user: params.user,
database: params.database,
protocol_version: params.protocol_version.toString(),
client_os_hostname: params.client_os_hostname
}

if (params.replication) {
Expand All @@ -510,10 +513,13 @@ class Client extends EventEmitter {
if (params.options) {
data.options = params.options
}

if (params.client_label) {
data.client_label = params.client_label
}
if (params.workload) {
data.workload = params.workload
}


return data
}
Expand Down
3 changes: 3 additions & 0 deletions packages/vertica-nodejs/lib/connection-parameters.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
'use strict'

var dns = require('dns')
var os = require('os')

var defaults = require('./defaults')

Expand Down Expand Up @@ -112,6 +113,8 @@ class ConnectionParameters {

this.backup_server_node = parseBackupServerNodes(val('backup_server_node', config))
this.client_label = val('client_label', config, false)
this.workload = val('workload', config, false)
this.client_os_hostname = os.hostname()
//NOTE: The client has only been tested to support 3.5, which was chosen in order to include SHA512 support
this.protocol_version = (3 << 16 | 5) // 3.5 -> (major << 16 | minor) -> (3 << 16 | 5) -> 196613

Expand Down
16 changes: 2 additions & 14 deletions packages/vertica-nodejs/lib/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,39 +51,27 @@ module.exports = {
// max milliseconds a client can go unused before it is removed
// from the pool and destroyed
idleTimeoutMillis: 30000,

client_encoding: '',

tls_mode: 'disable',

tls_key_file: undefined,

tls_cert_file: undefined,

options: undefined,

parseInputDatesAsUTC: false,

// max milliseconds any query using this connection will execute for before timing out in error.
// false=unlimited
statement_timeout: false,

// Terminate any session with an open transaction that has been idle for longer than the specified duration in milliseconds
// false=unlimited
idle_in_transaction_session_timeout: false,

// max milliseconds to wait for query to complete (client side)
query_timeout: false,

connect_timeout: 0,

keepalives: 1,

keepalives_idle: 0,

// A string to identify the vertica-nodejs connection's session on the server
client_label: '',

// A comma separated string listing all backup nodes to connect to. Each node is a host-port pair separated by a colon.
backup_server_node: '',
// workload associated with this session
workload: '',
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
const vertica = require('../../../lib')
const assert = require('assert')

describe('vertica label connection parameter', function () {
var os = require('os')

describe('vertica client label connection parameter', function () {
it('has a default value that is used when left unspecified', function(done) {
//assert current default value
assert.equal(vertica.defaults.client_label, '')
Expand Down Expand Up @@ -102,3 +104,30 @@ describe('vertica backup_server_node connection parameter', function() {
done()
})
})

describe('vertica client_os_hostname connection parameter', function() {
it('is automatically determined and sent in the startup packet', function() {
const client = new vertica.Client()
client.connect()
client.query("SELECT client_os_hostname FROM current_session", (err, res) => {
if (err) assert(false)
assert.equal(res.rows[0].client_os_hostname, os.hostname())
client.end()
})
})
})

describe('vertica workload connection parameter', function() {
it('can be set and is sent in the startup packet', function() {
const client = new vertica.Client({workload: 'testNodeWorkload'})
client.connect()
client.query(`SELECT contents FROM dc_client_server_messages
WHERE session_id = current_session()
AND message_type = '^+'
AND contents like '%workload%'`, (err, res) => {
if (err) assert(false)
assert.equal(res.rows[0].contents, 'workload: testNodeWorkload')
client.end()
})
})
})