@weave-js/core 0.11.1 → 0.13.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.
Files changed (116) hide show
  1. package/.eslintrc.js +1 -1
  2. package/jest.config.js +1 -1
  3. package/lib/ExtendableError.js +8 -8
  4. package/lib/broker/context.js +49 -49
  5. package/lib/broker/defaultOptions.js +8 -9
  6. package/lib/broker/index.js +160 -164
  7. package/lib/buildRuntime.js +34 -34
  8. package/lib/cache/adapters/base.js +50 -74
  9. package/lib/cache/adapters/inMemory.js +58 -58
  10. package/lib/cache/adapters/inMemoryLru.js +57 -57
  11. package/lib/cache/adapters/index.js +3 -39
  12. package/lib/cache/getCacheKeyByObject.js +31 -0
  13. package/lib/cache/getPropertyFromDataOrMetadata.js +20 -0
  14. package/lib/cache/lock.js +30 -24
  15. package/lib/constants.js +5 -5
  16. package/lib/errorHandler.js +8 -8
  17. package/lib/errors.js +64 -54
  18. package/lib/helper/defineAction.js +2 -2
  19. package/lib/helper/defineBrokerOptions.js +2 -2
  20. package/lib/helper/defineService.js +2 -2
  21. package/lib/index.js +21 -21
  22. package/lib/logger/base.js +38 -29
  23. package/lib/logger/format/asHumanReadable.js +15 -15
  24. package/lib/logger/format/asJson.js +10 -10
  25. package/lib/logger/format/index.js +3 -3
  26. package/lib/logger/index.js +24 -24
  27. package/lib/logger/levels.js +21 -21
  28. package/lib/logger/tools.js +15 -15
  29. package/lib/logger/utils/colorize.js +23 -23
  30. package/lib/logger/utils/format.js +75 -65
  31. package/lib/metrics/common.js +47 -47
  32. package/lib/metrics/constants.js +44 -44
  33. package/lib/metrics/exporter/base.js +8 -8
  34. package/lib/metrics/exporter/event.js +20 -20
  35. package/lib/metrics/exporter/index.js +15 -15
  36. package/lib/metrics/index.js +2 -2
  37. package/lib/metrics/types/base.js +20 -20
  38. package/lib/metrics/types/counter.js +6 -6
  39. package/lib/metrics/types/gauge.js +24 -24
  40. package/lib/metrics/types/histogram.js +26 -26
  41. package/lib/metrics/types/index.js +6 -6
  42. package/lib/metrics/types/info.js +17 -17
  43. package/lib/middlewares/action-hooks/index.js +38 -38
  44. package/lib/middlewares/bulkhead/index.js +34 -34
  45. package/lib/middlewares/cache/index.js +37 -37
  46. package/lib/middlewares/circuit-breaker/index.js +62 -62
  47. package/lib/middlewares/context-tracker/index.js +39 -39
  48. package/lib/middlewares/error-handler/index.js +47 -15
  49. package/lib/middlewares/index.js +2 -2
  50. package/lib/middlewares/metrics/getMiddlewareWrapper.js +17 -17
  51. package/lib/middlewares/metrics/index.js +29 -29
  52. package/lib/middlewares/retry/index.js +15 -15
  53. package/lib/middlewares/timeout/index.js +16 -16
  54. package/lib/middlewares/tracing/index.js +37 -37
  55. package/lib/middlewares/tracing/tags.js +6 -6
  56. package/lib/middlewares/validator/index.js +31 -31
  57. package/lib/registry/actionEndpoint.js +8 -8
  58. package/lib/registry/collections/actionCollection.js +39 -35
  59. package/lib/registry/collections/endpointCollection.js +63 -63
  60. package/lib/registry/collections/eventCollection.js +62 -62
  61. package/lib/registry/collections/nodeCollection.js +45 -45
  62. package/lib/registry/collections/serviceCollection.js +61 -55
  63. package/lib/registry/eventEndpoint.js +14 -14
  64. package/lib/registry/load-balancer/base.js +3 -3
  65. package/lib/registry/load-balancer/index.js +7 -7
  66. package/lib/registry/node.js +27 -27
  67. package/lib/registry/registry.js +139 -136
  68. package/lib/registry/service/parseAction.js +16 -16
  69. package/lib/registry/service/parseEvent.js +18 -18
  70. package/lib/registry/service/reduceMixins.js +10 -10
  71. package/lib/registry/service/service.js +72 -72
  72. package/lib/registry/serviceItem.js +21 -21
  73. package/lib/runtime/initActionInvoker.js +21 -21
  74. package/lib/runtime/initCache.js +7 -7
  75. package/lib/runtime/initContextFactory.js +22 -22
  76. package/lib/runtime/initEventbus.js +49 -49
  77. package/lib/runtime/initLogger.js +11 -11
  78. package/lib/runtime/initMetrics.js +54 -54
  79. package/lib/runtime/initMiddlewareManager.js +21 -21
  80. package/lib/runtime/initRegistry.js +6 -6
  81. package/lib/runtime/initServiceManager.js +90 -68
  82. package/lib/runtime/initTracing.js +23 -23
  83. package/lib/runtime/initTransport.js +5 -5
  84. package/lib/runtime/initUuidFactory.js +4 -4
  85. package/lib/runtime/initValidator.js +5 -5
  86. package/lib/tracing/collectors/base.js +22 -22
  87. package/lib/tracing/collectors/event.js +33 -33
  88. package/lib/tracing/collectors/index.js +15 -15
  89. package/lib/tracing/span.js +26 -26
  90. package/lib/tracing/time.js +8 -8
  91. package/lib/transport/InboundTransformStream.js +26 -26
  92. package/lib/transport/adapters/adapteBase.js +30 -30
  93. package/lib/transport/adapters/adapters.js +4 -4
  94. package/lib/transport/adapters/dummy/index.js +18 -18
  95. package/lib/transport/adapters/fromURI.js +13 -13
  96. package/lib/transport/adapters/getAdapterByName.js +5 -5
  97. package/lib/transport/adapters/index.js +12 -12
  98. package/lib/transport/adapters/tcp/discovery/codec.js +4 -4
  99. package/lib/transport/adapters/tcp/discovery/index.js +62 -62
  100. package/lib/transport/adapters/tcp/index.js +169 -171
  101. package/lib/transport/adapters/tcp/tcp-messagetypes.js +7 -7
  102. package/lib/transport/adapters/tcp/tcpReader.js +39 -39
  103. package/lib/transport/adapters/tcp/tcpWriteStream.js +26 -26
  104. package/lib/transport/adapters/tcp/tcpWriter.js +57 -57
  105. package/lib/transport/adapters/tcp/utils.js +12 -12
  106. package/lib/transport/createMessage.js +4 -4
  107. package/lib/transport/createTransport.js +254 -254
  108. package/lib/transport/errorPayloadFactory.js +13 -17
  109. package/lib/transport/messageHandlers.js +199 -206
  110. package/lib/transport/messageTypes.js +19 -19
  111. package/lib/types.js +28 -15
  112. package/lib/utils/index.js +1 -1
  113. package/lib/utils/options.js +44 -44
  114. package/lib/utils/restoreError.js +58 -6
  115. package/package.json +4 -4
  116. package/lib/cache/base.js +0 -136
