teraslice 2.17.2 → 2.17.4
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/cluster-service.js
CHANGED
|
@@ -3,6 +3,7 @@ import { shutdownHandler } from './dist/src/lib/workers/helpers/worker-shutdown.
|
|
|
3
3
|
import { makeTerafoundationContext } from './dist/src/lib/workers/context/terafoundation-context.js';
|
|
4
4
|
import { ClusterMaster } from './dist/src/lib/cluster/cluster_master.js';
|
|
5
5
|
import { AssetsService } from './dist/src/lib/cluster/services/index.js';
|
|
6
|
+
import { makeLogger } from './dist/src/lib/workers/helpers/terafoundation.js';
|
|
6
7
|
|
|
7
8
|
class Service {
|
|
8
9
|
constructor(context) {
|
|
@@ -42,6 +43,7 @@ class Service {
|
|
|
42
43
|
|
|
43
44
|
async function main() {
|
|
44
45
|
const context = await makeTerafoundationContext();
|
|
46
|
+
context.logger = makeLogger(context, 'cluster-service');
|
|
45
47
|
const cmd = new Service(context);
|
|
46
48
|
|
|
47
49
|
cmd.shutdownHandler = shutdownHandler(context, () => {
|
|
@@ -6,7 +6,7 @@ import { RecoveryCleanupType } from '@terascope/job-components';
|
|
|
6
6
|
import { parseErrorInfo, parseList, logError, TSError, startsWith, pWhile, isKey } from '@terascope/utils';
|
|
7
7
|
import { ExecutionStatusEnum } from '@terascope/types';
|
|
8
8
|
import { makeLogger } from '../../workers/helpers/terafoundation.js';
|
|
9
|
-
import {
|
|
9
|
+
import { makeTable, sendError, handleTerasliceRequest, getSearchOptions, createJobActiveQuery, addDeletedToQuery } from '../../utils/api_utils.js';
|
|
10
10
|
import { getPackageJSON } from '../../utils/file_utils.js';
|
|
11
11
|
const terasliceVersion = getPackageJSON().version;
|
|
12
12
|
function validateCleanupType(cleanupType) {
|
|
@@ -391,14 +391,10 @@ export class ApiService {
|
|
|
391
391
|
requestHandler(async () => executionService.getExecutionContext(exId));
|
|
392
392
|
});
|
|
393
393
|
v1routes.get('/cluster/stats', (req, res) => {
|
|
394
|
-
const { name: cluster } = this.context.sysconfig.teraslice;
|
|
395
394
|
const requestHandler = handleTerasliceRequest(req, res, 'Could not get cluster statistics');
|
|
396
395
|
requestHandler(async () => {
|
|
397
|
-
const stats =
|
|
398
|
-
|
|
399
|
-
return makePrometheus(stats, { cluster });
|
|
400
|
-
}
|
|
401
|
-
// for backwards compatability (unsupported for prometheus)
|
|
396
|
+
const stats = executionService.getClusterAnalytics();
|
|
397
|
+
// for backwards compatability
|
|
402
398
|
// @ts-expect-error
|
|
403
399
|
stats.slicer = stats.controllers;
|
|
404
400
|
return stats;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Table from 'easy-table';
|
|
2
|
-
import { parseErrorInfo, parseList, logError, isString, get, toInteger, TSError
|
|
2
|
+
import { parseErrorInfo, parseList, logError, isString, get, toInteger, TSError } from '@terascope/utils';
|
|
3
3
|
export function makeTable(req, defaults, data, mappingFn) {
|
|
4
4
|
const query = fieldsQuery(req.query, defaults);
|
|
5
5
|
let emptyChar = 'N/A';
|
|
@@ -74,46 +74,6 @@ export function sendError(res, code, message, logger) {
|
|
|
74
74
|
message
|
|
75
75
|
});
|
|
76
76
|
}
|
|
77
|
-
// NOTE: This only works for counters, if you're trying to extend this, you
|
|
78
|
-
// should probably switch to using prom-client.
|
|
79
|
-
export function makePrometheus(stats, defaultLabels = {}) {
|
|
80
|
-
const metricMapping = {
|
|
81
|
-
processed: 'teraslice_slices_processed',
|
|
82
|
-
failed: 'teraslice_slices_failed',
|
|
83
|
-
queued: 'teraslice_slices_queued',
|
|
84
|
-
job_duration: '', // this isn't really useful, omitting
|
|
85
|
-
workers_joined: 'teraslice_workers_joined',
|
|
86
|
-
workers_disconnected: 'teraslice_workers_disconnected',
|
|
87
|
-
workers_reconnected: 'teraslice_workers_reconnected'
|
|
88
|
-
};
|
|
89
|
-
let returnString = '';
|
|
90
|
-
Object.entries(stats.controllers).forEach(([key, value]) => {
|
|
91
|
-
if (isKey(metricMapping, key)) {
|
|
92
|
-
const name = metricMapping[key];
|
|
93
|
-
if (name !== '') {
|
|
94
|
-
returnString += `# TYPE ${name} counter\n`;
|
|
95
|
-
const labels = makePrometheusLabels(defaultLabels);
|
|
96
|
-
returnString += `${name}${labels} ${value}\n`;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
return returnString;
|
|
101
|
-
}
|
|
102
|
-
function makePrometheusLabels(defaults = {}) {
|
|
103
|
-
const labels = Object.assign({}, defaults);
|
|
104
|
-
const keys = Object.keys(labels);
|
|
105
|
-
if (!keys.length)
|
|
106
|
-
return '';
|
|
107
|
-
const labelsStr = keys.map((key) => {
|
|
108
|
-
const val = labels[key];
|
|
109
|
-
return `${key}="${val}"`;
|
|
110
|
-
}).join(',');
|
|
111
|
-
return `{${labelsStr}}`;
|
|
112
|
-
}
|
|
113
|
-
export function isPrometheusTerasliceRequest(req) {
|
|
114
|
-
const acceptHeader = get(req, 'headers.accept', '');
|
|
115
|
-
return acceptHeader && acceptHeader.indexOf('application/openmetrics-text;') > -1;
|
|
116
|
-
}
|
|
117
77
|
function parseQueryInt(req, key, defaultVal) {
|
|
118
78
|
const val = req.query[key];
|
|
119
79
|
if (val == null || val === '')
|
|
@@ -1,66 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createJobActiveQuery, addDeletedToQuery } from '../../src/lib/utils/api_utils.js';
|
|
2
2
|
describe('apiUtils', () => {
|
|
3
|
-
it('should be able make a prometheus text format', () => {
|
|
4
|
-
const stats = {
|
|
5
|
-
controllers: {
|
|
6
|
-
processed: 1000,
|
|
7
|
-
failed: 10,
|
|
8
|
-
queued: 5,
|
|
9
|
-
job_duration: 10,
|
|
10
|
-
workers_joined: 20,
|
|
11
|
-
workers_disconnected: 30,
|
|
12
|
-
workers_reconnected: 40
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
const r = `# TYPE teraslice_slices_processed counter
|
|
16
|
-
teraslice_slices_processed ${stats.controllers.processed}
|
|
17
|
-
# TYPE teraslice_slices_failed counter
|
|
18
|
-
teraslice_slices_failed ${stats.controllers.failed}
|
|
19
|
-
# TYPE teraslice_slices_queued counter
|
|
20
|
-
teraslice_slices_queued ${stats.controllers.queued}
|
|
21
|
-
# TYPE teraslice_workers_joined counter
|
|
22
|
-
teraslice_workers_joined ${stats.controllers.workers_joined}
|
|
23
|
-
# TYPE teraslice_workers_disconnected counter
|
|
24
|
-
teraslice_workers_disconnected ${stats.controllers.workers_disconnected}
|
|
25
|
-
# TYPE teraslice_workers_reconnected counter
|
|
26
|
-
teraslice_workers_reconnected ${stats.controllers.workers_reconnected}
|
|
27
|
-
`;
|
|
28
|
-
expect(makePrometheus(stats)).toEqual(r);
|
|
29
|
-
});
|
|
30
|
-
it('should be able make a prometheus text format with labels', () => {
|
|
31
|
-
const stats = {
|
|
32
|
-
controllers: {
|
|
33
|
-
processed: 1000,
|
|
34
|
-
failed: 10,
|
|
35
|
-
queued: 5,
|
|
36
|
-
job_duration: 10,
|
|
37
|
-
workers_joined: 20,
|
|
38
|
-
workers_disconnected: 30,
|
|
39
|
-
workers_reconnected: 40
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
const r = `# TYPE teraslice_slices_processed counter
|
|
43
|
-
teraslice_slices_processed{foo="bar"} ${stats.controllers.processed}
|
|
44
|
-
# TYPE teraslice_slices_failed counter
|
|
45
|
-
teraslice_slices_failed{foo="bar"} ${stats.controllers.failed}
|
|
46
|
-
# TYPE teraslice_slices_queued counter
|
|
47
|
-
teraslice_slices_queued{foo="bar"} ${stats.controllers.queued}
|
|
48
|
-
# TYPE teraslice_workers_joined counter
|
|
49
|
-
teraslice_workers_joined{foo="bar"} ${stats.controllers.workers_joined}
|
|
50
|
-
# TYPE teraslice_workers_disconnected counter
|
|
51
|
-
teraslice_workers_disconnected{foo="bar"} ${stats.controllers.workers_disconnected}
|
|
52
|
-
# TYPE teraslice_workers_reconnected counter
|
|
53
|
-
teraslice_workers_reconnected{foo="bar"} ${stats.controllers.workers_reconnected}
|
|
54
|
-
`;
|
|
55
|
-
expect(makePrometheus(stats, { foo: 'bar' })).toEqual(r);
|
|
56
|
-
});
|
|
57
|
-
it('should be able to detect if a request is prometheus', () => {
|
|
58
|
-
expect(isPrometheusTerasliceRequest({
|
|
59
|
-
headers: {
|
|
60
|
-
accept: 'blah application/openmetrics-text; blah blah'
|
|
61
|
-
}
|
|
62
|
-
})).toBeTruthy();
|
|
63
|
-
});
|
|
64
3
|
it('should be able to create the proper job queries', () => {
|
|
65
4
|
let query;
|
|
66
5
|
query = createJobActiveQuery('true');
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "teraslice",
|
|
3
3
|
"displayName": "Teraslice",
|
|
4
|
-
"version": "2.17.
|
|
4
|
+
"version": "2.17.4",
|
|
5
5
|
"description": "Distributed computing platform for processing JSON data",
|
|
6
6
|
"homepage": "https://github.com/terascope/teraslice#readme",
|
|
7
7
|
"bugs": {
|
|
@@ -35,16 +35,16 @@
|
|
|
35
35
|
"test:watch": "TEST_ELASTICSEARCH='true' node ../scripts/bin/ts-scripts test --watch ../teraslice --"
|
|
36
36
|
},
|
|
37
37
|
"resolutions": {
|
|
38
|
-
"debug": "~4.4.
|
|
38
|
+
"debug": "~4.4.3",
|
|
39
39
|
"ms": "~2.1.3"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@kubernetes/client-node": "~1.3.0",
|
|
43
|
-
"@terascope/elasticsearch-api": "~4.
|
|
44
|
-
"@terascope/job-components": "~1.
|
|
45
|
-
"@terascope/teraslice-messaging": "~1.
|
|
46
|
-
"@terascope/types": "~1.4.
|
|
47
|
-
"@terascope/utils": "~1.
|
|
43
|
+
"@terascope/elasticsearch-api": "~4.13.1",
|
|
44
|
+
"@terascope/job-components": "~1.12.4",
|
|
45
|
+
"@terascope/teraslice-messaging": "~1.13.4",
|
|
46
|
+
"@terascope/types": "~1.4.4",
|
|
47
|
+
"@terascope/utils": "~1.10.4",
|
|
48
48
|
"async-mutex": "~0.5.0",
|
|
49
49
|
"barbe": "~3.0.17",
|
|
50
50
|
"body-parser": "~2.2.0",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"fs-extra": "~11.3.1",
|
|
56
56
|
"gc-stats": "1.4.1",
|
|
57
57
|
"get-port": "~7.1.0",
|
|
58
|
-
"got": "~14.4.
|
|
58
|
+
"got": "~14.4.8",
|
|
59
59
|
"ip": "~2.0.1",
|
|
60
60
|
"kubernetes-client": "~9.0.0",
|
|
61
61
|
"ms": "~2.1.3",
|
|
@@ -63,11 +63,11 @@
|
|
|
63
63
|
"semver": "~7.7.2",
|
|
64
64
|
"socket.io": "~1.7.4",
|
|
65
65
|
"socket.io-client": "~1.7.4",
|
|
66
|
-
"terafoundation": "~1.
|
|
67
|
-
"uuid": "~
|
|
66
|
+
"terafoundation": "~1.15.4",
|
|
67
|
+
"uuid": "~13.0.0"
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
70
|
-
"@terascope/opensearch-client": "~1.
|
|
70
|
+
"@terascope/opensearch-client": "~1.1.4",
|
|
71
71
|
"@types/archiver": "~6.0.3",
|
|
72
72
|
"@types/express": "~5.0.3",
|
|
73
73
|
"@types/gc-stats": "~1.4.3",
|
package/worker-service.js
CHANGED
|
@@ -7,6 +7,7 @@ import { makeExecutionContext } from './dist/src/lib/workers/context/execution-c
|
|
|
7
7
|
import { makeTerafoundationContext } from './dist/src/lib/workers/context/terafoundation-context.js';
|
|
8
8
|
import { ExecutionController } from './dist/src/lib/workers/execution-controller/index.js';
|
|
9
9
|
import { Worker } from './dist/src/lib/workers/worker/index.js';
|
|
10
|
+
import { makeLogger } from './dist/src/lib/workers/helpers/terafoundation.js';
|
|
10
11
|
|
|
11
12
|
class Service {
|
|
12
13
|
constructor(context) {
|
|
@@ -69,6 +70,7 @@ class Service {
|
|
|
69
70
|
|
|
70
71
|
async function main() {
|
|
71
72
|
const context = await makeTerafoundationContext();
|
|
73
|
+
context.logger = makeLogger(context, 'worker-service');
|
|
72
74
|
const cmd = new Service(context);
|
|
73
75
|
|
|
74
76
|
cmd.shutdownHandler = shutdownHandler(context, (event, err) => {
|