@weave-js/core 0.10.0 → 0.11.0
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/lib/ExtendableError.js +33 -0
- package/lib/broker/context.js +12 -0
- package/lib/broker/{default-options.js → defaultOptions.js} +22 -4
- package/lib/broker/index.js +218 -192
- package/lib/{build-runtime.js → buildRuntime.js} +16 -16
- package/lib/cache/base.js +33 -28
- package/lib/cache/inMemory.js +140 -0
- package/lib/cache/index.js +1 -1
- package/lib/cache/lock.js +21 -4
- package/lib/constants.js +7 -4
- package/lib/{error-handler.js → errorHandler.js} +0 -0
- package/lib/errors.js +16 -9
- package/lib/helper/{define-action.js → defineAction.js} +3 -1
- package/lib/helper/{define-broker-options.js → defineBrokerOptions.js} +2 -0
- package/lib/helper/{define-service.js → defineService.js} +4 -1
- package/lib/index.js +13 -9
- package/lib/logger/format/asHumanReadable.js +4 -3
- package/lib/logger/index.js +4 -1
- package/lib/logger/levels.js +2 -1
- package/lib/logger/tools.js +4 -0
- package/lib/logger/utils/format.js +18 -4
- package/lib/metrics/constants.js +1 -1
- package/lib/metrics/types/gauge.js +1 -1
- package/lib/middlewares/action-hooks/index.js +59 -11
- package/lib/middlewares/bulkhead/index.js +2 -1
- package/lib/middlewares/cache/index.js +80 -0
- package/lib/middlewares/circuit-breaker/index.js +38 -13
- package/lib/middlewares/index.js +1 -0
- package/lib/middlewares/metrics/index.js +1 -1
- package/lib/middlewares/timeout/index.js +2 -2
- package/lib/middlewares/tracing/index.js +24 -11
- package/lib/middlewares/tracing/tags.js +43 -0
- package/lib/middlewares/validator/index.js +1 -1
- package/lib/registry/{action-endpoint.js → actionEndpoint.js} +0 -0
- package/lib/registry/collections/{action-collection.js → actionCollection.js} +1 -1
- package/lib/registry/collections/{endpoint-collection.js → endpointCollection.js} +2 -3
- package/lib/registry/collections/{event-collection.js → eventCollection.js} +4 -8
- package/lib/registry/collections/{node-collection.js → nodeCollection.js} +0 -0
- package/lib/registry/collections/{service-collection.js → serviceCollection.js} +1 -1
- package/lib/registry/{event-endpoint.js → eventEndpoint.js} +0 -0
- package/lib/registry/registry.js +9 -22
- package/lib/registry/service/service.js +2 -2
- package/lib/registry/{service-item.js → serviceItem.js} +0 -0
- package/lib/runtime/{init-action-invoker.js → initActionInvoker.js} +1 -1
- package/lib/runtime/{init-cache.js → initCache.js} +0 -0
- package/lib/runtime/{init-context-factory.js → initContextFactory.js} +0 -0
- package/lib/runtime/{init-eventbus.js → initEventbus.js} +8 -7
- package/lib/runtime/{init-logger.js → initLogger.js} +0 -0
- package/lib/runtime/{init-metrics.js → initMetrics.js} +11 -10
- package/lib/runtime/{init-middleware-manager.js → initMiddlewareManager.js} +0 -0
- package/lib/runtime/{init-registry.js → initRegistry.js} +0 -0
- package/lib/runtime/{init-service-manager.js → initServiceManager.js} +0 -0
- package/lib/runtime/{init-tracing.js → initTracing.js} +2 -1
- package/lib/runtime/{init-transport.js → initTransport.js} +0 -0
- package/lib/runtime/{init-uuid-factory.js → initUuidFactory.js} +0 -0
- package/lib/runtime/{init-validator.js → initValidator.js} +0 -0
- package/lib/tracing/collectors/base.js +11 -19
- package/lib/tracing/collectors/event.js +2 -2
- package/lib/tracing/collectors/index.js +2 -2
- package/lib/tracing/span.js +8 -6
- package/lib/transport/InboundTransformStream.js +75 -0
- package/lib/transport/adapters/{adapter-base.js → adapteBase.js} +15 -0
- package/lib/transport/adapters/adapters.js +1 -1
- package/lib/transport/adapters/dummy/index.js +2 -2
- package/lib/transport/adapters/tcp/discovery/index.js +45 -31
- package/lib/transport/adapters/tcp/index.js +20 -13
- package/lib/transport/adapters/tcp/tcpReader.js +1 -0
- package/lib/transport/adapters/tcp/tcpWriteStream.js +1 -1
- package/lib/transport/adapters/tcp/tcpWriter.js +2 -2
- package/lib/transport/createMessage.js +11 -0
- package/lib/transport/createTransport.js +214 -171
- package/lib/transport/errorPayloadFactory.js +18 -0
- package/lib/transport/{message-handlers.js → messageHandlers.js} +91 -22
- package/lib/transport/messageTypes.js +23 -0
- package/lib/types.js +49 -49
- package/lib/utils/options.js +4 -2
- package/lib/utils/{restore-error.js → restoreError.js} +1 -1
- package/package.json +6 -12
- package/CHANGELOG.md +0 -1334
- package/lib/cache/memory.js +0 -121
- package/lib/middlewares/tracing/buildTags.js +0 -17
- package/lib/new-errors.js +0 -25
- package/lib/tracing/collectors/console.js +0 -34
- package/lib/tracing/index.js +0 -3
- package/lib/tracing/tracer.js +0 -64
- package/lib/transport/message-types.js +0 -59
- package/lib/transport/message.js +0 -16
package/lib/cache/base.js
CHANGED
|
@@ -39,8 +39,8 @@ function registerCacheMetrics (metrics) {
|
|
|
39
39
|
|
|
40
40
|
exports.createCacheBase = (runtime, options) => {
|
|
41
41
|
const cache = {
|
|
42
|
+
isConnected: false,
|
|
42
43
|
runtime,
|
|
43
|
-
options,
|
|
44
44
|
options: Object.assign({
|
|
45
45
|
ttl: null
|
|
46
46
|
}, options),
|
|
@@ -107,36 +107,41 @@ exports.createCacheBase = (runtime, options) => {
|
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
cache.middleware = () => {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
110
|
+
// cache.middleware = (runtime) => {
|
|
111
|
+
// return {
|
|
112
|
+
// localAction: (handler, action) => {
|
|
113
|
+
// const cacheOptions = Object.assign({ enabled: true }, isObject(action.cache) ? action.cache : { enabled: !!action.cache })
|
|
114
|
+
// if (cacheOptions.enabled) {
|
|
115
|
+
// return function cacheMiddleware (context, serviceInjections) {
|
|
116
|
+
// const cacheHashKey = runtime.cache.getCachingHash(action.name, context.data, context.meta, action.cache.keys)
|
|
117
|
+
// context.isCachedResult = false
|
|
118
118
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
119
|
+
// if (context.meta.$noCache === true) {
|
|
120
|
+
// return handler(context, serviceInjections)
|
|
121
|
+
// }
|
|
122
122
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}
|
|
123
|
+
// if (runtime.cache.isConnected === false) {
|
|
124
|
+
// runtime.cache.log('Cache adapter is not connected yet. Call handler...')
|
|
125
|
+
// return handler(context, serviceInjections)
|
|
126
|
+
// }
|
|
128
127
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
}
|
|
128
|
+
// return runtime.cache.get(cacheHashKey).then((cachedResult) => {
|
|
129
|
+
// if (cachedResult !== null) {
|
|
130
|
+
// context.isCachedResult = true
|
|
131
|
+
// return cachedResult
|
|
132
|
+
// }
|
|
133
|
+
|
|
134
|
+
// return handler(context, serviceInjections).then((result) => {
|
|
135
|
+
// runtime.cache.set(cacheHashKey, result, action.cache.ttl)
|
|
136
|
+
// return result
|
|
137
|
+
// })
|
|
138
|
+
// })
|
|
139
|
+
// }
|
|
140
|
+
// }
|
|
141
|
+
// return handler
|
|
142
|
+
// }
|
|
143
|
+
// }
|
|
144
|
+
// }
|
|
140
145
|
|
|
141
146
|
return cache
|
|
142
147
|
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Author: Kevin Ries (kevin@fachw3rk.de)
|
|
3
|
+
* -----
|
|
4
|
+
* Copyright 2021 Fachwerk
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const { match } = require('@weave-js/utils')
|
|
8
|
+
const { createCacheBase } = require('./base')
|
|
9
|
+
const { createLock } = require('./lock')
|
|
10
|
+
const Constants = require('../metrics/constants')
|
|
11
|
+
|
|
12
|
+
const makeInMemoryCache = (runtime, options = {}) => {
|
|
13
|
+
const base = createCacheBase(runtime, options)
|
|
14
|
+
const storage = new Map()
|
|
15
|
+
const name = 'Memory'
|
|
16
|
+
|
|
17
|
+
const lock = createLock()
|
|
18
|
+
|
|
19
|
+
const timer = setInterval(() => {
|
|
20
|
+
checkTtl()
|
|
21
|
+
}, 3000)
|
|
22
|
+
|
|
23
|
+
timer.unref()
|
|
24
|
+
|
|
25
|
+
// if a new broker gets connected, we need to clear the cache
|
|
26
|
+
runtime.bus.on('$transport.connected', () => {
|
|
27
|
+
base.log.debug('Transport adapter connected. Cache will be cleared.')
|
|
28
|
+
cache.clear()
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
const checkTtl = () => {
|
|
32
|
+
const now = Date.now()
|
|
33
|
+
|
|
34
|
+
storage.forEach((item, hashKey) => {
|
|
35
|
+
if (item.expire && item.expire < now) {
|
|
36
|
+
cache.log.debug(`Delete ${hashKey}`)
|
|
37
|
+
storage.delete(hashKey)
|
|
38
|
+
}
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const cache = Object.assign(
|
|
43
|
+
{},
|
|
44
|
+
base,
|
|
45
|
+
{
|
|
46
|
+
name,
|
|
47
|
+
init () {
|
|
48
|
+
base.init()
|
|
49
|
+
cache.isConnected = true
|
|
50
|
+
},
|
|
51
|
+
get (cacheKey) {
|
|
52
|
+
base.log.debug(`Get ${cacheKey}`)
|
|
53
|
+
|
|
54
|
+
if (base.metrics) {
|
|
55
|
+
base.metrics.increment(Constants.CACHE_GET_TOTAL)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const item = storage.get(cacheKey)
|
|
59
|
+
|
|
60
|
+
if (item) {
|
|
61
|
+
cache.log.debug(`Found ${cacheKey}`)
|
|
62
|
+
|
|
63
|
+
if (base.metrics) {
|
|
64
|
+
base.metrics.increment(Constants.CACHE_FOUND_TOTAL)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (item.expire && item.expire < Date.now()) {
|
|
68
|
+
cache.log.debug(`Delete ${cacheKey}`)
|
|
69
|
+
storage.delete(cacheKey)
|
|
70
|
+
if (base.metrics) {
|
|
71
|
+
base.metrics.increment(Constants.CACHE_EXPIRED_TOTAL)
|
|
72
|
+
}
|
|
73
|
+
return Promise.resolve(null)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return Promise.resolve(item.data)
|
|
77
|
+
}
|
|
78
|
+
return Promise.resolve(null)
|
|
79
|
+
},
|
|
80
|
+
set (hashKey, data, ttl) {
|
|
81
|
+
if (base.metrics) {
|
|
82
|
+
base.metrics.increment(Constants.CACHE_SET_TOTAL)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (ttl == null) {
|
|
86
|
+
ttl = options.ttl
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
storage.set(hashKey, {
|
|
90
|
+
data,
|
|
91
|
+
expire: ttl ? Date.now() + ttl : null
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
base.log.debug(`Set ${hashKey}`)
|
|
95
|
+
|
|
96
|
+
return Promise.resolve(data)
|
|
97
|
+
},
|
|
98
|
+
remove (hashKey) {
|
|
99
|
+
if (base.metrics) {
|
|
100
|
+
base.metrics.increment(Constants.CACHE_DELETED_TOTAL)
|
|
101
|
+
}
|
|
102
|
+
storage.delete(hashKey)
|
|
103
|
+
base.log.debug(`Delete ${hashKey}`)
|
|
104
|
+
|
|
105
|
+
return Promise.resolve()
|
|
106
|
+
},
|
|
107
|
+
clear (pattern = '**') {
|
|
108
|
+
if (base.metrics) {
|
|
109
|
+
base.metrics.increment(Constants.CACHE_DELETED_TOTAL)
|
|
110
|
+
}
|
|
111
|
+
storage.forEach((_, key) => {
|
|
112
|
+
if (match(key, pattern)) {
|
|
113
|
+
base.log.debug(`Delete ${key}`)
|
|
114
|
+
this.remove(key)
|
|
115
|
+
}
|
|
116
|
+
})
|
|
117
|
+
return Promise.resolve()
|
|
118
|
+
},
|
|
119
|
+
lock (key, ttl) {
|
|
120
|
+
return lock.acquire(key, ttl).then(() => {
|
|
121
|
+
return () => lock.release(key)
|
|
122
|
+
})
|
|
123
|
+
},
|
|
124
|
+
tryLock (key, ttl) {
|
|
125
|
+
if (lock.isLocked(key)) {
|
|
126
|
+
return Promise.reject(new Error('Locked'))
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return lock.acquire(key, ttl).then(() => {
|
|
130
|
+
return () => lock.release(key)
|
|
131
|
+
})
|
|
132
|
+
},
|
|
133
|
+
stop () {
|
|
134
|
+
clearInterval(timer)
|
|
135
|
+
}
|
|
136
|
+
})
|
|
137
|
+
return cache
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
module.exports = makeInMemoryCache
|
package/lib/cache/index.js
CHANGED
package/lib/cache/lock.js
CHANGED
|
@@ -1,14 +1,31 @@
|
|
|
1
|
-
|
|
1
|
+
const createLock = () => {
|
|
2
2
|
const locked = new Map()
|
|
3
|
+
|
|
3
4
|
return {
|
|
4
5
|
acquire (key, ttl) {
|
|
5
|
-
const
|
|
6
|
-
if (!
|
|
7
|
-
|
|
6
|
+
const lockedItems = locked.get(key)
|
|
7
|
+
if (!lockedItems) {
|
|
8
|
+
locked.set(key, [])
|
|
9
|
+
return Promise.resolve()
|
|
10
|
+
} else {
|
|
11
|
+
return new Promise((resolve) => lockedItems.push(resolve))
|
|
8
12
|
}
|
|
9
13
|
},
|
|
10
14
|
isLocked (key) {
|
|
11
15
|
return !!locked.has(key)
|
|
16
|
+
},
|
|
17
|
+
release (key) {
|
|
18
|
+
const lockedItems = locked.get(key)
|
|
19
|
+
if (lockedItems) {
|
|
20
|
+
if (lockedItems.length > 0) {
|
|
21
|
+
lockedItems.shift()()
|
|
22
|
+
} else {
|
|
23
|
+
locked.delete(key)
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return Promise.resolve()
|
|
12
27
|
}
|
|
13
28
|
}
|
|
14
29
|
}
|
|
30
|
+
|
|
31
|
+
module.exports = { createLock }
|
package/lib/constants.js
CHANGED
|
@@ -11,6 +11,13 @@ exports.loadBalancingStrategy = {
|
|
|
11
11
|
RANDOM: 'random'
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
exports.circuitBreakerStates = {
|
|
15
|
+
CIRCUIT_CLOSED: 'closed',
|
|
16
|
+
CIRCUIT_HALF_OPENED: 'half_opened',
|
|
17
|
+
CIRCUIT_HALF_OPEN_WAITING: 'half_open_waiting',
|
|
18
|
+
CIRCUIT_OPENED: 'opened'
|
|
19
|
+
}
|
|
20
|
+
|
|
14
21
|
exports.level = {
|
|
15
22
|
trace: 'trace',
|
|
16
23
|
debug: 'debug',
|
|
@@ -19,7 +26,3 @@ exports.level = {
|
|
|
19
26
|
error: 'error',
|
|
20
27
|
fatal: 'fatal'
|
|
21
28
|
}
|
|
22
|
-
|
|
23
|
-
exports.SYNC_MIDDLEWARE_HOOKS = {
|
|
24
|
-
STARTING: 'starting'
|
|
25
|
-
}
|
|
File without changes
|
package/lib/errors.js
CHANGED
|
@@ -4,7 +4,9 @@
|
|
|
4
4
|
* Copyright 2021 Fachwerk
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
const { ExtendableError } = require('./ExtendableError')
|
|
8
|
+
|
|
9
|
+
class WeaveError extends ExtendableError {
|
|
8
10
|
constructor (message, code, type, data) {
|
|
9
11
|
super(message)
|
|
10
12
|
this.name = this.constructor.name
|
|
@@ -15,7 +17,7 @@ class WeaveError extends Error {
|
|
|
15
17
|
}
|
|
16
18
|
}
|
|
17
19
|
|
|
18
|
-
class
|
|
20
|
+
class WeaveRetryableError extends WeaveError {
|
|
19
21
|
constructor (message, code, type, data) {
|
|
20
22
|
super(message)
|
|
21
23
|
this.code = code || 500
|
|
@@ -25,7 +27,7 @@ class WeaveRetrieableError extends WeaveError {
|
|
|
25
27
|
}
|
|
26
28
|
}
|
|
27
29
|
|
|
28
|
-
class WeaveServiceNotFoundError extends
|
|
30
|
+
class WeaveServiceNotFoundError extends WeaveRetryableError {
|
|
29
31
|
constructor (data = {}) {
|
|
30
32
|
let message
|
|
31
33
|
|
|
@@ -33,31 +35,36 @@ class WeaveServiceNotFoundError extends WeaveRetrieableError {
|
|
|
33
35
|
message = `Service "${data.actionName}" not found on node "${data.nodeId}".`
|
|
34
36
|
} else if (data.actionName) {
|
|
35
37
|
message = `Service "${data.actionName}" not found.`
|
|
38
|
+
} else {
|
|
39
|
+
message = 'Service not found.'
|
|
36
40
|
}
|
|
37
41
|
|
|
38
42
|
super(message, 404, 'WEAVE_SERVICE_NOT_FOUND_ERROR', data)
|
|
39
43
|
}
|
|
40
44
|
}
|
|
41
45
|
|
|
42
|
-
class WeaveServiceNotAvailableError extends
|
|
46
|
+
class WeaveServiceNotAvailableError extends WeaveRetryableError {
|
|
43
47
|
constructor (data = {}) {
|
|
44
48
|
let message
|
|
45
49
|
if (data.nodeId) {
|
|
46
50
|
message = `Service "${data.actionName}" not available on node "${data.nodeId}".`
|
|
47
|
-
} else {
|
|
51
|
+
} else if (data.actionName) {
|
|
48
52
|
message = `Service "${data.actionName}" not available.`
|
|
53
|
+
} else {
|
|
54
|
+
message = 'Service not available.'
|
|
49
55
|
}
|
|
50
56
|
|
|
51
|
-
super(message,
|
|
57
|
+
super(message, 503, 'WEAVE_SERVICE_NOT_AVAILABLE_ERROR', data)
|
|
52
58
|
}
|
|
53
59
|
}
|
|
54
60
|
|
|
55
|
-
class WeaveRequestTimeoutError extends
|
|
61
|
+
class WeaveRequestTimeoutError extends WeaveRetryableError {
|
|
56
62
|
constructor (actionName, nodeId, timeout) {
|
|
57
63
|
const message = `Action ${actionName} timed out node ${nodeId || '<local>'}.`
|
|
58
64
|
super(message, 504, 'WEAVE_REQUEST_TIMEOUT_ERROR', {
|
|
59
65
|
actionName,
|
|
60
|
-
nodeId
|
|
66
|
+
nodeId,
|
|
67
|
+
timeout
|
|
61
68
|
})
|
|
62
69
|
this.retryable = true
|
|
63
70
|
}
|
|
@@ -116,7 +123,7 @@ module.exports = {
|
|
|
116
123
|
WeaveParameterValidationError,
|
|
117
124
|
WeaveQueueSizeExceededError,
|
|
118
125
|
WeaveRequestTimeoutError,
|
|
119
|
-
|
|
126
|
+
WeaveRetryableError,
|
|
120
127
|
WeaveServiceNotAvailableError,
|
|
121
128
|
WeaveServiceNotFoundError,
|
|
122
129
|
WeaveGracefulStopTimeoutError,
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/* istanbul ignore next */
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* @typedef {import('../types.js').ServiceActionDefinition} ServiceActionDefinition
|
|
3
5
|
*/
|
|
@@ -6,7 +8,7 @@
|
|
|
6
8
|
* Create and register a new service action.
|
|
7
9
|
* @param {ServiceActionDefinition} actionDefinition - Schema of the the action
|
|
8
10
|
* @returns {ServiceActionDefinition} Action definition
|
|
9
|
-
|
|
11
|
+
*/
|
|
10
12
|
module.exports = function (actionDefinition) {
|
|
11
13
|
return actionDefinition
|
|
12
14
|
}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
|
|
2
|
+
/* istanbul ignore next */
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
5
|
* @typedef {import('../types.js').ServiceSchema} ServiceSchema
|
|
3
6
|
*/
|
|
@@ -6,7 +9,7 @@
|
|
|
6
9
|
* Create and register a new service
|
|
7
10
|
* @param {ServiceSchema} serviceSchema - Schema of the Service
|
|
8
11
|
* @returns {ServiceSchema} Service schema
|
|
9
|
-
|
|
12
|
+
*/
|
|
10
13
|
module.exports = function (serviceSchema) {
|
|
11
14
|
return serviceSchema
|
|
12
15
|
}
|
package/lib/index.js
CHANGED
|
@@ -4,15 +4,15 @@
|
|
|
4
4
|
* @typedef {import('./types.js').Broker} Broker
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
const { getDefaultOptions } = require('./broker/
|
|
7
|
+
const { getDefaultOptions } = require('./broker/defaultOptions')
|
|
8
8
|
const { defaultsDeep } = require('@weave-js/utils')
|
|
9
|
-
const {
|
|
9
|
+
const { initRuntime } = require('./buildRuntime')
|
|
10
10
|
const { createBrokerInstance } = require('./broker')
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* @type {BrokerOptions} options Broker options
|
|
14
14
|
*/
|
|
15
|
-
exports.defaultOptions =
|
|
15
|
+
exports.defaultOptions = getDefaultOptions()
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* Build runtime object
|
|
@@ -27,13 +27,12 @@ exports.createBroker = (options) => {
|
|
|
27
27
|
options = defaultsDeep(options, defaultOptions)
|
|
28
28
|
|
|
29
29
|
// Init runtime
|
|
30
|
-
const runtime =
|
|
30
|
+
const runtime = initRuntime(options)
|
|
31
31
|
|
|
32
32
|
// Create broker instance
|
|
33
33
|
return createBrokerInstance(runtime)
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
// eslint-disable-next-line valid-jsdoc
|
|
37
36
|
/**
|
|
38
37
|
* @deprecated since version 0.9.0
|
|
39
38
|
* @param {import('./types.js').BrokerOptions} options Broker options.
|
|
@@ -45,15 +44,20 @@ exports.Weave = exports.createBroker
|
|
|
45
44
|
exports.Errors = require('./errors')
|
|
46
45
|
|
|
47
46
|
exports.Constants = require('./constants')
|
|
47
|
+
|
|
48
48
|
// Transport
|
|
49
49
|
exports.TransportAdapters = require('./transport/adapters')
|
|
50
50
|
|
|
51
51
|
// Caching
|
|
52
52
|
exports.Cache = require('./cache')
|
|
53
|
-
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @deprecated since version 0.10.0
|
|
56
|
+
*/
|
|
57
|
+
exports.createBaseTracingCollector = require('./tracing/collectors/base').createBaseTracingCollector
|
|
54
58
|
exports.TracingAdapters = require('./tracing/collectors')
|
|
55
59
|
|
|
56
60
|
// Helper
|
|
57
|
-
exports.defineBrokerOptions = require('./helper/
|
|
58
|
-
exports.defineService = require('./helper/
|
|
59
|
-
exports.defineAction = require('./helper/
|
|
61
|
+
exports.defineBrokerOptions = require('./helper/defineBrokerOptions')
|
|
62
|
+
exports.defineService = require('./helper/defineService')
|
|
63
|
+
exports.defineAction = require('./helper/defineAction')
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const { green, magenta, red, yellow,
|
|
1
|
+
const { green, magenta, red, yellow, gray, cyan } = require('../utils/colorize')
|
|
2
2
|
const os = require('os')
|
|
3
3
|
|
|
4
4
|
exports.asHumanReadable = ({ levels, options }, originObj, message, number, time) => {
|
|
@@ -15,8 +15,9 @@ exports.asHumanReadable = ({ levels, options }, originObj, message, number, time
|
|
|
15
15
|
|
|
16
16
|
const currentLabel = levels.labels[number]
|
|
17
17
|
|
|
18
|
+
const color = logLevelColors[currentLabel] || yellow
|
|
18
19
|
// Log level label
|
|
19
|
-
logResult +=
|
|
20
|
+
logResult += color(currentLabel.toUpperCase())
|
|
20
21
|
|
|
21
22
|
// date time
|
|
22
23
|
logResult += ' [' + new Date(time).toISOString() + '] '
|
|
@@ -26,7 +27,7 @@ exports.asHumanReadable = ({ levels, options }, originObj, message, number, time
|
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
if (message) {
|
|
29
|
-
logResult += ' ' +
|
|
30
|
+
logResult += ' ' + color(message)
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
if (Object.keys(originObj).length > 0) {
|
package/lib/logger/index.js
CHANGED
package/lib/logger/levels.js
CHANGED
|
@@ -51,8 +51,9 @@ exports.mappings = (customLevels = null, useOnlyCustomLevels = false) => {
|
|
|
51
51
|
customNums
|
|
52
52
|
)
|
|
53
53
|
|
|
54
|
+
// Merge log levels with "silent" log level.
|
|
54
55
|
const values = Object.assign(
|
|
55
|
-
Object.create(Object.prototype, { silent: { value:
|
|
56
|
+
Object.create(Object.prototype, { silent: { value: 0 }}),
|
|
56
57
|
useOnlyCustomLevels ? null : levels,
|
|
57
58
|
customLevels
|
|
58
59
|
)
|
package/lib/logger/tools.js
CHANGED
|
@@ -7,6 +7,10 @@ exports.generateLogMethod = (runtime, level, hook) => {
|
|
|
7
7
|
return log
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
+
return function hookWrappedLog (...args) {
|
|
11
|
+
hook.call(runtime, args, log, level)
|
|
12
|
+
}
|
|
13
|
+
|
|
10
14
|
function log (origin, ...n) {
|
|
11
15
|
if (typeof origin === 'object') {
|
|
12
16
|
let message = origin
|
|
@@ -52,29 +52,43 @@ exports.format = (f, args, opts) => {
|
|
|
52
52
|
case 79: // 'O'
|
|
53
53
|
case 111: // 'o'
|
|
54
54
|
case 106: // 'j'
|
|
55
|
-
if (a >= argumentLength) {
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
if (a >= argumentLength) {
|
|
56
|
+
break
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (lastPos < i) {
|
|
60
|
+
str += f.slice(lastPos, i)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (args[a] === undefined) {
|
|
64
|
+
break
|
|
65
|
+
}
|
|
66
|
+
|
|
58
67
|
const type = typeof args[a]
|
|
68
|
+
|
|
59
69
|
if (type === 'string') {
|
|
60
70
|
str += '\'' + args[a] + '\''
|
|
61
71
|
lastPos = i + 2
|
|
62
72
|
i++
|
|
63
73
|
break
|
|
64
74
|
}
|
|
75
|
+
|
|
65
76
|
if (type === 'function') {
|
|
66
77
|
str += args[a].name || '<anonymous>'
|
|
67
78
|
lastPos = i + 2
|
|
68
79
|
i++
|
|
69
80
|
break
|
|
70
81
|
}
|
|
82
|
+
|
|
71
83
|
str += ss(args[a])
|
|
72
84
|
lastPos = i + 2
|
|
73
85
|
i++
|
|
74
86
|
break
|
|
75
87
|
case 115: // 's'
|
|
76
88
|
if (a >= argumentLength) { break }
|
|
77
|
-
if (lastPos < i) {
|
|
89
|
+
if (lastPos < i) {
|
|
90
|
+
str += f.slice(lastPos, i)
|
|
91
|
+
}
|
|
78
92
|
str += String(args[a])
|
|
79
93
|
lastPos = i + 2
|
|
80
94
|
i++
|
package/lib/metrics/constants.js
CHANGED
|
@@ -29,7 +29,7 @@ exports.TRANSPORTER_PACKETS_RECEIVED = 'weave.transport.packets.received'
|
|
|
29
29
|
exports.TRANSPORT_IN_FLIGHT_STREAMS = 'weave.transport.streams.in-flight'
|
|
30
30
|
|
|
31
31
|
// Bulkhead
|
|
32
|
-
exports.
|
|
32
|
+
exports.BULKHEAD_REQUESTS_IN_FLIGHT = 'weave.bulkhead.requests.in-flight'
|
|
33
33
|
|
|
34
34
|
// OS Metrics
|
|
35
35
|
exports.OS_HOSTNAME = 'os.hostname'
|