@@ -1,17 +1,17 @@
1
1
  /*
2
- * Author: Kevin Ries (kevin@fachw3rk.de)
2
+ * Author: Kevin Ries (kevin.ries@fachwerk.io)
3
3
  * -----
4
4
  * Copyright 2019 Fachwerk
5
5
  */
6
6
 
7
- const os = require('os')
8
- const { initBase } = require('./base')
9
- const { asJson, asHumanReadable } = require('./format')
10
- const { mappings } = require('./levels')
11
- const { coreFixtures } = require('./tools')
7
+ const os = require('os');
8
+ const { initBase } = require('./base');
9
+ const { asJson, asHumanReadable } = require('./format');
10
+ const { mappings } = require('./levels');
11
+ const { coreFixtures } = require('./tools');
12
12
 
13
- const { pid } = process
14
- const hostname = os.hostname()
13
+ const { pid } = process;
14
+ const hostname = os.hostname();
15
15
 
16
16
  const defaultOptions = {
17
17
  enabled: true,
@@ -29,50 +29,50 @@ const defaultOptions = {
29
29
  messageFormat: false
30
30
  },
31
31
  destination: process.stdout
32
- }
32
+ };
33
33
 
34
34
  exports.createLogger = (options) => {
35
- options = Object.assign(defaultOptions, options)
35
+ options = Object.assign(defaultOptions, options);
36
36
 
37
- const instance = {}
37
+ const instance = {};
38
38
  const runtime = {
39
39
  options,
40
40
  logMethods: {},
41
41
  destination: options.destination,
42
42
  formatter: process.stdout.isTTY ? asHumanReadable : asJson
43
- }
43
+ };
44
44
 
