[RNDSTROPPY-94,RNDSTROPPY-89,RNDSTROPPY-90]: new drivers semantic#52
Merged
[RNDSTROPPY-94,RNDSTROPPY-89,RNDSTROPPY-90]: new drivers semantic#52
Conversation
Closes RNDSTROPPY-94
Closes RNDSTROPPY-94, RNDSTROPPY-90, RNDSTROPPY-89
Closes RNDSTROPPY-94
Closes RNDSTROPPY-94
Closes RNDSTROPPY-94
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of Changes
Replaces the monolithic
DriverX.fromConfig(globalConfig)API with a two-stepDriverX.create().setup(driverConfig)pattern. Sharing semantics (shared poolvs. per-VU connection) are now determined implicitly by the k6 lifecycle stage
in which
setup()is called, rather than by an explicitconnectionTypefieldin the config.
Driver lifecycle:
DriverX.create()— allocates an empty shell; no connection is made yet..setup(config)— stores the config (runs once per shell viasync.Once).driver is marked shared; one pool is created on the first VU that reaches
the iteration phase and reused by all VUs.
default()orsetup()): thedriver is marked per-VU; each VU gets its own independent pool.
DialFunc(k6 network metrics) is always available.once()helper — wraps any function so it executes only once per VUregardless of how many iterations run. Useful for per-VU initialisation that
must not repeat (e.g. calling
setup()on a per-VU driver).Proto cleanup:
GlobalConfig.driverfield removed; driver config is no longer part of theglobal config.
DriverConfig.ConnectionTypeoneof anddb_specific: Value.Structreplacedby a typed
DriverConfig.PostgresConfigmessage with explicit optional fields(
max_conns,min_conns,max_conn_lifetime,default_query_exec_mode, …).DriverConfigis now passed directly todriver.setup()instead of beingnested inside
GlobalConfig.Internal refactor:
driver.Dispatch()now accepts a singledriver.Optionsstruct(
Config,Logger,DialFunc) instead of positional arguments.Driver.Configure()method removed; pool reconfiguration withDialFunchappens inside
NewDriver().NewDriverByConfigBin→NewDriverin the Go/JS boundary.multitracerremoved; singleloggerTracerused instead.Usage Examples
Shared driver (one pool for all VUs)
Call
setup()at the top level (init phase). All VUs share the same pool.Per-VU driver (each VU gets its own pool)
Create the shell at init, call
setup()insidedefault(). Wrap it withonce()so the setup only fires on the first iteration of each VU.Multiple independent drivers in one script
Each
DriverX.create()call allocates an independent slot. Shared vs. per-VUis decided per-driver by when
setup()is called.Per-VU drivers for multi-node tests (each VU targets a different node)
Create the shell at init, then use
once()to callsetup()on the firstiteration with a URL derived from the VU's ID. Each VU connects to a dedicated
node in round-robin order.
VUs 0, 3, 6 → node-0 · VUs 1, 4, 7 → node-1 · VUs 2, 5, 8 → node-2.
The
once()guard ensures the pool is created exactly once per VU regardlessof iteration count.
Motivation and Context
The previous API required embedding the driver URL inside
GlobalConfigandpicking a connection type via a protobuf
oneof. This was unintuitive andforced users to understand the internal
sharedDrvsingleton. The new APImakes sharing explicit through call-site location (init vs. iteration), which
aligns with how k6 itself distinguishes lifecycle phases. It also removes the
need for
Configure()as a separate post-construction step, eliminating thetwo-phase init race that existed when multiple VUs tried to configure the
shared driver concurrently.
How Has This Been Tested?
make tests— unit tests pass (pool config, spy proxy).workloads/tests/sqlapi_test.ts— existing SQL API integration test updatedto new API and passing.
workloads/tests/multi_drivers_test.ts— new integration test that runs 3VUs × 3 iterations and verifies:
application_name.application_namestable acrossiterations.
once()fires exactly once per VU regardless of iteration count.pg_stat_activityconfirms correct connection counts per pool.Type of Changes
Checklist