@terascope/job-components 0.75.1 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/builtin/collect/interfaces.d.ts +2 -2
- package/dist/src/builtin/collect/interfaces.d.ts.map +1 -1
- package/dist/src/builtin/collect/interfaces.js +1 -2
- package/dist/src/builtin/collect/processor.d.ts +4 -4
- package/dist/src/builtin/collect/processor.d.ts.map +1 -1
- package/dist/src/builtin/collect/processor.js +5 -7
- package/dist/src/builtin/collect/processor.js.map +1 -1
- package/dist/src/builtin/collect/schema.d.ts +2 -2
- package/dist/src/builtin/collect/schema.d.ts.map +1 -1
- package/dist/src/builtin/collect/schema.js +2 -5
- package/dist/src/builtin/collect/schema.js.map +1 -1
- package/dist/src/builtin/delay/interfaces.d.ts +1 -1
- package/dist/src/builtin/delay/interfaces.d.ts.map +1 -1
- package/dist/src/builtin/delay/interfaces.js +1 -2
- package/dist/src/builtin/delay/processor.d.ts +2 -2
- package/dist/src/builtin/delay/processor.d.ts.map +1 -1
- package/dist/src/builtin/delay/processor.js +4 -7
- package/dist/src/builtin/delay/processor.js.map +1 -1
- package/dist/src/builtin/delay/schema.d.ts +2 -2
- package/dist/src/builtin/delay/schema.d.ts.map +1 -1
- package/dist/src/builtin/delay/schema.js +2 -5
- package/dist/src/builtin/delay/schema.js.map +1 -1
- package/dist/src/builtin/index.d.ts +5 -5
- package/dist/src/builtin/index.d.ts.map +1 -1
- package/dist/src/builtin/index.js +6 -16
- package/dist/src/builtin/index.js.map +1 -1
- package/dist/src/builtin/noop/processor.d.ts +1 -1
- package/dist/src/builtin/noop/processor.d.ts.map +1 -1
- package/dist/src/builtin/noop/processor.js +2 -5
- package/dist/src/builtin/noop/processor.js.map +1 -1
- package/dist/src/builtin/noop/schema.d.ts +1 -1
- package/dist/src/builtin/noop/schema.d.ts.map +1 -1
- package/dist/src/builtin/noop/schema.js +2 -5
- package/dist/src/builtin/noop/schema.js.map +1 -1
- package/dist/src/builtin/test-reader/data/fetcher-data.d.ts +1 -1
- package/dist/src/builtin/test-reader/data/fetcher-data.d.ts.map +1 -1
- package/dist/src/builtin/test-reader/data/fetcher-data.js +1 -2
- package/dist/src/builtin/test-reader/data/fetcher-data.js.map +1 -1
- package/dist/src/builtin/test-reader/data/slicer-data.d.ts +1 -1
- package/dist/src/builtin/test-reader/data/slicer-data.d.ts.map +1 -1
- package/dist/src/builtin/test-reader/data/slicer-data.js +1 -2
- package/dist/src/builtin/test-reader/data/slicer-data.js.map +1 -1
- package/dist/src/builtin/test-reader/fetcher.d.ts +3 -3
- package/dist/src/builtin/test-reader/fetcher.d.ts.map +1 -1
- package/dist/src/builtin/test-reader/fetcher.js +12 -21
- package/dist/src/builtin/test-reader/fetcher.js.map +1 -1
- package/dist/src/builtin/test-reader/interfaces.d.ts +1 -1
- package/dist/src/builtin/test-reader/interfaces.d.ts.map +1 -1
- package/dist/src/builtin/test-reader/interfaces.js +1 -2
- package/dist/src/builtin/test-reader/schema.d.ts +2 -2
- package/dist/src/builtin/test-reader/schema.d.ts.map +1 -1
- package/dist/src/builtin/test-reader/schema.js +2 -5
- package/dist/src/builtin/test-reader/schema.js.map +1 -1
- package/dist/src/builtin/test-reader/slicer.d.ts +3 -3
- package/dist/src/builtin/test-reader/slicer.d.ts.map +1 -1
- package/dist/src/builtin/test-reader/slicer.js +10 -19
- package/dist/src/builtin/test-reader/slicer.js.map +1 -1
- package/dist/src/config-validators.d.ts +1 -1
- package/dist/src/config-validators.d.ts.map +1 -1
- package/dist/src/config-validators.js +10 -19
- package/dist/src/config-validators.js.map +1 -1
- package/dist/src/execution-context/api.d.ts +4 -5
- package/dist/src/execution-context/api.d.ts.map +1 -1
- package/dist/src/execution-context/api.js +16 -16
- package/dist/src/execution-context/api.js.map +1 -1
- package/dist/src/execution-context/base.d.ts +6 -6
- package/dist/src/execution-context/base.d.ts.map +1 -1
- package/dist/src/execution-context/base.js +30 -27
- package/dist/src/execution-context/base.js.map +1 -1
- package/dist/src/execution-context/index.d.ts +9 -12
- package/dist/src/execution-context/index.d.ts.map +1 -1
- package/dist/src/execution-context/index.js +16 -44
- package/dist/src/execution-context/index.js.map +1 -1
- package/dist/src/execution-context/interfaces.d.ts +2 -2
- package/dist/src/execution-context/interfaces.d.ts.map +1 -1
- package/dist/src/execution-context/interfaces.js +1 -2
- package/dist/src/execution-context/slicer.d.ts +5 -4
- package/dist/src/execution-context/slicer.d.ts.map +1 -1
- package/dist/src/execution-context/slicer.js +20 -20
- package/dist/src/execution-context/slicer.js.map +1 -1
- package/dist/src/execution-context/utils.d.ts +1 -1
- package/dist/src/execution-context/utils.d.ts.map +1 -1
- package/dist/src/execution-context/utils.js +5 -11
- package/dist/src/execution-context/utils.js.map +1 -1
- package/dist/src/execution-context/worker.d.ts +6 -5
- package/dist/src/execution-context/worker.d.ts.map +1 -1
- package/dist/src/execution-context/worker.js +50 -68
- package/dist/src/execution-context/worker.js.map +1 -1
- package/dist/src/formats.d.ts +2 -2
- package/dist/src/formats.d.ts.map +1 -1
- package/dist/src/formats.js +21 -27
- package/dist/src/formats.js.map +1 -1
- package/dist/src/index.d.ts +12 -12
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +13 -29
- package/dist/src/index.js.map +1 -1
- package/dist/src/interfaces/context.d.ts +23 -140
- package/dist/src/interfaces/context.d.ts.map +1 -1
- package/dist/src/interfaces/context.js +1 -2
- package/dist/src/interfaces/index.d.ts +4 -5
- package/dist/src/interfaces/index.d.ts.map +1 -1
- package/dist/src/interfaces/index.js +4 -21
- package/dist/src/interfaces/index.js.map +1 -1
- package/dist/src/interfaces/misc.d.ts +3 -0
- package/dist/src/interfaces/misc.d.ts.map +1 -1
- package/dist/src/interfaces/misc.js +2 -2
- package/dist/src/interfaces/misc.js.map +1 -1
- package/dist/src/interfaces/operation-lifecycle.d.ts +4 -3
- package/dist/src/interfaces/operation-lifecycle.d.ts.map +1 -1
- package/dist/src/interfaces/operation-lifecycle.js +1 -2
- package/dist/src/interfaces/operations.d.ts +11 -64
- package/dist/src/interfaces/operations.d.ts.map +1 -1
- package/dist/src/interfaces/operations.js +1 -4
- package/dist/src/interfaces/operations.js.map +1 -1
- package/dist/src/job-schemas.d.ts +1 -1
- package/dist/src/job-schemas.d.ts.map +1 -1
- package/dist/src/job-schemas.js +32 -39
- package/dist/src/job-schemas.js.map +1 -1
- package/dist/src/job-validator.d.ts +3 -2
- package/dist/src/job-validator.d.ts.map +1 -1
- package/dist/src/job-validator.js +19 -20
- package/dist/src/job-validator.js.map +1 -1
- package/dist/src/operation-loader/index.d.ts +2 -2
- package/dist/src/operation-loader/index.d.ts.map +1 -1
- package/dist/src/operation-loader/index.js +2 -18
- package/dist/src/operation-loader/index.js.map +1 -1
- package/dist/src/operation-loader/interfaces.d.ts +1 -1
- package/dist/src/operation-loader/interfaces.d.ts.map +1 -1
- package/dist/src/operation-loader/interfaces.js +15 -18
- package/dist/src/operation-loader/interfaces.js.map +1 -1
- package/dist/src/operation-loader/loader.d.ts +7 -9
- package/dist/src/operation-loader/loader.d.ts.map +1 -1
- package/dist/src/operation-loader/loader.js +96 -137
- package/dist/src/operation-loader/loader.js.map +1 -1
- package/dist/src/operations/api-factory.d.ts +2 -2
- package/dist/src/operations/api-factory.d.ts.map +1 -1
- package/dist/src/operations/api-factory.js +4 -13
- package/dist/src/operations/api-factory.js.map +1 -1
- package/dist/src/operations/batch-processor.d.ts +2 -2
- package/dist/src/operations/batch-processor.d.ts.map +1 -1
- package/dist/src/operations/batch-processor.js +5 -11
- package/dist/src/operations/batch-processor.js.map +1 -1
- package/dist/src/operations/convict-schema.d.ts +2 -2
- package/dist/src/operations/convict-schema.d.ts.map +1 -1
- package/dist/src/operations/convict-schema.js +11 -15
- package/dist/src/operations/convict-schema.js.map +1 -1
- package/dist/src/operations/core/api-core.d.ts +4 -4
- package/dist/src/operations/core/api-core.d.ts.map +1 -1
- package/dist/src/operations/core/api-core.js +7 -10
- package/dist/src/operations/core/api-core.js.map +1 -1
- package/dist/src/operations/core/core.d.ts +2 -2
- package/dist/src/operations/core/core.d.ts.map +1 -1
- package/dist/src/operations/core/core.js +5 -4
- package/dist/src/operations/core/core.js.map +1 -1
- package/dist/src/operations/core/fetcher-core.d.ts +2 -2
- package/dist/src/operations/core/fetcher-core.d.ts.map +1 -1
- package/dist/src/operations/core/fetcher-core.js +2 -8
- package/dist/src/operations/core/fetcher-core.js.map +1 -1
- package/dist/src/operations/core/index.d.ts +6 -6
- package/dist/src/operations/core/index.d.ts.map +1 -1
- package/dist/src/operations/core/index.js +7 -18
- package/dist/src/operations/core/index.js.map +1 -1
- package/dist/src/operations/core/operation-core.d.ts +5 -5
- package/dist/src/operations/core/operation-core.d.ts.map +1 -1
- package/dist/src/operations/core/operation-core.js +8 -11
- package/dist/src/operations/core/operation-core.js.map +1 -1
- package/dist/src/operations/core/processor-core.d.ts +2 -2
- package/dist/src/operations/core/processor-core.d.ts.map +1 -1
- package/dist/src/operations/core/processor-core.js +2 -8
- package/dist/src/operations/core/processor-core.js.map +1 -1
- package/dist/src/operations/core/schema-core.d.ts +1 -1
- package/dist/src/operations/core/schema-core.d.ts.map +1 -1
- package/dist/src/operations/core/schema-core.js +3 -4
- package/dist/src/operations/core/schema-core.js.map +1 -1
- package/dist/src/operations/core/slicer-core.d.ts +4 -4
- package/dist/src/operations/core/slicer-core.d.ts.map +1 -1
- package/dist/src/operations/core/slicer-core.js +13 -14
- package/dist/src/operations/core/slicer-core.js.map +1 -1
- package/dist/src/operations/each-processor.d.ts +2 -2
- package/dist/src/operations/each-processor.d.ts.map +1 -1
- package/dist/src/operations/each-processor.js +2 -8
- package/dist/src/operations/each-processor.js.map +1 -1
- package/dist/src/operations/fetcher.d.ts +2 -2
- package/dist/src/operations/fetcher.d.ts.map +1 -1
- package/dist/src/operations/fetcher.js +4 -10
- package/dist/src/operations/fetcher.js.map +1 -1
- package/dist/src/operations/filter-processor.d.ts +2 -2
- package/dist/src/operations/filter-processor.d.ts.map +1 -1
- package/dist/src/operations/filter-processor.js +2 -8
- package/dist/src/operations/filter-processor.js.map +1 -1
- package/dist/src/operations/index.d.ts +14 -15
- package/dist/src/operations/index.d.ts.map +1 -1
- package/dist/src/operations/index.js +15 -47
- package/dist/src/operations/index.js.map +1 -1
- package/dist/src/operations/interfaces.d.ts +12 -12
- package/dist/src/operations/interfaces.d.ts.map +1 -1
- package/dist/src/operations/interfaces.js +1 -2
- package/dist/src/operations/job-observer.d.ts +3 -3
- package/dist/src/operations/job-observer.d.ts.map +1 -1
- package/dist/src/operations/job-observer.js +14 -10
- package/dist/src/operations/job-observer.js.map +1 -1
- package/dist/src/operations/map-processor.d.ts +2 -2
- package/dist/src/operations/map-processor.d.ts.map +1 -1
- package/dist/src/operations/map-processor.js +4 -10
- package/dist/src/operations/map-processor.js.map +1 -1
- package/dist/src/operations/observer.d.ts +2 -2
- package/dist/src/operations/observer.d.ts.map +1 -1
- package/dist/src/operations/observer.js +2 -8
- package/dist/src/operations/observer.js.map +1 -1
- package/dist/src/operations/operation-api.d.ts +2 -2
- package/dist/src/operations/operation-api.d.ts.map +1 -1
- package/dist/src/operations/operation-api.js +2 -8
- package/dist/src/operations/operation-api.js.map +1 -1
- package/dist/src/operations/parallel-slicer.d.ts +2 -2
- package/dist/src/operations/parallel-slicer.d.ts.map +1 -1
- package/dist/src/operations/parallel-slicer.js +7 -16
- package/dist/src/operations/parallel-slicer.js.map +1 -1
- package/dist/src/operations/slicer.d.ts +2 -2
- package/dist/src/operations/slicer.d.ts.map +1 -1
- package/dist/src/operations/slicer.js +7 -16
- package/dist/src/operations/slicer.js.map +1 -1
- package/dist/src/register-apis.d.ts +2 -3
- package/dist/src/register-apis.d.ts.map +1 -1
- package/dist/src/register-apis.js +17 -49
- package/dist/src/register-apis.js.map +1 -1
- package/dist/src/test-helpers.d.ts +11 -31
- package/dist/src/test-helpers.d.ts.map +1 -1
- package/dist/src/test-helpers.js +67 -150
- package/dist/src/test-helpers.js.map +1 -1
- package/dist/src/utils.d.ts +1 -1
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +9 -14
- package/dist/src/utils.js.map +1 -1
- package/package.json +10 -7
- package/dist/src/interfaces/jobs.d.ts +0 -171
- package/dist/src/interfaces/jobs.d.ts.map +0 -1
- package/dist/src/interfaces/jobs.js +0 -10
- package/dist/src/interfaces/jobs.js.map +0 -1
- package/dist/src/operations/shims/index.d.ts +0 -9
- package/dist/src/operations/shims/index.d.ts.map +0 -1
- package/dist/src/operations/shims/index.js +0 -21
- package/dist/src/operations/shims/index.js.map +0 -1
- package/dist/src/operations/shims/legacy-processor-shim.d.ts +0 -5
- package/dist/src/operations/shims/legacy-processor-shim.d.ts.map +0 -1
- package/dist/src/operations/shims/legacy-processor-shim.js +0 -50
- package/dist/src/operations/shims/legacy-processor-shim.js.map +0 -1
- package/dist/src/operations/shims/legacy-reader-shim.d.ts +0 -7
- package/dist/src/operations/shims/legacy-reader-shim.d.ts.map +0 -1
- package/dist/src/operations/shims/legacy-reader-shim.js +0 -66
- package/dist/src/operations/shims/legacy-reader-shim.js.map +0 -1
- package/dist/src/operations/shims/legacy-slice-events-shim.d.ts +0 -10
- package/dist/src/operations/shims/legacy-slice-events-shim.d.ts.map +0 -1
- package/dist/src/operations/shims/legacy-slice-events-shim.js +0 -34
- package/dist/src/operations/shims/legacy-slice-events-shim.js.map +0 -1
- package/dist/src/operations/shims/operation-api-shim.d.ts +0 -7
- package/dist/src/operations/shims/operation-api-shim.d.ts.map +0 -1
- package/dist/src/operations/shims/operation-api-shim.js +0 -10
- package/dist/src/operations/shims/operation-api-shim.js.map +0 -1
- package/dist/src/operations/shims/processor-shim.d.ts +0 -4
- package/dist/src/operations/shims/processor-shim.d.ts.map +0 -1
- package/dist/src/operations/shims/processor-shim.js +0 -51
- package/dist/src/operations/shims/processor-shim.js.map +0 -1
- package/dist/src/operations/shims/reader-shim.d.ts +0 -4
- package/dist/src/operations/shims/reader-shim.d.ts.map +0 -1
- package/dist/src/operations/shims/reader-shim.js +0 -92
- package/dist/src/operations/shims/reader-shim.js.map +0 -1
- package/dist/src/operations/shims/schema-shim.d.ts +0 -4
- package/dist/src/operations/shims/schema-shim.d.ts.map +0 -1
- package/dist/src/operations/shims/schema-shim.js +0 -31
- package/dist/src/operations/shims/schema-shim.js.map +0 -1
- package/dist/src/operations/shims/shim-utils.d.ts +0 -9
- package/dist/src/operations/shims/shim-utils.d.ts.map +0 -1
- package/dist/src/operations/shims/shim-utils.js +0 -34
- package/dist/src/operations/shims/shim-utils.js.map +0 -1
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { Context, ValidatedJobConfig, ExecutionConfig, OpConfig, GetClientConfig } from './interfaces';
|
|
1
|
+
import { Context, ValidatedJobConfig, ExecutionConfig, OpConfig, GetClientConfig } from './interfaces/index.js';
|
|
2
2
|
/** Get the first opConfig from an operation name */
|
|
3
3
|
export declare function getOpConfig(job: ValidatedJobConfig, name: string): OpConfig | undefined;
|
|
4
4
|
export declare function getAssetPath(assetDirs: string[], assets: string[], name: string): Promise<string>;
|
|
5
|
-
export declare function getClient(context: Context, config: GetClientConfig, type: string): any
|
|
6
|
-
export declare function getClientAsync(context: Context, config: GetClientConfig, type: string): Promise<any>;
|
|
5
|
+
export declare function getClient(context: Context, config: GetClientConfig, type: string): Promise<any>;
|
|
7
6
|
export declare function registerApis(context: Context, job: ValidatedJobConfig | ExecutionConfig, assetIds?: string[]): void;
|
|
8
7
|
//# sourceMappingURL=register-apis.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register-apis.d.ts","sourceRoot":"","sources":["../../src/register-apis.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"register-apis.d.ts","sourceRoot":"","sources":["../../src/register-apis.ts"],"names":[],"mappings":"AAIA,OAAO,EACH,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAC5C,QAAQ,EAAE,eAAe,EAC5B,MAAM,uBAAuB,CAAC;AAG/B,oDAAoD;AACpD,wBAAgB,WAAW,CAAC,GAAG,EAAE,kBAAkB,EAAE,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS,CAEvF;AAGD,wBAAsB,YAAY,CAC9B,SAAS,EAAE,MAAM,EAAE,EACnB,MAAM,EAAE,MAAM,EAAE,EAChB,IAAI,EAAE,MAAM,GACb,OAAO,CAAC,MAAM,CAAC,CA6BjB;AAYD,wBAAsB,SAAS,CAC3B,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,eAAe,EACvB,IAAI,EAAE,MAAM,GACb,OAAO,CAAC,GAAG,CAAC,CAkBd;AAED,wBAAgB,YAAY,CACxB,OAAO,EAAE,OAAO,EAChB,GAAG,EAAE,kBAAkB,GAAG,eAAe,EACzC,QAAQ,CAAC,EAAE,MAAM,EAAE,GACpB,IAAI,CAkCN"}
|
|
@@ -1,20 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.registerApis = exports.getClientAsync = exports.getClient = exports.getAssetPath = exports.getOpConfig = void 0;
|
|
7
|
-
const fs_1 = __importDefault(require("fs"));
|
|
8
|
-
const path_1 = __importDefault(require("path"));
|
|
9
|
-
const utils_1 = require("@terascope/utils");
|
|
10
|
-
const execution_context_1 = require("./execution-context");
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { parseJSON, castArray } from '@terascope/utils';
|
|
4
|
+
import { ExecutionContextAPI } from './execution-context/index.js';
|
|
11
5
|
/** Get the first opConfig from an operation name */
|
|
12
|
-
function getOpConfig(job, name) {
|
|
6
|
+
export function getOpConfig(job, name) {
|
|
13
7
|
return job.operations.find((op) => op._op === name);
|
|
14
8
|
}
|
|
15
|
-
exports.getOpConfig = getOpConfig;
|
|
16
9
|
/* Get the asset path from a asset name or ID */
|
|
17
|
-
async function getAssetPath(assetDirs, assets, name) {
|
|
10
|
+
export async function getAssetPath(assetDirs, assets, name) {
|
|
18
11
|
if (assetDirs.length === 0) {
|
|
19
12
|
throw new Error('No asset_directory has been configured, cannot get asset path');
|
|
20
13
|
}
|
|
@@ -24,50 +17,27 @@ async function getAssetPath(assetDirs, assets, name) {
|
|
|
24
17
|
}
|
|
25
18
|
for (const assetDir of assetDirs) {
|
|
26
19
|
if (name.length === 40) {
|
|
27
|
-
const assetPath =
|
|
28
|
-
if (
|
|
20
|
+
const assetPath = path.join(assetDir, name);
|
|
21
|
+
if (fs.existsSync(assetDir))
|
|
29
22
|
return assetPath;
|
|
30
23
|
}
|
|
31
24
|
const [assetName] = name.split(':').map((s) => s.trim());
|
|
32
25
|
for (const id of assetIds) {
|
|
33
|
-
const rawAssetJSON =
|
|
34
|
-
const assetJSON =
|
|
26
|
+
const rawAssetJSON = fs.readFileSync(path.join(assetDir, id, 'asset.json'));
|
|
27
|
+
const assetJSON = parseJSON(rawAssetJSON);
|
|
35
28
|
if (assetJSON.name === assetName) {
|
|
36
|
-
return
|
|
29
|
+
return path.join(assetDir, id);
|
|
37
30
|
}
|
|
38
31
|
}
|
|
39
32
|
}
|
|
40
33
|
throw new Error(`Unable to find asset "${name}"`);
|
|
41
34
|
}
|
|
42
|
-
exports.getAssetPath = getAssetPath;
|
|
43
|
-
/*
|
|
44
|
-
* This will request a connection based on the 'connection' attribute of an opConfig.
|
|
45
|
-
* Intended as a context API endpoint. Use getClientAsync for elasticsearch connections
|
|
46
|
-
*/
|
|
47
|
-
function getClient(context, config, type) {
|
|
48
|
-
const clientConfig = {
|
|
49
|
-
type,
|
|
50
|
-
cached: true,
|
|
51
|
-
endpoint: 'default',
|
|
52
|
-
};
|
|
53
|
-
if (config && config.connection) {
|
|
54
|
-
clientConfig.endpoint = config.connection || 'default';
|
|
55
|
-
const isCached = config.connection_cache != null;
|
|
56
|
-
clientConfig.cached = isCached ? config.connection_cache : true;
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
clientConfig.endpoint = 'default';
|
|
60
|
-
clientConfig.cached = true;
|
|
61
|
-
}
|
|
62
|
-
return context.foundation.getConnection(clientConfig).client;
|
|
63
|
-
}
|
|
64
|
-
exports.getClient = getClient;
|
|
65
35
|
/*
|
|
66
36
|
* This will request a connection based on the 'connection' attribute of
|
|
67
37
|
* an opConfig. Used to create new client types for elasticsearch, not for use
|
|
68
38
|
* for other connection types other than elasticsearch-next
|
|
69
39
|
*/
|
|
70
|
-
async function
|
|
40
|
+
export async function getClient(context, config, type) {
|
|
71
41
|
const clientConfig = {
|
|
72
42
|
type,
|
|
73
43
|
cached: true,
|
|
@@ -85,22 +55,21 @@ async function getClientAsync(context, config, type) {
|
|
|
85
55
|
const { client } = await context.apis.foundation.createClient(clientConfig);
|
|
86
56
|
return client;
|
|
87
57
|
}
|
|
88
|
-
|
|
89
|
-
function registerApis(context, job, assetIds) {
|
|
58
|
+
export function registerApis(context, job, assetIds) {
|
|
90
59
|
const cleanupApis = ['op_runner', 'executionContext', 'job_runner', 'assets'];
|
|
91
60
|
for (const api of cleanupApis) {
|
|
92
61
|
if (context.apis[api] != null) {
|
|
93
62
|
delete context.apis[api];
|
|
94
63
|
}
|
|
95
64
|
}
|
|
96
|
-
context.apis.registerAPI('executionContext', new
|
|
65
|
+
context.apis.registerAPI('executionContext', new ExecutionContextAPI(context, job));
|
|
97
66
|
context.apis.registerAPI('op_runner', {
|
|
98
|
-
// DEPRECATED, PLEASE USE "getClientAsync"
|
|
99
67
|
getClient(config, type) {
|
|
100
68
|
return getClient(context, config, type);
|
|
101
69
|
},
|
|
70
|
+
// For backward compatibility, but it will not show up on the type
|
|
102
71
|
getClientAsync(config, type) {
|
|
103
|
-
return
|
|
72
|
+
return getClient(context, config, type);
|
|
104
73
|
},
|
|
105
74
|
});
|
|
106
75
|
context.apis.registerAPI('job_runner', {
|
|
@@ -108,12 +77,11 @@ function registerApis(context, job, assetIds) {
|
|
|
108
77
|
return getOpConfig(job, name);
|
|
109
78
|
},
|
|
110
79
|
});
|
|
111
|
-
const assetDir =
|
|
80
|
+
const assetDir = castArray(context.sysconfig.teraslice.assets_directory);
|
|
112
81
|
context.apis.registerAPI('assets', {
|
|
113
82
|
getPath(name) {
|
|
114
83
|
return getAssetPath(assetDir, assetIds || job.assets, name);
|
|
115
84
|
},
|
|
116
85
|
});
|
|
117
86
|
}
|
|
118
|
-
exports.registerApis = registerApis;
|
|
119
87
|
//# sourceMappingURL=register-apis.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register-apis.js","sourceRoot":"","sources":["../../src/register-apis.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"register-apis.js","sourceRoot":"","sources":["../../src/register-apis.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAMxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AAEnE,oDAAoD;AACpD,MAAM,UAAU,WAAW,CAAC,GAAuB,EAAE,IAAY;IAC7D,OAAO,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,EAAY,EAAE,EAAE,CAAC,EAAE,CAAC,GAAG,KAAK,IAAI,CAAC,CAAC;AAClE,CAAC;AAED,gDAAgD;AAChD,MAAM,CAAC,KAAK,UAAU,YAAY,CAC9B,SAAmB,EACnB,MAAgB,EAChB,IAAY;IAEZ,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE;QACxB,MAAM,IAAI,KAAK,CAAC,+DAA+D,CAAC,CAAC;KACpF;IAED,MAAM,QAAQ,GAAG,MAAM,IAAI,EAAE,CAAC;IAE9B,IAAI,CAAC,IAAI,EAAE;QACP,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC;KACzC;IAED,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE;QAC9B,IAAI,IAAI,CAAC,MAAM,KAAK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AS,CAAC,SAAS,CAAC,gBAAgB,CAAC,CAAC;IAEjF,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE;QAC/B,OAAO,CAAC,IAAY;YAChB,OAAO,YAAY,CAAC,QAAQ,EAAE,QAAQ,IAAI,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QAChE,CAAC;KACJ,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -1,52 +1,32 @@
|
|
|
1
|
+
import { Terafoundation } from '@terascope/types';
|
|
1
2
|
import { Logger } from '@terascope/utils';
|
|
2
|
-
import
|
|
3
|
-
import * as i from './interfaces';
|
|
3
|
+
import * as i from './interfaces/index.js';
|
|
4
4
|
export declare function newTestSlice(request?: i.SliceRequest): i.Slice;
|
|
5
|
-
export declare function newTestJobConfig(defaults?: Partial<i.
|
|
6
|
-
export declare function newTestExecutionConfig(jobConfig?: Partial<i.
|
|
7
|
-
/**
|
|
8
|
-
* Create a new Execution Context
|
|
9
|
-
* @deprecated use the new WorkerExecutionContext and SlicerExecutionContext
|
|
10
|
-
*/
|
|
11
|
-
export declare function newTestExecutionContext(type: i.Assignment, config: i.ExecutionConfig): i.LegacyExecutionContext;
|
|
5
|
+
export declare function newTestJobConfig(defaults?: Partial<i.JobConfigParams>): i.ValidatedJobConfig;
|
|
6
|
+
export declare function newTestExecutionConfig(jobConfig?: Partial<i.JobConfigParams>): i.ExecutionConfig;
|
|
12
7
|
export interface CachedClients {
|
|
13
8
|
[prop: string]: any;
|
|
14
9
|
}
|
|
15
|
-
export interface
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
createClient?: i.CreateClientFactoryFn;
|
|
19
|
-
config?: Record<string, any>;
|
|
20
|
-
endpoint?: string;
|
|
21
|
-
}
|
|
22
|
-
export interface TestClientsByEndpoint {
|
|
23
|
-
[endpoint: string]: any;
|
|
24
|
-
}
|
|
25
|
-
export interface TestClients {
|
|
26
|
-
[type: string]: TestClientsByEndpoint;
|
|
27
|
-
}
|
|
28
|
-
export interface TestContextAPIs extends i.ContextAPIs {
|
|
29
|
-
setTestClients(clients: TestClientConfig[]): void;
|
|
30
|
-
getTestClients(): TestClients;
|
|
10
|
+
export interface TestContextAPIs extends i.ExecutionContextAPIs {
|
|
11
|
+
setTestClients(clients: i.TestClientConfig[]): void;
|
|
12
|
+
getTestClients(): i.TestClients;
|
|
31
13
|
scrapePromMetrics(): Promise<string>;
|
|
32
14
|
}
|
|
33
15
|
export interface MockPromMetrics {
|
|
34
|
-
metricList:
|
|
16
|
+
metricList: Terafoundation.MetricList;
|
|
35
17
|
defaultLabels: Record<string, string>;
|
|
36
18
|
prefix: string;
|
|
37
19
|
}
|
|
38
|
-
export declare function getLabelKey(labels: Record<string, string>): string;
|
|
39
20
|
export interface TestContextOptions {
|
|
40
21
|
assignment?: i.Assignment;
|
|
41
|
-
clients?: TestClientConfig[];
|
|
22
|
+
clients?: i.TestClientConfig[];
|
|
42
23
|
cluster_manager_type?: i.ClusterManagerType;
|
|
43
24
|
}
|
|
44
25
|
export declare class TestContext implements i.Context {
|
|
45
26
|
logger: Logger;
|
|
46
27
|
sysconfig: i.SysConfig;
|
|
47
|
-
cluster:
|
|
48
|
-
apis:
|
|
49
|
-
foundation: i.LegacyFoundationApis;
|
|
28
|
+
cluster: Terafoundation.Cluster;
|
|
29
|
+
apis: i.TestContextApis & Terafoundation.ContextAPIs;
|
|
50
30
|
name: string;
|
|
51
31
|
assignment: i.Assignment;
|
|
52
32
|
platform: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-helpers.d.ts","sourceRoot":"","sources":["../../src/test-helpers.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"test-helpers.d.ts","sourceRoot":"","sources":["../../src/test-helpers.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAEsB,MAAM,EAElC,MAAM,kBAAkB,CAAC;AAI1B,OAAO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;IACrD,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,CAAC,CAAC,UAAU,CAAY;IACpC,QAAQ,EAAE,MAAM,CAAoB;IACpC,IAAI,EAAE,MAAM,CAAgB;IAC5B,eAAe,EAAE,eAAe,GAAG,IAAI,CAAC;gBAE5B,QAAQ,EAAE,MAAM,EAAE,OAAO,GAAE,kBAAuB;CAkbjE"}
|
package/dist/src/test-helpers.js
CHANGED
|
@@ -1,50 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.TestContext = exports.getLabelKey = exports.newTestExecutionContext = exports.newTestExecutionConfig = exports.newTestJobConfig = exports.newTestSlice = void 0;
|
|
30
|
-
const path_1 = __importDefault(require("path"));
|
|
31
|
-
const events_1 = require("events");
|
|
32
|
-
const utils_1 = require("@terascope/utils");
|
|
33
|
-
const prom_client_1 = __importStar(require("prom-client"));
|
|
34
|
-
function newId(prefix) {
|
|
35
|
-
return `${prefix}-${(0, utils_1.random)(10000, 99999)}`;
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { EventEmitter } from 'node:events';
|
|
3
|
+
import { random, isString, getTypeOf, isFunction, debugLogger, makeISODate } from '@terascope/utils';
|
|
4
|
+
import promClient, { Counter, Gauge, Histogram, Summary } from 'prom-client';
|
|
5
|
+
function newId() {
|
|
6
|
+
return random(10000, 99999);
|
|
36
7
|
}
|
|
37
|
-
function newTestSlice(request = {}) {
|
|
8
|
+
export function newTestSlice(request = {}) {
|
|
38
9
|
return {
|
|
39
|
-
slice_id:
|
|
40
|
-
slicer_id:
|
|
41
|
-
slicer_order:
|
|
10
|
+
slice_id: `slice-id-${newId()}`,
|
|
11
|
+
slicer_id: random(0, 99999),
|
|
12
|
+
slicer_order: random(0, 99999),
|
|
42
13
|
request,
|
|
43
|
-
_created:
|
|
14
|
+
_created: makeISODate(),
|
|
44
15
|
};
|
|
45
16
|
}
|
|
46
|
-
|
|
47
|
-
function newTestJobConfig(defaults = {}) {
|
|
17
|
+
export function newTestJobConfig(defaults = {}) {
|
|
48
18
|
return Object.assign({
|
|
49
19
|
name: 'test-job',
|
|
50
20
|
apis: [],
|
|
@@ -61,46 +31,19 @@ function newTestJobConfig(defaults = {}) {
|
|
|
61
31
|
env_vars: {}
|
|
62
32
|
}, defaults);
|
|
63
33
|
}
|
|
64
|
-
|
|
65
|
-
function newTestExecutionConfig(jobConfig = {}) {
|
|
34
|
+
export function newTestExecutionConfig(jobConfig = {}) {
|
|
66
35
|
const exConfig = newTestJobConfig(jobConfig);
|
|
67
36
|
exConfig.slicer_hostname = 'example.com';
|
|
68
|
-
exConfig.slicer_port =
|
|
69
|
-
exConfig.ex_id =
|
|
70
|
-
exConfig.job_id =
|
|
37
|
+
exConfig.slicer_port = random(8000, 60000);
|
|
38
|
+
exConfig.ex_id = `ex-id-${newId()}`;
|
|
39
|
+
exConfig.job_id = `job-id-${newId()}`;
|
|
71
40
|
if (!exConfig.metadata)
|
|
72
41
|
exConfig.metadata = {};
|
|
73
42
|
return exConfig;
|
|
74
43
|
}
|
|
75
|
-
exports.newTestExecutionConfig = newTestExecutionConfig;
|
|
76
|
-
/**
|
|
77
|
-
* Create a new Execution Context
|
|
78
|
-
* @deprecated use the new WorkerExecutionContext and SlicerExecutionContext
|
|
79
|
-
*/
|
|
80
|
-
function newTestExecutionContext(type, config) {
|
|
81
|
-
if (type === 'execution_controller') {
|
|
82
|
-
return {
|
|
83
|
-
config,
|
|
84
|
-
queue: [],
|
|
85
|
-
reader: null,
|
|
86
|
-
slicer: () => { },
|
|
87
|
-
dynamicQueueLength: false,
|
|
88
|
-
queueLength: 10000,
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
return {
|
|
92
|
-
config,
|
|
93
|
-
queue: config.operations.map(() => () => { }),
|
|
94
|
-
reader: () => { },
|
|
95
|
-
slicer: () => { },
|
|
96
|
-
dynamicQueueLength: false,
|
|
97
|
-
queueLength: 10000,
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
exports.newTestExecutionContext = newTestExecutionContext;
|
|
101
44
|
function getKey(opts) {
|
|
102
45
|
const { type, endpoint = 'default' } = opts;
|
|
103
|
-
if (!
|
|
46
|
+
if (!isString(type))
|
|
104
47
|
throw new Error('A type must be specified when registering a Client');
|
|
105
48
|
return `${type}:${endpoint}`;
|
|
106
49
|
}
|
|
@@ -117,48 +60,44 @@ function setConnectorConfig(sysconfig, opts, config, override = true) {
|
|
|
117
60
|
}
|
|
118
61
|
return connectors[type][endpoint];
|
|
119
62
|
}
|
|
120
|
-
function isPromise(p) {
|
|
121
|
-
if (p && typeof p === 'object' && typeof (p === null || p === void 0 ? void 0 : p.then) === 'function') {
|
|
122
|
-
return true;
|
|
123
|
-
}
|
|
124
|
-
return false;
|
|
125
|
-
}
|
|
126
|
-
function getLabelKey(labels) {
|
|
127
|
-
let labelKey = '';
|
|
128
|
-
for (const [key, value] of Object.entries(labels).sort()) {
|
|
129
|
-
labelKey += `${key}:${value},`;
|
|
130
|
-
}
|
|
131
|
-
return labelKey;
|
|
132
|
-
}
|
|
133
|
-
exports.getLabelKey = getLabelKey;
|
|
134
63
|
const _cachedClients = new WeakMap();
|
|
135
64
|
const _createClientFns = new WeakMap();
|
|
136
|
-
class TestContext {
|
|
65
|
+
export class TestContext {
|
|
66
|
+
logger;
|
|
67
|
+
sysconfig;
|
|
68
|
+
cluster;
|
|
69
|
+
apis;
|
|
70
|
+
name;
|
|
71
|
+
assignment = 'worker';
|
|
72
|
+
platform = process.platform;
|
|
73
|
+
arch = process.arch;
|
|
74
|
+
mockPromMetrics;
|
|
137
75
|
constructor(testName, options = {}) {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
this.arch = process.arch;
|
|
141
|
-
const logger = (0, utils_1.debugLogger)(testName);
|
|
142
|
-
const events = new events_1.EventEmitter();
|
|
76
|
+
const logger = debugLogger(testName);
|
|
77
|
+
const events = new EventEmitter();
|
|
143
78
|
this.name = testName;
|
|
144
79
|
if (options.assignment) {
|
|
145
80
|
this.assignment = options.assignment;
|
|
146
81
|
}
|
|
147
82
|
this.logger = logger;
|
|
148
83
|
this.cluster = {
|
|
84
|
+
// @ts-expect-error
|
|
149
85
|
worker: {
|
|
150
|
-
id: newId(
|
|
86
|
+
id: newId(),
|
|
151
87
|
},
|
|
152
88
|
};
|
|
153
89
|
const sysconfig = {
|
|
154
90
|
terafoundation: {
|
|
91
|
+
workers: 8,
|
|
92
|
+
environment: 'test',
|
|
93
|
+
log_path: '',
|
|
94
|
+
log_level: { console: 'debug' },
|
|
95
|
+
logging: ['console'],
|
|
155
96
|
connectors: {
|
|
156
97
|
'elasticsearch-next': {
|
|
157
98
|
default: {}
|
|
158
99
|
},
|
|
159
100
|
},
|
|
160
|
-
asset_storage_connection_type: 'elasticsearch-next',
|
|
161
|
-
asset_storage_connection: 'default',
|
|
162
101
|
prom_metrics_enabled: false,
|
|
163
102
|
prom_metrics_port: 3333,
|
|
164
103
|
prom_metrics_add_default: true,
|
|
@@ -166,7 +105,7 @@ class TestContext {
|
|
|
166
105
|
teraslice: {
|
|
167
106
|
action_timeout: 10000,
|
|
168
107
|
analytics_rate: 10000,
|
|
169
|
-
assets_directory:
|
|
108
|
+
assets_directory: path.join(process.cwd(), 'assets'),
|
|
170
109
|
asset_storage_connection_type: 'elasticsearch-next',
|
|
171
110
|
asset_storage_connection: 'default',
|
|
172
111
|
asset_storage_bucket: '',
|
|
@@ -194,7 +133,7 @@ class TestContext {
|
|
|
194
133
|
worker_disconnect_timeout: 3000,
|
|
195
134
|
workers: 1,
|
|
196
135
|
},
|
|
197
|
-
_nodeName: `${newId(
|
|
136
|
+
_nodeName: `${testName}-${newId()}__${this?.cluster?.worker?.id}`,
|
|
198
137
|
};
|
|
199
138
|
this.sysconfig = sysconfig;
|
|
200
139
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
@@ -207,31 +146,9 @@ class TestContext {
|
|
|
207
146
|
makeLogger(...params) {
|
|
208
147
|
return logger.child(params[0]);
|
|
209
148
|
},
|
|
210
|
-
|
|
211
|
-
const
|
|
212
|
-
|
|
213
|
-
const key = getKey(opts);
|
|
214
|
-
if (cached && cachedClients[key] != null) {
|
|
215
|
-
return cachedClients[key];
|
|
216
|
-
}
|
|
217
|
-
const clientFns = _createClientFns.get(ctx) || {};
|
|
218
|
-
const create = clientFns[key];
|
|
219
|
-
if (!create)
|
|
220
|
-
throw new Error(`No client was found for connection "${key}"`);
|
|
221
|
-
if (!(0, utils_1.isFunction)(create)) {
|
|
222
|
-
const actual = (0, utils_1.getTypeOf)(create);
|
|
223
|
-
throw new Error(`Registered Client for connection "${key}" is not a function, got ${actual}`);
|
|
224
|
-
}
|
|
225
|
-
const config = setConnectorConfig(sysconfig, opts, {}, false);
|
|
226
|
-
const client = create(config, logger, opts);
|
|
227
|
-
if (isPromise(client)) {
|
|
228
|
-
throw new Error('Cannot call a sync client creation method using an async function, please use createClient instead');
|
|
229
|
-
}
|
|
230
|
-
if (client) {
|
|
231
|
-
cachedClients[key] = client;
|
|
232
|
-
}
|
|
233
|
-
_cachedClients.set(ctx, cachedClients);
|
|
234
|
-
return client;
|
|
149
|
+
startWorkers() {
|
|
150
|
+
const workers = [];
|
|
151
|
+
return workers;
|
|
235
152
|
},
|
|
236
153
|
async createClient(opts) {
|
|
237
154
|
const { cached } = opts;
|
|
@@ -244,8 +161,8 @@ class TestContext {
|
|
|
244
161
|
const create = clientFns[key];
|
|
245
162
|
if (!create)
|
|
246
163
|
throw new Error(`No client was found for connection "${key}"`);
|
|
247
|
-
if (!
|
|
248
|
-
const actual =
|
|
164
|
+
if (!isFunction(create)) {
|
|
165
|
+
const actual = getTypeOf(create);
|
|
249
166
|
throw new Error(`Registered Client for connection "${key}" is not a function, got ${actual}`);
|
|
250
167
|
}
|
|
251
168
|
const connectorConfig = setConnectorConfig(ctx.sysconfig, opts, {}, false);
|
|
@@ -277,7 +194,7 @@ class TestContext {
|
|
|
277
194
|
prefix: finalPrefix,
|
|
278
195
|
labels: defaultLabels
|
|
279
196
|
};
|
|
280
|
-
|
|
197
|
+
promClient.collectDefaultMetrics(defaultMetricsConfig);
|
|
281
198
|
}
|
|
282
199
|
if (job_prom_metrics_enabled === true
|
|
283
200
|
|| (job_prom_metrics_enabled === undefined && tf_prom_metrics_enabled)) {
|
|
@@ -297,7 +214,7 @@ class TestContext {
|
|
|
297
214
|
if (!metric || !metric.functions || !metric.metric) {
|
|
298
215
|
throw new Error(`Metric ${name} is not setup`);
|
|
299
216
|
}
|
|
300
|
-
if (metric.metric instanceof
|
|
217
|
+
if (metric.metric instanceof Gauge) {
|
|
301
218
|
const labelValues = Object.keys(labels).map((key) => labels[key]);
|
|
302
219
|
const res = metric.metric.labels(...labelValues.concat(Object.values(this.getDefaultLabels())));
|
|
303
220
|
res.set(value);
|
|
@@ -313,8 +230,8 @@ class TestContext {
|
|
|
313
230
|
if (!metric || !metric.functions || !metric.metric) {
|
|
314
231
|
throw new Error(`Metric ${name} is not setup`);
|
|
315
232
|
}
|
|
316
|
-
if (metric.metric instanceof
|
|
317
|
-
|| metric.metric instanceof
|
|
233
|
+
if (metric.metric instanceof Counter
|
|
234
|
+
|| metric.metric instanceof Gauge) {
|
|
318
235
|
const labelValues = Object.keys(labels).map((key) => labels[key]);
|
|
319
236
|
const res = metric.metric.labels(...labelValues.concat(Object.values(this.getDefaultLabels())));
|
|
320
237
|
res.inc(value);
|
|
@@ -330,7 +247,7 @@ class TestContext {
|
|
|
330
247
|
if (!metric || !metric.functions || !metric.metric) {
|
|
331
248
|
throw new Error(`Metric ${name} is not setup`);
|
|
332
249
|
}
|
|
333
|
-
if (metric.metric instanceof
|
|
250
|
+
if (metric.metric instanceof Gauge) {
|
|
334
251
|
const labelValues = Object.keys(labels).map((key) => labels[key]);
|
|
335
252
|
const res = metric.metric.labels(...labelValues.concat(Object.values(this.getDefaultLabels())));
|
|
336
253
|
res.dec(value);
|
|
@@ -346,8 +263,8 @@ class TestContext {
|
|
|
346
263
|
if (!metric || !metric.functions || !metric.metric) {
|
|
347
264
|
throw new Error(`Metric ${name} is not setup`);
|
|
348
265
|
}
|
|
349
|
-
if (metric.metric instanceof
|
|
350
|
-
|| metric.metric instanceof
|
|
266
|
+
if (metric.metric instanceof Summary
|
|
267
|
+
|| metric.metric instanceof Histogram) {
|
|
351
268
|
const labelValues = Object.keys(labels).map((key) => labels[key]);
|
|
352
269
|
const res = metric.metric.labels(...labelValues.concat(Object.values(this.getDefaultLabels())));
|
|
353
270
|
res.observe(value);
|
|
@@ -361,7 +278,7 @@ class TestContext {
|
|
|
361
278
|
if (ctx.mockPromMetrics) {
|
|
362
279
|
if (!this.hasMetric(name)) {
|
|
363
280
|
const fullname = ctx.mockPromMetrics.prefix + name;
|
|
364
|
-
const gauge = new
|
|
281
|
+
const gauge = new Gauge({
|
|
365
282
|
name: fullname,
|
|
366
283
|
help,
|
|
367
284
|
labelNames,
|
|
@@ -382,7 +299,7 @@ class TestContext {
|
|
|
382
299
|
if (ctx.mockPromMetrics) {
|
|
383
300
|
if (!this.hasMetric(name)) {
|
|
384
301
|
const fullname = ctx.mockPromMetrics.prefix + name;
|
|
385
|
-
const counter = new
|
|
302
|
+
const counter = new Counter({
|
|
386
303
|
name: fullname,
|
|
387
304
|
help,
|
|
388
305
|
labelNames,
|
|
@@ -403,7 +320,7 @@ class TestContext {
|
|
|
403
320
|
if (ctx.mockPromMetrics) {
|
|
404
321
|
if (!this.hasMetric(name)) {
|
|
405
322
|
const fullname = ctx.mockPromMetrics.prefix + name;
|
|
406
|
-
const histogram = new
|
|
323
|
+
const histogram = new Histogram({
|
|
407
324
|
name: fullname,
|
|
408
325
|
help,
|
|
409
326
|
labelNames,
|
|
@@ -425,7 +342,7 @@ class TestContext {
|
|
|
425
342
|
if (ctx.mockPromMetrics) {
|
|
426
343
|
if (!this.hasMetric(name)) {
|
|
427
344
|
const fullname = ctx.mockPromMetrics.prefix + name;
|
|
428
|
-
const summary = new
|
|
345
|
+
const summary = new Summary({
|
|
429
346
|
name: fullname,
|
|
430
347
|
help,
|
|
431
348
|
labelNames,
|
|
@@ -457,7 +374,7 @@ class TestContext {
|
|
|
457
374
|
const fullname = ctx.mockPromMetrics.prefix + name;
|
|
458
375
|
if (ctx.mockPromMetrics.metricList[name]) {
|
|
459
376
|
deleted = delete ctx.mockPromMetrics.metricList[name];
|
|
460
|
-
|
|
377
|
+
promClient.register.removeSingleMetric(fullname);
|
|
461
378
|
}
|
|
462
379
|
else {
|
|
463
380
|
throw new Error(`metric ${name} not defined in metric list`);
|
|
@@ -485,12 +402,12 @@ class TestContext {
|
|
|
485
402
|
},
|
|
486
403
|
setTestClients(clients = []) {
|
|
487
404
|
clients.forEach((clientConfig) => {
|
|
488
|
-
const {
|
|
489
|
-
const createFN = createClient
|
|
405
|
+
const { createClient, config: connectionConfig = {} } = clientConfig;
|
|
406
|
+
const createFN = createClient;
|
|
490
407
|
const clientFns = _createClientFns.get(ctx) || {};
|
|
491
408
|
const key = getKey(clientConfig);
|
|
492
|
-
if (!
|
|
493
|
-
const actual =
|
|
409
|
+
if (!isFunction(createFN)) {
|
|
410
|
+
const actual = getTypeOf(createFN);
|
|
494
411
|
throw new Error(`Test Client for connection "${key}" is not a function, got ${actual}`);
|
|
495
412
|
}
|
|
496
413
|
ctx.logger.trace(`Setting test client for connection "${key}"`, connectionConfig);
|
|
@@ -516,18 +433,18 @@ class TestContext {
|
|
|
516
433
|
},
|
|
517
434
|
async scrapePromMetrics() {
|
|
518
435
|
if (ctx.mockPromMetrics) {
|
|
519
|
-
return
|
|
436
|
+
return promClient.register.metrics();
|
|
520
437
|
}
|
|
521
438
|
return '';
|
|
522
439
|
},
|
|
440
|
+
op_runner: {},
|
|
441
|
+
assets: {},
|
|
442
|
+
job_runner: {},
|
|
443
|
+
executionContext: {}
|
|
523
444
|
};
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
makeLogger: this.apis.foundation.makeLogger,
|
|
528
|
-
};
|
|
529
|
-
this.apis.setTestClients(options.clients);
|
|
445
|
+
if (options.clients) {
|
|
446
|
+
this.apis.setTestClients(options.clients);
|
|
447
|
+
}
|
|
530
448
|
}
|
|
531
449
|
}
|
|
532
|
-
exports.TestContext = TestContext;
|
|
533
450
|
//# sourceMappingURL=test-helpers.js.map
|