45
45
  if (options.enabled === false) {
46
- options.level = 'silent'
46
+ options.level = 'silent';
47
47
  }
48
48
 
49
49
  if (options.base !== null) {
50
50
  if (options.name === undefined) {
51
- runtime.fixtures = coreFixtures(options.base)
51
+ runtime.fixtures = coreFixtures(options.base);
52
52
  } else {
53
- runtime.fixtures = coreFixtures(Object.assign({}, options.base, { name: options.name }))
53
+ runtime.fixtures = coreFixtures(Object.assign({}, options.base, { name: options.name }));
54
54
  }
55
55
  }
56
56
 
57
57
  if (options.mixin && typeof options.mixin !== 'function') {
58
- throw Error(`Unknown mixin type "${typeof options.mixin}" - expected "function"`)
58
+ throw Error(`Unknown mixin type "${typeof options.mixin}" - expected "function"`);
59
59
  } else if (options.mixin) {
60
- runtime.mixin = options.mixin
60
+ runtime.mixin = options.mixin;
61
61
  }
62
62
 
63
- const levels = mappings(options.customLevels)
63
+ const levels = mappings(options.customLevels);
64
64
 
65
65
  // merge levels in logger runtime
66
- Object.assign(runtime, { levels })
66
+ Object.assign(runtime, { levels });
67
67
 
68
- initBase(runtime)
68
+ initBase(runtime);
69
69
 
70
- runtime.setLevel(options.level)
70
+ runtime.setLevel(options.level);
71
71
 
72
72
  Object.assign(instance, {
73
73
  levels,
74
74
  ...runtime.logMethods
75
- })
75
+ });
76
76
 
77
- return instance
78
- }
77
+ return instance;
78
+ };
@@ -1,4 +1,4 @@
1
- const { generateLogMethod } = require('./tools')
1
+ const { generateLogMethod } = require('./tools');
2
2
 
3
3
  const levels = {
4
4
  verbose: 60,
@@ -7,14 +7,14 @@ const levels = {
7
7
  warn: 30,
8
8
  error: 20,
9
9
  fatal: 10
10
- }
10
+ };
11
11
 
12
12
  // wrap log methods
13
13
  const levelMethods = {
14
14
  fatal: (runtime, hook) => {
15
- const logFatal = generateLogMethod(runtime, levels.fatal, hook)
15
+ const logFatal = generateLogMethod(runtime, levels.fatal, hook);
16
16
  return function (...args) {
17
- logFatal.call(runtime, ...args)
17
+ logFatal.call(runtime, ...args);
18
18
  // if (typeof stream.flushSync === 'function') {
19
19
  // try {
20
20
  // stream.flushSync()
@@ -22,48 +22,48 @@ const levelMethods = {
22
22
  // // https://github.com/pinojs/pino/pull/740#discussion_r346788313
23
23
  // }
24
24
  // }
25
- }
25
+ };
26
26
  },
27
27
  error: (runtime, hook) => generateLogMethod(runtime, levels.error, hook),
28
28
  warn: (runtime, hook) => generateLogMethod(runtime, levels.warn, hook),
29
29
  info: (runtime, hook) => generateLogMethod(runtime, levels.info, hook),
30
30
  debug: (runtime, hook) => generateLogMethod(runtime, levels.debug, hook),
31
31
  verbose: (runtime, hook) => generateLogMethod(runtime, levels.verbose, hook)
32
- }
32
+ };
33
33
 
34
- exports.levelMethods = levelMethods
34
+ exports.levelMethods = levelMethods;
35
35
 
36
36
  const numbers = Object.keys(levels).reduce((o, k) => {
37
- o[levels[k]] = k
38
- return o
39
- }, {})
37
+ o[levels[k]] = k;
38
+ return o;
39
+ }, {});
40
40
 
