Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
w1am committed Dec 18, 2024
1 parent 1da39c3 commit c7e8545
Show file tree
Hide file tree
Showing 23 changed files with 245 additions and 204 deletions.
10 changes: 5 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Development is done on the `master` branch. We attempt to do our best to ensure
**Repository Setup:**
1. Clone the repository:
```bash
$ git clone [email protected]:Kurrent/Kurrent-Client-NodeJS.git
$ git clone [email protected]:EventStore/Kurrent-Client-NodeJS.git
$ cd Kurrent-Client-NodeJS
```
2. Install all necessary dependencies:
Expand Down Expand Up @@ -70,7 +70,7 @@ $ npm run test:debug // debug all tests
$ npm run test:debug ReadAll // only the ReadAll tests
```

Specific docker images can be specified via the enviroment variable `KURRENT_IMAGE`.
Specific docker images can be specified via the environment variable `KURRENT_IMAGE`.

```shell script
$ npx cross-env KURRENT_IMAGE=77d63f3f0ab3 jest
Expand All @@ -81,8 +81,8 @@ See [Jest] documentation for more options.
### Debugging

This project uses the [debug] module internally to log information about connections, options and GRPC requests.
To see all the internal logs, set the DEBUG environment variable to `esdb:*` when launching your app.
Logs can be further filtered with glob patterns, for example, only connection logs: `esdb:connection`, everything but grpc logs: `esdb:*,-*:grpc`.
To see all the internal logs, set the DEBUG environment variable to `kdb:*` when launching your app.
Logs can be further filtered with glob patterns, for example, only connection logs: `kdb:connection`, everything but grpc logs: `kdb:*,-*:grpc`.

You can set a few environment variables that will further change the behavior of the debug logging:

Expand All @@ -103,4 +103,4 @@ See the Node.js documentation for [`util.inspect()`] for the complete list.
[jest]: https://jestjs.io/
[debug]: https://github.com/visionmedia/debug
[`util.inspect()`]: https://nodejs.org/api/util.html#util_util_inspect_object_options
[kurrent-client-nodejs]: https://github.com/Kurrent/Kurrent-Client-NodeJS
[kurrent-client-nodejs]: https://github.com/EventStore/Kurrent-Client-NodeJS
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ Refer to our [Contribution Guidelines]
[discord-kurrent]: https://discord.gg/Phn9pmCw3t
[discord-ddd-cqrs-es]: https://discord.com/invite/sEZGSHNNbH
[license-badge]: https://img.shields.io/npm/l/@kurrent/db-client.svg
[license-badge-url]: https://github.com/Kurrent/Kurrent-Client-NodeJS/blob/master/LICENSE
[contribution guidelines]: https://github.com/Kurrent/Kurrent-Client-NodeJS/blob/master/CONTRIBUTING.md
[license-badge-url]: https://github.com/EventStore/Kurrent-Client-NodeJS/blob/master/LICENSE
[contribution guidelines]: https://github.com/EventStore/Kurrent-Client-NodeJS/blob/master/CONTRIBUTING.md
8 changes: 4 additions & 4 deletions packages/db-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,9 @@ Refer to our [Contribution Guidelines]
[discord-ddd-cqrs-es]: https://discord.com/invite/sEZGSHNNbH
[npm-badge]: https://img.shields.io/npm/v/@kurrent/db-client.svg
[npm-badge-url]: https://www.npmjs.com/package/@kurrent/db-client
[ci-badge]: https://github.com/Kurrent/Kurrent-Client-NodeJS/workflows/CI/badge.svg?branch=master
[ci-badge-url]: https://github.com/Kurrent/Kurrent-Client-NodeJS/actions
[ci-badge]: https://github.com/EventStore/Kurrent-Client-NodeJS/workflows/CI/badge.svg?branch=master
[ci-badge-url]: https://github.com/EventStore/Kurrent-Client-NodeJS/actions
[license-badge]: https://img.shields.io/npm/l/@kurrent/db-client.svg
[license-badge-url]: https://github.com/Kurrent/Kurrent-Client-NodeJS/blob/master/LICENSE
[contribution guidelines]: https://github.com/Kurrent/Kurrent-Client-NodeJS/blob/master/CONTRIBUTING.md
[license-badge-url]: https://github.com/EventStore/Kurrent-Client-NodeJS/blob/master/LICENSE
[contribution guidelines]: https://github.com/EventStore/Kurrent-Client-NodeJS/blob/master/CONTRIBUTING.md
[Kurrent docs]: https://developers.eventstore.com/server/v24.6/quick-start/installation
17 changes: 14 additions & 3 deletions packages/db-client/src/Client/parseConnectionString.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,22 +86,33 @@ const parseProtocol = (
options: ConnectionOptions
): ConnectionOptions => {
let nextPosition = position;
const expected = "esdb:// or esdb+discover://";
const expected =
"kurrent://, kurrent+discover://, kdb://, or kdb+discover://";
const match = connectionString
.substring(position)
.match(/^(?<protocol>[^:]+):\/\//);

if (match && match.groups?.protocol) {
nextPosition += match[0].length;

if (match.groups.protocol.startsWith("esdb")) {
console.warn(
`The 'esdb' protocol is deprecated. Please use 'kurrent' or 'kdb' instead.`
);
}

switch (match.groups.protocol) {
case "esdb": {
case "esdb":
case "kurrent":
case "kdb": {
return parseCredentials(connectionString, nextPosition, {
...options,
dnsDiscover: false,
});
}
case "esdb+discover": {
case "esdb+discover":
case "kurrent+discover":
case "kdb+discover": {
return parseCredentials(connectionString, nextPosition, {
...options,
dnsDiscover: true,
Expand Down
10 changes: 5 additions & 5 deletions packages/opentelemetry/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ Refer to our [contribution guidelines][contributing-guidelines].
[Discord-ddd-cqrs-es]: https://discord.com/invite/sEZGSHNNbH
[contributing-guidelines]: https://github.com/prisma/prisma/blob/main/CONTRIBUTING.md
[license-badge]: https://img.shields.io/npm/l/@kurrent/db-client.svg
[license-badge-url]: https://github.com/Kurrent/Kurrent-Client-NodeJS/blob/master/LICENSE
[ci-badge-url]: https://github.com/Kurrent/Kurrent-Client-NodeJS/actions
[Kurrent-Client-NodeJS]: https://github.com/Kurrent/Kurrent-Client-NodeJS
[ci-badge]: https://github.com/Kurrent/Kurrent-Client-NodeJS/workflows/CI/badge.svg?branch=master
[ci-badge-url]: https://github.com/Kurrent/Kurrent-Client-NodeJS/actions
[license-badge-url]: https://github.com/EventStore/Kurrent-Client-NodeJS/blob/master/LICENSE
[ci-badge-url]: https://github.com/EventStore/Kurrent-Client-NodeJS/actions
[Kurrent-Client-NodeJS]: https://github.com/EventStore/Kurrent-Client-NodeJS
[ci-badge]: https://github.com/EventStore/Kurrent-Client-NodeJS/workflows/CI/badge.svg?branch=master
[ci-badge-url]: https://github.com/EventStore/Kurrent-Client-NodeJS/actions
2 changes: 1 addition & 1 deletion packages/opentelemetry/src/attributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const db = "db";
const server = "server";
const streams = "streams";

export const KurrentDBAttributes = {
export const KurrentAttributes = {
DATABASE_USER: `${db}.user`,
DATABASE_SYSTEM: `${db}.system`,
DATABASE_OPERATION: `${db}.operation`,
Expand Down
62 changes: 32 additions & 30 deletions packages/opentelemetry/src/instrumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import type {
} from "@kurrent/db-client";
import type { ReadResp as StreamsReadResp } from "@kurrent/db-client/generated/streams_pb";
import type { ReadResp as PersistentReadResp } from "@kurrent/db-client/generated/persistent_pb";
import { KurrentDBAttributes } from "./attributes";
import { KurrentAttributes } from "./attributes";
import type { PersistentSubscriptionImpl } from "@kurrent/db-client/src/persistentSubscription/utils/PersistentSubscriptionImpl";
import type { Subscription } from "@kurrent/db-client/src/streams/utils/Subscription";
import { INSTRUMENTATION_NAME, INSTRUMENTATION_VERSION } from "./version";
Expand Down Expand Up @@ -144,19 +144,19 @@ export class Instrumentation extends InstrumentationBase {
const { hostname, port } = Instrumentation.getServerAddress(uri);

const attributes: Attributes = {
[KurrentDBAttributes.KURRENT_DB_STREAM]: streamName,
[KurrentDBAttributes.SERVER_ADDRESS]: hostname,
[KurrentDBAttributes.SERVER_PORT]: port,
[KurrentDBAttributes.DATABASE_SYSTEM]: INSTRUMENTATION_NAME,
[KurrentDBAttributes.DATABASE_OPERATION]: operation,
[KurrentAttributes.KURRENT_DB_STREAM]: streamName,
[KurrentAttributes.SERVER_ADDRESS]: hostname,
[KurrentAttributes.SERVER_PORT]: port,
[KurrentAttributes.DATABASE_SYSTEM]: INSTRUMENTATION_NAME,
[KurrentAttributes.DATABASE_OPERATION]: operation,
};

if (options?.credentials) {
attributes[KurrentDBAttributes.DATABASE_USER] =
attributes[KurrentAttributes.DATABASE_USER] =
options.credentials.username;
}

const span = tracer.startSpan(KurrentDBAttributes.STREAM_APPEND, {
const span = tracer.startSpan(KurrentAttributes.STREAM_APPEND, {
kind: SpanKind.CLIENT,
attributes,
});
Expand Down Expand Up @@ -230,31 +230,33 @@ export class Instrumentation extends InstrumentationBase {
const subscriptionId = subscription.id;

const attributes: Attributes = {
[KurrentDBAttributes.KURRENT_DB_STREAM]: resolvedEvent?.event?.streamId,
[KurrentDBAttributes.KURRENT_DB_EVENT_ID]: resolvedEvent?.event?.id,
[KurrentDBAttributes.KURRENT_DB_EVENT_TYPE]: resolvedEvent?.event?.type,
[KurrentDBAttributes.KURRENT_DB_SUBSCRIPTION_ID]: subscriptionId,
[KurrentDBAttributes.SERVER_ADDRESS]: hostname,
[KurrentDBAttributes.SERVER_PORT]: port,
[KurrentDBAttributes.DATABASE_SYSTEM]: INSTRUMENTATION_NAME,
[KurrentDBAttributes.DATABASE_OPERATION]: operation,
[KurrentDBAttributes.DATABASE_USER]: options?.credentials?.username,
[KurrentAttributes.KURRENT_DB_STREAM]: resolvedEvent?.event?.streamId,
[KurrentAttributes.KURRENT_DB_EVENT_ID]: resolvedEvent?.event?.id,
[KurrentAttributes.KURRENT_DB_EVENT_TYPE]: resolvedEvent?.event?.type,
[KurrentAttributes.KURRENT_DB_SUBSCRIPTION_ID]: subscriptionId,
[KurrentAttributes.SERVER_ADDRESS]: hostname,
[KurrentAttributes.SERVER_PORT]: port,
[KurrentAttributes.DATABASE_SYSTEM]: INSTRUMENTATION_NAME,
[KurrentAttributes.DATABASE_OPERATION]: operation,
[KurrentAttributes.DATABASE_USER]: options?.credentials?.username,
};

return context.with(parentContext, () => {
const span = tracer.startSpan(spanName, {
const span = tracer.startSpan(
spanName,
{
attributes,
kind: SpanKind.CONSUMER,
});
},
parentContext
);

try {
return resolved;
} catch (error) {
throw Instrumentation.handleError(error, span);
} finally {
span.end();
}
});
try {
return resolved;
} catch (error) {
throw Instrumentation.handleError(error, span);
} finally {
span.end();
}
};
}

Expand Down Expand Up @@ -291,7 +293,7 @@ export class Instrumentation extends InstrumentationBase {

this.resolveUri().then((uri) =>
Instrumentation.applySubscriptionInstrumentation(
KurrentDBAttributes.STREAM_SUBSCRIBE,
KurrentAttributes.STREAM_SUBSCRIBE,
subscription,
uri,
operation,
Expand Down Expand Up @@ -338,7 +340,7 @@ export class Instrumentation extends InstrumentationBase {

this.resolveUri().then((uri) =>
Instrumentation.applySubscriptionInstrumentation(
KurrentDBAttributes.STREAM_SUBSCRIBE,
KurrentAttributes.STREAM_SUBSCRIBE,
subscription,
uri,
operation,
Expand Down
2 changes: 1 addition & 1 deletion packages/test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ Refer to our [contribution guidelines][contributing-guidelines].
[discord-ddd-cqrs-es]: https://discord.com/invite/sEZGSHNNbH
[contributing-guidelines]: https://github.com/prisma/prisma/blob/main/CONTRIBUTING.md
[license-badge]: https://img.shields.io/npm/l/@kurrent/db-client.svg
[license-badge-url]: https://github.com/Kurrent/Kurrent-Client-NodeJS/blob/master/LICENSE
[license-badge-url]: https://github.com/EventStore/Kurrent-Client-NodeJS/blob/master/LICENSE
Original file line number Diff line number Diff line change
@@ -1,35 +1,38 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`connection string parser Should throw on invalid strings esbd+discovery://localhost 1`] = `"Unexpected \\"esbd+discovery://\\" at position 0, expected esdb:// or esdb+discover://."`;
exports[`connection string parser Should throw on invalid strings esbd+discovery://localhost 1`] = `"Unexpected \\"esbd+discovery://\\" at position 0, expected kurrent://, kurrent+discover://, kdb://, or kdb+discover://."`;

exports[`connection string parser Should throw on invalid strings esdb://host1,host2:200:300?throwOnAppendFailure=false 1`] = `"Unexpected \\":300\\" at position 22, expected , or ?key=value."`;
exports[`connection string parser Should throw on invalid strings https://console.eventstore.cloud/ 1`] = `"Unexpected \\"https://\\" at position 0, expected kurrent://, kurrent+discover://, kdb://, or kdb+discover://."`;

exports[`connection string parser Should throw on invalid strings esdb://host1;host2;host3?throwOnAppendFailure=false 1`] = `"Unexpected \\";\\" at position 12, expected ?key=value."`;
exports[`connection string parser Should throw on invalid strings kurrent://host1,host2:200:300?throwOnAppendFailure=false 1`] = `"Unexpected \\":300\\" at position 25, expected , or ?key=value."`;

exports[`connection string parser Should throw on invalid strings esdb://localhost/&throwOnAppendFailure=false 1`] = `"Unexpected \\"&\\" at position 17, expected ?key=value."`;
exports[`connection string parser Should throw on invalid strings kurrent://host1;host2;host3?throwOnAppendFailure=false 1`] = `"Unexpected \\";\\" at position 15, expected ?key=value."`;

exports[`connection string parser Should throw on invalid strings esdb://localhost?keepAliveInterval=XXIV 1`] = `"Unexpected \\"XXIV\\" at position 35, expected Integer."`;
exports[`connection string parser Should throw on invalid strings kurrent://localhost/&throwOnAppendFailure=false 1`] = `"Unexpected \\"&\\" at position 20, expected ?key=value."`;

exports[`connection string parser Should throw on invalid strings esdb://localhost?keepAliveTimeout=please 1`] = `"Unexpected \\"please\\" at position 34, expected Integer."`;
exports[`connection string parser Should throw on invalid strings kurrent://localhost?keepAliveInterval=XXIV 1`] = `"Unexpected \\"XXIV\\" at position 38, expected Integer."`;

exports[`connection string parser Should throw on invalid strings esdb://localhost?throwOnAppendFailure=false&nodePreference=any 1`] = `"Unexpected \\"any\\" at position 59, expected leader or follower or read_only_replica or random."`;
exports[`connection string parser Should throw on invalid strings kurrent://localhost?keepAliveTimeout=please 1`] = `"Unexpected \\"please\\" at position 37, expected Integer."`;

exports[`connection string parser Should throw on invalid strings esdb://localhost?throwOnAppendFailure=false?nodePreference=follower 1`] = `"Unexpected \\"?\\" at position 43, expected &key=value."`;
exports[`connection string parser Should throw on invalid strings kurrent://localhost?throwOnAppendFailure=false&nodePreference=any 1`] = `"Unexpected \\"any\\" at position 62, expected leader or follower or read_only_replica or random."`;

exports[`connection string parser Should throw on invalid strings esdb://localhost?throwOnAppendFailure=if you feel like it 1`] = `"Unexpected \\"if you feel like it\\" at position 38, expected true or false."`;
exports[`connection string parser Should throw on invalid strings kurrent://localhost?throwOnAppendFailure=false?nodePreference=follower 1`] = `"Unexpected \\"?\\" at position 46, expected &key=value."`;

exports[`connection string parser Should throw on invalid strings esdb://localhost?throwOnAppendFailure=sometimes 1`] = `"Unexpected \\"sometimes\\" at position 38, expected true or false."`;
exports[`connection string parser Should throw on invalid strings kurrent://localhost?throwOnAppendFailure=if you feel like it 1`] = `"Unexpected \\"if you feel like it\\" at position 41, expected true or false."`;

exports[`connection string parser Should throw on invalid strings esdb://my:great@username:UyeXx8$^PsOo4jG88FlCauR1Coz25q@host?nodePreference=follower&throwOnAppendFailure=false 1`] = `"Unexpected \\"UyeXx8\\" at position 25, expected port number."`;
exports[`connection string parser Should throw on invalid strings kurrent://localhost?throwOnAppendFailure=sometimes 1`] = `"Unexpected \\"sometimes\\" at position 41, expected true or false."`;

exports[`connection string parser Should throw on invalid strings esdb://throwOnAppendFailure=false 1`] = `"Unexpected \\"=\\" at position 27, expected ?key=value."`;
exports[`connection string parser Should throw on invalid strings kurrent://my:great@username:UyeXx8$^PsOo4jG88FlCauR1Coz25q@host?nodePreference=follower&throwOnAppendFailure=false 1`] = `"Unexpected \\"UyeXx8\\" at position 28, expected port number."`;

exports[`connection string parser Should throw on invalid strings https://console.eventstore.cloud/ 1`] = `"Unexpected \\"https://\\" at position 0, expected esdb:// or esdb+discover://."`;
exports[`connection string parser Should throw on invalid strings kurrent://throwOnAppendFailure=false 1`] = `"Unexpected \\"=\\" at position 30, expected ?key=value."`;

exports[`connection string parser Should throw on invalid strings localhost 1`] = `"Unexpected \\"l\\" at position 0, expected esdb:// or esdb+discover://."`;
exports[`connection string parser Should throw on invalid strings localhost 1`] = `"Unexpected \\"l\\" at position 0, expected kurrent://, kurrent+discover://, kdb://, or kdb+discover://."`;

exports[`connection string parser Should warn on unknown and unsupported keys esdb://localhost?catchOnAppendFailure=true&throwOnAppendFailure=false 1`] = `
Array [
Array [
"The 'esdb' protocol is deprecated. Please use 'kurrent' or 'kdb' instead.",
],
Array [
"Unknown option key \\"catchOnAppendFailure\\", setting will be ignored.
esdb://localhost?catchOnAppendFailure=true&throwOnAppendFailure=false
Expand All @@ -38,30 +41,40 @@ esdb://localhost?catchOnAppendFailure=true&throwOnAppendFailure=false
]
`;

exports[`connection string parser Should warn on unknown and unsupported keys esdb://localhost?someNonsense=follower&doTheThing=true 1`] = `
exports[`connection string parser Should warn on unknown and unsupported keys kurrent://localhost?catchOnAppendFailure=true&throwOnAppendFailure=false 1`] = `
Array [
Array [
"Unknown option key \\"catchOnAppendFailure\\", setting will be ignored.
kurrent://localhost?catchOnAppendFailure=true&throwOnAppendFailure=false
^^^^^^^^^^^^^^^^^^^^",
],
]
`;

exports[`connection string parser Should warn on unknown and unsupported keys kurrent://localhost?someNonsense=follower&doTheThing=true 1`] = `
Array [
Array [
"Unknown option key \\"someNonsense\\", setting will be ignored.
esdb://localhost?someNonsense=follower&doTheThing=true
^^^^^^^^^^^^",
kurrent://localhost?someNonsense=follower&doTheThing=true
^^^^^^^^^^^^",
],
Array [
"Unknown option key \\"doTheThing\\", setting will be ignored.
esdb://localhost?someNonsense=follower&doTheThing=true
^^^^^^^^^^",
kurrent://localhost?someNonsense=follower&doTheThing=true
^^^^^^^^^^",
],
]
`;

exports[`connection string parser Should warn on unknown and unsupported keys esdb://localhost?tlsVerifyCert=false 1`] = `
exports[`connection string parser Should warn on unknown and unsupported keys kurrent://localhost?tlsVerifyCert=false 1`] = `
Array [
Array [
"\\"tlsVerifyCert\\" is not currently supported by this client, and will have no effect.
Consider either:
Passing \\"tlsCAFile\\" in the connection string.
Setting NODE_EXTRA_CA_CERTS https://nodejs.org/api/cli.html#cli_node_extra_ca_certs_file
esdb://localhost?tlsVerifyCert=false
^^^^^^^^^^^^^^^^^^^",
kurrent://localhost?tlsVerifyCert=false
^^^^^^^^^^^^^^^^^^^",
],
]
`;
2 changes: 2 additions & 0 deletions packages/test/src/connection/cluster.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { collect, createTestCluster } from "@test-utils";
import { jsonEvent, KurrentDBClient } from "@kurrent/db-client";

jest.setTimeout(120_000);

describe("cluster", () => {
const cluster = createTestCluster();
const STREAM_NAME = "test_stream_name";
Expand Down
Loading

0 comments on commit c7e8545

Please sign in to comment.