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

Refactor: Split big code files #354

Merged
merged 2 commits into from
Feb 27, 2024
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
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ jobs:
with:
github-token: ${{ secrets.YDB_PLATFORM_BOT_TOKEN_REPO }}
npm-token: ${{ secrets.NODE_AUTH_TOKEN }}
npm-dist-tag: beta
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ All notable changes to this project will be documented in this file. See [standa
- decimal value is present as string instead of bigint
(it wasn't working for float values before)
- fix uuid and tz-date types conversion (it wasn't working before)
* signatures of most methods in Session are changed:
* signatures of most methods in TableSession are changed:
- executeQuery
Before: `(query, params, txControl, operationParams?, settings?, collectStats?)`
After: `(query, params, txControl, settings?)`
Expand Down Expand Up @@ -336,7 +336,7 @@ All notable changes to this project will be documented in this file. See [standa

* drop support of old environment variables ([963819a](https://www.github.com/ydb-platform/ydb-nodejs-sdk/commit/963819af9209a45749f5118077f1da4bdb390fa6))
* reorganize signature of SchemeClient's methods ([734d57a](https://www.github.com/ydb-platform/ydb-nodejs-sdk/commit/734d57a2dd7c655cf727b96df415212504339cf8))
* reorganize signatures of Session's methods ([431f149](https://www.github.com/ydb-platform/ydb-nodejs-sdk/commit/431f1491bf880f3ba9541d9455d8dd2f2b7849e6))
* reorganize signatures of TableSession's methods ([431f149](https://www.github.com/ydb-platform/ydb-nodejs-sdk/commit/431f1491bf880f3ba9541d9455d8dd2f2b7849e6))
* use identity names conversion in TypedData ([275598a](https://www.github.com/ydb-platform/ydb-nodejs-sdk/commit/275598aa444e1e977386a3dadd02bbc9ba01f38e))

### [2.9.2](https://www.github.com/ydb-platform/ydb-nodejs-sdk/compare/v2.9.1...v2.9.2) (2022-02-09)
Expand Down Expand Up @@ -431,7 +431,7 @@ All notable changes to this project will be documented in this file. See [standa
* and many other changes in protobufs.

### 1.10.0
* Add `alterTable` method to Session class
* Add `alterTable` method to TableSession class
* Put compiled protobufs to a separate 'ydb-sdk' namespace

### 1.9.0
Expand Down
52 changes: 52 additions & 0 deletions slo-workload/DEV.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# SLO development guide

## Local testing

### Start local environment

In the [slo-tests](https://github.com/ydb-platform/slo-tests) project
in the _playground_ folder

`docker compose up -d`

### Check everything in the browser

In the browser, open

* [Grafana](http://localhost:3000/)

* [YDB](http://localhost:8765/) (Check SLO dashboard)

### Configure local console to run SLO tests

In the [ydb-nodejs-sdk](https://github.com/ydb-platform/ydb-nodejs-sdk) project
in the _slo-workload_ folder

`npm i`

`set YDB_ANONYMOUS_CREDENTIALS=1`

`set YDB_SSL_ROOT_CERTIFICATES_FILE=../../slo-tests/playground/data/ydb_certs/ca.pem`

### Create the test database

`npx ts-node src/index.ts create grpcs://localhost:2135 local`

### Run the test - for 5 min

`npx ts-node src/index.ts run grpcs://localhost:2135 local`

### Clean the baseClean the base

`npx ts-node src/index.ts cleanup grpcs://localhost:2135 local`

### What to do in case of problems

* Restart the environment

`docker compose down`

`docker compose up -d`

* Repeat the tests several times. There are floating errors because the tests
are integration tests. So the picture may vary from one run to another
2 changes: 1 addition & 1 deletion slo-workload/src/metricsJob.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Executor from './utils/Executor'

export class MetricsJob {
private intervalId: NodeJS.Timer | undefined
private intervalId: NodeJS.Timeout | undefined
private endTime: number
private promise: Promise<void>

Expand Down
2 changes: 1 addition & 1 deletion slo-workload/src/utils/RateLimiter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import NanoTimer from 'nanotimer'
export default class RateLimiter {
private delayMicroSec: number
private count: number = 0
private realRPSObserverId: NodeJS.Timer
private realRPSObserverId: NodeJS.Timeout
private returnerTimer: NanoTimer
private real: number = 0
private returner = () => {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {initDriver, destroyDriver} from '../test-utils';
import {initDriver, destroyDriver} from "../../utils/test";

describe('Connection', () => {
it('Test GRPC connection', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import Driver from '../driver';
import { destroyDriver, initDriver } from '../test-utils';
import Driver from '../../../driver';
import { Types } from '../../../types';
import {
AlterTableDescription,
AlterTableSettings,
Column,
OperationParams,
TableDescription,
TableIndex,
} from '../table';
import { Types } from '../types';
TableIndex
} from "../../../table";
import {initDriver, destroyDriver} from "../../../utils/test";

const getTableName = () => `table_alter_${Math.trunc(1000 * Math.random())}`;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
import Driver from '../driver';
import {
createTable,
destroyDriver,
fillTableWithData,
initDriver,
Row,
TABLE
} from '../test-utils';
import {Session} from '../table';
import {Ydb} from 'ydb-sdk-proto';
import Driver from '../../../driver';
import {TableSession} from "../../../table";
import {Row, initDriver, destroyDriver, createTable, fillTableWithData, TABLE} from "../../../utils/test";

async function readTable(session: Session): Promise<Row[]> {
async function readTable(session: TableSession): Promise<Row[]> {
const rows: Row[] = [];

await session.streamReadTable(TABLE, (result) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import Driver from '../driver';
import {destroyDriver, initDriver, TABLE} from '../test-utils';
import {Column, Session, TableDescription} from '../table';
import {declareType, TypedData, Types} from '../types';
import {withRetries} from '../retries';
import Driver from '../../../driver';
import {declareType, TypedData, Types} from '../../../types';
import {withRetries} from '../../../retries';
import {Column, TableSession, TableDescription} from "../../../table";
import {initDriver, destroyDriver, TABLE} from "../../../utils/test";

async function createTable(session: Session) {
async function createTable(session: TableSession) {
await session.dropTable(TABLE);
await session.createTable(
TABLE,
Expand Down Expand Up @@ -46,7 +46,7 @@ class Row extends TypedData {
}
}

export async function fillTableWithData(session: Session, rows: Row[]) {
export async function fillTableWithData(session: TableSession, rows: Row[]) {
const query = `
DECLARE $data AS List<Struct<id: Uint64, field1: Text, field2: String, field3: Yson>>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Driver from '../driver';
import {destroyDriver, initDriver} from '../test-utils';
import {Column, DescribeTableSettings, TableDescription} from '../table';
import {TypedValues, Types} from '../types';
import Driver from '../../../driver';
import {TypedValues, Types} from '../../../types';
import Long from 'long';
import {Ydb} from 'ydb-sdk-proto';
import {Column, DescribeTableSettings, TableDescription} from "../../../table";
import {initDriver, destroyDriver} from "../../../utils/test";

const getTableName = () => `table_create_${Math.trunc(100000 * Math.random())}`;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import http from 'http';
import Driver from "../driver";
import {destroyDriver, initDriver} from "../test-utils";
import {sleep} from "../utils";
import Driver from "../../../driver";

import {sleep} from "../../../utils";
import {initDriver, destroyDriver} from "../../../utils/test";

const SHUTDOWN_URL = process.env.YDB_SHUTDOWN_URL || 'http://localhost:8765/actors/kqp_proxy?force_shutdown=all';

describe('Graceful session close', () => {
xdescribe('Graceful session close', () => {
let driver: Driver;
afterAll(async () => await destroyDriver(driver));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {parseConnectionString} from '../parse-connection-string';
import {parseConnectionString} from "../../../utils/parse-connection-string";

describe('Parse connection string', () => {
it('test parseConnectionString', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
import Driver from '../driver';
import {
createTable,
destroyDriver,
fillTableWithData,
initDriver,
Row,
TABLE
} from '../test-utils';
import {ReadTableSettings, Session} from '../table';
import {TypedValues, TypedData} from '../types';
import Driver from '../../../driver';
import {TypedValues, TypedData} from '../../../types';
import {ReadTableSettings, TableSession} from "../../../table";
import {Row, initDriver, destroyDriver, createTable, fillTableWithData, TABLE} from "../../../utils/test";

async function readTable(session: Session, settings: ReadTableSettings): Promise<TypedData[]> {
async function readTable(session: TableSession, settings: ReadTableSettings): Promise<TypedData[]> {
const rows: TypedData[] = [];

await session.streamReadTable(TABLE, (result) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {Endpoint} from '../discovery';
import Driver from '../driver';
import Driver from '../../../driver';
import {
Aborted,
BadRequest,
Expand All @@ -18,11 +17,12 @@ import {
Unavailable,
Undetermined,
YdbError,
} from '../errors';
import {FallbackLogger} from '../logging';
import {RetryParameters, retryable} from '../retries';
import {destroyDriver, initDriver} from '../test-utils';
import {pessimizable} from '../utils';
} from '../../../errors';
import {FallbackLogger} from '../../../logging';
import {RetryParameters, retryable} from '../../../retries';
import {Endpoint} from "../../../discovery";
import {pessimizable} from "../../../utils";
import {initDriver, destroyDriver} from "../../../utils/test";

const logger = new FallbackLogger({level: 'error'});
class ErrorThrower {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
import Driver from '../driver';
import {
TABLE,
createTable,
destroyDriver,
fillTableWithData,
initDriver,
Row,
} from '../test-utils';
import {Session} from '../table';
import {TypedData} from '../types';

async function executeScanQuery(session: Session): Promise<TypedData[]> {
import Driver from '../../../driver';
import {TypedData} from '../../../types';
import {TableSession} from "../../../table";
import {Row, initDriver, destroyDriver, createTable, fillTableWithData, TABLE} from "../../../utils/test";

async function executeScanQuery(session: TableSession): Promise<TypedData[]> {
const query = `SELECT * FROM ${TABLE};`;

const rows: TypedData[] = [];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Long from 'long';
import {google, Ydb} from 'ydb-sdk-proto';
import Driver from '../driver';
import {initDriver, destroyDriver} from '../test-utils';
import {TypedData, TypedValues, Types} from '../types';
import Driver from '../../../driver';
import {TypedData, TypedValues, Types} from '../../../types';
import NullValue = google.protobuf.NullValue;
import {initDriver, destroyDriver} from "../../../utils/test";

describe('Types', () => {
let driver: Driver;
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/unit/AuthErrors.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@

import { FallbackLogger, setupLogger } from '../../logging';
setupLogger(new FallbackLogger({level: 'error'}))

import { ServiceError } from '@grpc/grpc-js/build/src/call';
import {IamAuthService, StaticCredentialsAuthService} from '../../credentials';
import { TransportUnavailable } from '../../errors';
import { StatusObject } from '@grpc/grpc-js';
import { Status } from '@grpc/grpc-js/build/src/constants';
import {StaticCredentialsAuthService} from "../../credentials/static-credentials-auth-service";
import {IamAuthService} from "../../credentials/iam-auth-service";

describe('Retries on errors in auth services', () => {
const mockIamCounter = {retries: 0}
Expand Down Expand Up @@ -40,7 +40,7 @@ describe('Retries on errors in auth services', () => {
throw mockCallErrorFromStatus({code: 14, details: 'My custom unavailable error', metadata: {}})
})
return service
}
}
return actual
})
require('ydb-sdk-proto')
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/unit/BackoffSettings.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {BackoffSettings} from '../../retries';
import * as utils from '../../utils';

function runTest(backoff: BackoffSettings, retries: number, min: number, max: number) {
it(`have correct value for ${retries} retries`, () => {
let timeout = -1;
Expand All @@ -16,7 +15,8 @@ function runTest(backoff: BackoffSettings, retries: number, min: number, max: nu
});
}

describe('Fast backoff', () => {
xdescribe('Fast backoff', () => {

const fast = new BackoffSettings(10, 5);

afterEach(() => {
Expand All @@ -31,7 +31,7 @@ describe('Fast backoff', () => {
runTest(fast, 11, (1 << 10) * 5 * 0.5, (1 << 10) * 5);
});

describe('Slow backoff', () => {
xdescribe('Slow backoff', () => {
const slow = new BackoffSettings(6, 1000);

afterEach(() => {
Expand Down
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export enum Events {
ENDPOINT_REMOVED = 'endpoint:removed'
}

// TODO: Remove obsolete consts and one for grpc metadata
export enum ResponseMetadataKeys {
RequestId = 'x-request-id',
ConsumedUnits = 'x-ydb-consumed-units',
Expand Down
Loading
Loading