41
41
  exports.mappings = (customLevels = null, useOnlyCustomLevels = false) => {
42
42
  const customNums = customLevels ? Object.keys(customLevels).reduce((o, k) => {
43
- o[customLevels[k]] = k
44
- return o
43
+ o[customLevels[k]] = k;
44
+ return o;
45
45
  }, {})
46
- : null
46
+ : null;
47
47
 
48
48
  const labels = Object.assign(
49
49
  Object.create(Object.prototype, { Infinity: { value: 'silent' }}),
50
50
  useOnlyCustomLevels ? null : numbers,
51
51
  customNums
52
- )
52
+ );
53
53
 
54
54
  // Merge log levels with "silent" log level.
55
55
  const values = Object.assign(
56
56
  Object.create(Object.prototype, { silent: { value: 0 }}),
57
57
  useOnlyCustomLevels ? null : levels,
58
58
  customLevels
59
- )
59
+ );
60
60
 
61
- return { labels, values }
62
- }
61
+ return { labels, values };
62
+ };
63
63
 
64
64
  exports.isStandardLevel = (level, useOnlyCustomLevels) => {
65
65
  if (useOnlyCustomLevels) {
66
- return false
66
+ return false;
67
67
  }
68
68
 
69
69
  switch (level) {
@@ -73,8 +73,8 @@ exports.isStandardLevel = (level, useOnlyCustomLevels) => {
73
73
  case 'info':
74
74
  case 'debug':
75
75
  case 'verbose':
76
- return true
76
+ return true;
77
77
  default:
78
- return false
78
+ return false;
79
79
  }
80
- }
80
+ };
@@ -1,33 +1,33 @@
1
- const { format } = require('./utils/format')
1
+ const { format } = require('./utils/format');
2
2
 
3
- exports.noop = () => {}
3
+ exports.noop = () => {};
4
4
 
5
5
  exports.generateLogMethod = (runtime, level, hook) => {
6
6
  if (!hook) {
7
- return log
7
+ return log;
8
8
  }
9
9
 
10
10
  return function hookWrappedLog (...args) {
11
- hook.call(runtime, args, log, level)
12
- }
11
+ hook.call(runtime, args, log, level);
12
+ };
13
13
 
14
14
  function log (origin, ...n) {
15
15
  if (typeof origin === 'object') {
16
- let message = origin
17
- let formatParams
16
+ let message = origin;
17
+ let formatParams;
18
18
  if (message === null && n.length === 0) {
19
- formatParams = [null]
19
+ formatParams = [null];
20
20
  } else {
21
- message = n.shift()
22
- formatParams = n
21
+ message = n.shift();
22
+ formatParams = n;
23
23
  }
24
- runtime.write(origin, format(message, formatParams, runtime.options.formatOptions), level)
24
+ runtime.write(origin, format(message, formatParams, runtime.options.formatOptions), level);
25
25
  } else {
26
- runtime.write(null, format(origin, n, runtime.options.formatOptions), level)
26
+ runtime.write(null, format(origin, n, runtime.options.formatOptions), level);
27
27
  }
28
28
  }
29
- }
29
+ };
30
30
 
31
31
  exports.coreFixtures = (object) => {
32
- return object
33
- }
32
+ return object;
33
+ };
@@ -1,32 +1,32 @@
1
1
  const init = (x, y) => {
2
- const regex = new RegExp(`\\x1b\\[${y}m`, 'g')
3
- const open = `\x1b[${x}m`; const close = `\x1b[${y}m`
2
+ const regex = new RegExp(`\\x1b\\[${y}m`, 'g');
3
+ const open = `\x1b[${x}m`; const close = `\x1b[${y}m`;
4
4
 
5
5
  return function (txt) {
6
- return open + (~('' + txt).indexOf(close) ? txt.replace(regex, close + open) : txt) + close
7
- }
8
- }
6
+ return open + (~('' + txt).indexOf(close) ? txt.replace(regex, close + open) : txt) + close;
7
+ };
8
+ };
9
9
 
10
10
  // modifiers
11
- exports.bold = init(1, 22)
12
- exports.dim = init(2, 22)
13
- exports.hidden = init(8, 28)
14
- exports.inverse = init(7, 27)
15
- exports.italic = init(3, 23)
16
- exports.reset = init(0, 0)
17
- exports.strikeThrough = init(9, 29)
18
- exports.underline = init(4, 24)
11
+ exports.bold = init(1, 22);
12
+ exports.dim = init(2, 22);
13
+ exports.hidden = init(8, 28);
14
+ exports.inverse = init(7, 27);
15
+ exports.italic = init(3, 23);
16
+ exports.reset = init(0, 0);
17
+ exports.strikeThrough = init(9, 29);
18
+ exports.underline = init(4, 24);
19
19
 
20
20
  // colors
21
- exports.black = init(30, 39)
22
- exports.blue = init(34, 39)
23
- exports.cyan = init(36, 39)
24
- exports.gray = init(90, 39)
25
- exports.green = init(32, 39)
26
- exports.grey = init(90, 39)
27
- exports.magenta = init(35, 39)
28
- exports.red = init(31, 39)
29
- exports.white = init(37, 39)
30
- exports.yellow = init(33, 39)
21
+ exports.black = init(30, 39);
22
+ exports.blue = init(34, 39);
23
+ exports.cyan = init(36, 39);
24
+ exports.gray = init(90, 39);
25
+ exports.green = init(32, 39);
26
+ exports.grey = init(90, 39);
27
+ exports.magenta = init(35, 39);
28
+ exports.red = init(31, 39);
29
+ exports.white = init(37, 39);
30
+ exports.yellow = init(33, 39);
31
31
 
32
32
  // todo: bg colors
@@ -1,114 +1,124 @@
1
1
  const tryStringify = (o) => {
2
2
  try {
3
- return JSON.stringify(o)
3
+ return JSON.stringify(o);
4
4
  } catch (e) {
5
- return '"[Circular]"'
5
+ return '"[Circular]"';
6
6
  }
7
- }
7
+ };
8
8
 
9
- exports.format = (f, args, opts) => {
10
- const ss = (opts && opts.stringify) || tryStringify
11
- const offset = 1
9
+ function format (f, args, opts) {
10
+ const ss = (opts && opts.stringify) || tryStringify;
11
+ const offset = 1;
12
12
  if (typeof f === 'object' && f !== null) {
13
- const len = args.length + offset
14
- if (len === 1) return f
15
- const objects = new Array(len)
16
- objects[0] = ss(f)
13
+ const len = args.length + offset;
14
+ if (len === 1) return f;
15
+ const objects = new Array(len);
16
+ objects[0] = ss(f);
17
17
  for (let index = 1; index < len; index++) {
18
- objects[index] = ss(args[index])
18
+ objects[index] = ss(args[index]);
19
19
  }
20
- return objects.join(' ')
20
+ return objects.join(' ');
21
21
  }
22
22
  if (typeof f !== 'string') {
23
- return f
23
+ return f;
24
24
  }
25
- const argumentLength = args.length
26
- if (argumentLength === 0) return f
25
+ const argumentLength = args.length;
26
+ if (argumentLength === 0) return f;
27
27
 
28
- let str = ''
29
- let a = 1 - offset
30
- let lastPos = -1
31
- const formatLength = (f && f.length) || 0
28
+ let str = '';
29
+ let a = 1 - offset;
30
+ let lastPos = -1;
31
+ const formatLength = (f && f.length) || 0;
32
32
 
33
33
  for (let i = 0; i < formatLength;) {
34
34
  if (f.charCodeAt(i) === 37 && i + 1 < formatLength) {
35
- lastPos = lastPos > -1 ? lastPos : 0
35
+ lastPos = lastPos > -1 ? lastPos : 0;
36
36
  switch (f.charCodeAt(i + 1)) {
37
37
  case 100: // 'd'
38
38
  case 102: // 'f'
39
- if (a >= argumentLength) { break }
40
- if (lastPos < i) { str += f.slice(lastPos, i) }
41
- if (args[a] == null) break
42
- str += Number(args[a])
43
- lastPos = i = i + 2
44
- break
39
+ if (a >= argumentLength) { break; }
40
+ if (lastPos < i) {
41
+ str += f.slice(lastPos, i);
42
+ }
43
+ if (args[a] == null) break;
44
+ str += Number(args[a]);
45
+ lastPos = i = i + 2;
46
+ break;
45
47
  case 105: // 'i'
46
- if (a >= argumentLength) { break }
47
- if (lastPos < i) { str += f.slice(lastPos, i) }
48
- if (args[a] == null) break
49
- str += Math.floor(Number(args[a]))
50
- lastPos = i = i + 2
51
- break
48
+ if (a >= argumentLength) {
49
+ break;
50
+ }
51
+ if (lastPos < i) {
52
+ str += f.slice(lastPos, i);
53
+ }
54
+ if (args[a] == null) break;
55
+ str += Math.floor(Number(args[a]));
56
+ lastPos = i = i + 2;
57
+ break;
52
58
  case 79: // 'O'
53
59
  case 111: // 'o'
54
60
  case 106: // 'j'
55
61
  if (a >= argumentLength) {
56
- break
62
+ break;
57
63
  }
58
64
 
59
65
  if (lastPos < i) {
60
- str += f.slice(lastPos, i)
66
+ str += f.slice(lastPos, i);
61
67
  }
62
68
 
63
69
  if (args[a] === undefined) {
64
- break
70
+ break;
65
71
  }
66
72
 
67
- const type = typeof args[a]
73
+ const type = typeof args[a];
68
74
 
69
75
  if (type === 'string') {
70
- str += '\'' + args[a] + '\''
71
- lastPos = i + 2
72
- i++
73
- break
76
+ str += '\'' + args[a] + '\'';
77
+ lastPos = i + 2;
78
+ i++;
79
+ break;
74
80
  }
75
81
 
76
82
  if (type === 'function') {
77
- str += args[a].name || '<anonymous>'
78
- lastPos = i + 2
79
- i++
80
- break
83
+ str += args[a].name || '<anonymous>';
84
+ lastPos = i + 2;
85
+ i++;
86
+ break;
81
87
  }
82
88
 
83
- str += ss(args[a])
84
- lastPos = i + 2
85
- i++
86
- break
89
+ str += ss(args[a]);
90
+ lastPos = i + 2;
91
+ i++;
92
+ break;
87
93
  case 115: // 's'
88
- if (a >= argumentLength) { break }
94
+ if (a >= argumentLength) { break; }
89
95
  if (lastPos < i) {
90
- str += f.slice(lastPos, i)
96
+ str += f.slice(lastPos, i);
91
97
  }
92
- str += String(args[a])
93
- lastPos = i + 2
94
- i++
95
- break
98
+ str += String(args[a]);
99
+ lastPos = i + 2;
100
+ i++;
101
+ break;
96
102
  case 37: // '%'
97
- if (lastPos < i) { str += f.slice(lastPos, i) }
98
- str += '%'
99
- lastPos = i + 2
100
- i++
101
- a--
102
- break
103
+ if (lastPos < i) {
104
+ str += f.slice(lastPos, i);
105
+ }
106
+ str += '%';
107
+ lastPos = i + 2;
108
+ i++;
109
+ a--;
110
+ break;
103
111
  }
104
- ++a
112
+ ++a;
105
113
  }
106
- ++i
114
+ ++i;
107
115
  }
108
116
 
109
- if (lastPos === -1) { return f } else if (lastPos < formatLength) {
110
- str += f.slice(lastPos)
117
+ if (lastPos === -1) { return f; } else if (lastPos < formatLength) {
118
+ str += f.slice(lastPos);
111
119
  }
112
120
 
113
- return str
121
+ return str;
114
122
  }
123
+
124
+ module.exports = { format };
@@ -1,78 +1,78 @@
1
1
  /**
2
2
  * @typedef {import('../types.js').Runtime} Runtime
3
3
  */
4
- const os = require('os')
5
- const Constants = require('./constants')
4
+ const os = require('os');
5
+ const Constants = require('./constants');
6
6
 
7
7
  const getUserInfo = () => {
8
8
  try {
9
- return os.userInfo()
9
+ return os.userInfo();
10
10
  } catch (e) {
11
- return {}
11
+ return {};
12
12
  }
13
- }
13
+ };
14
14
 
15
15
  /**
16
16
  * @param {Runtime} runtime Runtime reference
17
17
  * @returns {void}
18
18
  */
19
19
  exports.registerCommonMetrics = (runtime) => {
20
- const { metrics } = runtime
20
+ const { metrics } = runtime;
21
21
 
22
22
  // Process metrics
23
- metrics.register({ name: Constants.PROCESS_PID, type: 'info', description: 'Process PID' }).set(process.pid)
24
- metrics.register({ name: Constants.PROCESS_PPID, type: 'info', description: 'Process parent PID' }).set(process.ppid)
25
- metrics.register({ name: Constants.PROCESS_UPTIME, type: 'info', description: 'Process uptime' }).set(process.uptime())
23
+ metrics.register({ name: Constants.PROCESS_PID, type: 'info', description: 'Process PID' }).set(process.pid);
24
+ metrics.register({ name: Constants.PROCESS_PPID, type: 'info', description: 'Process parent PID' }).set(process.ppid);
25
+ metrics.register({ name: Constants.PROCESS_UPTIME, type: 'info', description: 'Process uptime' }).set(process.uptime());
26
26
 
27
27
  // Weave metrics
28
- metrics.register({ name: Constants.WEAVE_ENVIRONMENT, type: 'info', description: 'Environment' }).set('Node.js')
29
- metrics.register({ name: Constants.WEAVE_ENVIRONMENT_VERSION, type: 'info', description: 'Runtime version' }).set(process.version)
30
- metrics.register({ name: Constants.WEAVE_VERSION, type: 'info', description: 'Weave version' }).set(runtime.version)
31
- metrics.register({ name: Constants.WEAVE_NODE_ID, type: 'info', description: 'Node ID' }).set(runtime.nodeId)
32
- metrics.register({ name: Constants.WEAVE_NAMESPACE, type: 'info', description: 'Namespace in which the node runs.' }).set(runtime.options.namespace)
28
+ metrics.register({ name: Constants.WEAVE_ENVIRONMENT, type: 'info', description: 'Environment' }).set('Node.js');
29
+ metrics.register({ name: Constants.WEAVE_ENVIRONMENT_VERSION, type: 'info', description: 'Runtime version' }).set(process.version);
30
+ metrics.register({ name: Constants.WEAVE_VERSION, type: 'info', description: 'Weave version' }).set(runtime.version);
31
+ metrics.register({ name: Constants.WEAVE_NODE_ID, type: 'info', description: 'Node ID' }).set(runtime.nodeId);
32
+ metrics.register({ name: Constants.WEAVE_NAMESPACE, type: 'info', description: 'Namespace in which the node runs.' }).set(runtime.options.namespace);
33
33
 
34
34
  // OS Metrics
35
- metrics.register({ name: Constants.OS_HOSTNAME, type: 'info', description: 'Hostname' }).set(os.hostname())
36
- metrics.register({ name: Constants.OS_TYPE, type: 'info', description: 'OS type' }).set(os.type())
37
- metrics.register({ name: Constants.OS_RELEASE, type: 'info', description: 'OS release' }).set(os.release())
38
- metrics.register({ name: Constants.OS_ARCH, type: 'info', description: 'OS architecture' }).set(os.arch())
39
- metrics.register({ name: Constants.OS_PLATTFORM, type: 'info', description: 'OS plattform' }).set(os.platform())
40
- metrics.register({ name: Constants.OS_MEMORY_TOTAL, type: 'gauge', description: 'OS free memory' })
41
- metrics.register({ name: Constants.OS_MEMORY_USED, type: 'gauge', description: 'OS memory used' })
42
- metrics.register({ name: Constants.OS_MEMORY_FREE, type: 'gauge', description: 'OS memory free' })
43
- metrics.register({ name: Constants.OS_UPTIME, type: 'gauge', description: 'OS uptime' }).set(os.uptime())
35
+ metrics.register({ name: Constants.OS_HOSTNAME, type: 'info', description: 'Hostname' }).set(os.hostname());
36
+ metrics.register({ name: Constants.OS_TYPE, type: 'info', description: 'OS type' }).set(os.type());
37
+ metrics.register({ name: Constants.OS_RELEASE, type: 'info', description: 'OS release' }).set(os.release());
38
+ metrics.register({ name: Constants.OS_ARCH, type: 'info', description: 'OS architecture' }).set(os.arch());
39
+ metrics.register({ name: Constants.OS_PLATTFORM, type: 'info', description: 'OS plattform' }).set(os.platform());
40
+ metrics.register({ name: Constants.OS_MEMORY_TOTAL, type: 'gauge', description: 'OS free memory' });
41
+ metrics.register({ name: Constants.OS_MEMORY_USED, type: 'gauge', description: 'OS memory used' });
42
+ metrics.register({ name: Constants.OS_MEMORY_FREE, type: 'gauge', description: 'OS memory free' });
43
+ metrics.register({ name: Constants.OS_UPTIME, type: 'gauge', description: 'OS uptime' }).set(os.uptime());
44
44
 
45
- metrics.register({ name: Constants.OS_CPU_LOAD_1, type: 'gauge', description: 'OS CPU load 1' })
46
- metrics.register({ name: Constants.OS_CPU_LOAD_5, type: 'gauge', description: 'OS CPU load 5' })
47
- metrics.register({ name: Constants.OS_CPU_LOAD_15, type: 'gauge', description: 'OS CPU load 15' })
45
+ metrics.register({ name: Constants.OS_CPU_LOAD_1, type: 'gauge', description: 'OS CPU load 1' });
46
+ metrics.register({ name: Constants.OS_CPU_LOAD_5, type: 'gauge', description: 'OS CPU load 5' });
47
+ metrics.register({ name: Constants.OS_CPU_LOAD_15, type: 'gauge', description: 'OS CPU load 15' });
48
48
 
49
- const userInfo = getUserInfo()
50
- metrics.register({ name: Constants.OS_USER_UID, type: 'info', description: 'User UID' }).set(userInfo.uid)
51
- metrics.register({ name: Constants.OS_USER_GID, type: 'info', description: 'User GID' }).set(userInfo.gid)
52
- metrics.register({ name: Constants.OS_USER_USERNAME, type: 'info', description: 'Username' }).set(userInfo.username)
53
- metrics.register({ name: Constants.OS_USER_HOMEDIR, type: 'info', description: 'User home directory' }).set(userInfo.homedir)
54
- }
49
+ const userInfo = getUserInfo();
50
+ metrics.register({ name: Constants.OS_USER_UID, type: 'info', description: 'User UID' }).set(userInfo.uid);
51
+ metrics.register({ name: Constants.OS_USER_GID, type: 'info', description: 'User GID' }).set(userInfo.gid);
52
+ metrics.register({ name: Constants.OS_USER_USERNAME, type: 'info', description: 'Username' }).set(userInfo.username);
53
+ metrics.register({ name: Constants.OS_USER_HOMEDIR, type: 'info', description: 'User home directory' }).set(userInfo.homedir);
54
+ };
55
55
 
56
56
  /**
57
57
  * @param {Runtime} runtime Runtime reference
58
58
  * @returns {void}
59
59
  */
60
60
  exports.updateCommonMetrics = (runtime) => {
61
- const { metrics } = runtime
61
+ const { metrics } = runtime;
62
62
 
63
- metrics.set(Constants.PROCESS_UPTIME, process.uptime())
64
- const freeMemory = os.freemem()
65
- const totalMemory = os.totalmem()
66
- const usedMemory = totalMemory - freeMemory
63
+ metrics.set(Constants.PROCESS_UPTIME, process.uptime());
64
+ const freeMemory = os.freemem();
65
+ const totalMemory = os.totalmem();
66
+ const usedMemory = totalMemory - freeMemory;
67
67
 
68
- metrics.set(Constants.OS_RELEASE, os.release())
69
- metrics.set(Constants.OS_MEMORY_TOTAL, totalMemory)
70
- metrics.set(Constants.OS_MEMORY_USED, usedMemory)
71
- metrics.set(Constants.OS_MEMORY_FREE, freeMemory)
72
- metrics.set(Constants.OS_UPTIME, os.uptime())
68
+ metrics.set(Constants.OS_RELEASE, os.release());
69
+ metrics.set(Constants.OS_MEMORY_TOTAL, totalMemory);
70
+ metrics.set(Constants.OS_MEMORY_USED, usedMemory);
71
+ metrics.set(Constants.OS_MEMORY_FREE, freeMemory);
72
+ metrics.set(Constants.OS_UPTIME, os.uptime());
73
73
 
74
- const load = os.loadavg()
75
- metrics.set(Constants.OS_CPU_LOAD_1, load[0])
76
- metrics.set(Constants.OS_CPU_LOAD_5, load[1])
77
- metrics.set(Constants.OS_CPU_LOAD_15, load[2])
78
- }
74
+ const load = os.loadavg();
75
+ metrics.set(Constants.OS_CPU_LOAD_1, load[0]);
76
+ metrics.set(Constants.OS_CPU_LOAD_5, load[1]);
77
+ metrics.set(Constants.OS_CPU_LOAD_15, load[2]);
78
+ };