@ohos-ports/pm2 0.0.0-stage → 7.1.2-beta.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/CHANGELOG.md +2607 -0
- package/CONTRIBUTING.md +124 -0
- package/GNU-AGPL-3.0.txt +665 -0
- package/LICENSE +1 -0
- package/README.md +255 -2
- package/SECURITY.md +41 -0
- package/bin/pm2 +3 -0
- package/bin/pm2-dev +3 -0
- package/bin/pm2-docker +3 -0
- package/bin/pm2-runtime +3 -0
- package/bin/pm2.ps1 +3 -0
- package/constants.js +113 -0
- package/index.js +12 -0
- package/lib/API/Configuration.js +212 -0
- package/lib/API/Containerizer.js +335 -0
- package/lib/API/Dashboard.js +726 -0
- package/lib/API/Deploy.js +117 -0
- package/lib/API/Extra.js +798 -0
- package/lib/API/ExtraMgmt/Docker.js +30 -0
- package/lib/API/Log.js +388 -0
- package/lib/API/LogManagement.js +351 -0
- package/lib/API/Modules/LOCAL.js +122 -0
- package/lib/API/Modules/Modularizer.js +148 -0
- package/lib/API/Modules/NPM.js +443 -0
- package/lib/API/Modules/TAR.js +368 -0
- package/lib/API/Modules/flagExt.js +46 -0
- package/lib/API/Modules/index.js +120 -0
- package/lib/API/Monit.js +247 -0
- package/lib/API/Serve.js +497 -0
- package/lib/API/Startup.js +630 -0
- package/lib/API/UX/helpers.js +213 -0
- package/lib/API/UX/index.js +9 -0
- package/lib/API/UX/pm2-describe.js +197 -0
- package/lib/API/UX/pm2-ls-minimal.js +31 -0
- package/lib/API/UX/pm2-ls.js +581 -0
- package/lib/API/Version.js +383 -0
- package/lib/API/interpreter.json +12 -0
- package/lib/API/pm2-plus/PM2IO.js +381 -0
- package/lib/API/pm2-plus/auth-strategies/CliAuth.js +306 -0
- package/lib/API/pm2-plus/auth-strategies/WebAuth.js +195 -0
- package/lib/API/pm2-plus/helpers.js +97 -0
- package/lib/API/pm2-plus/link.js +126 -0
- package/lib/API/pm2-plus/pres/motd +16 -0
- package/lib/API/pm2-plus/pres/motd.update +26 -0
- package/lib/API/pm2-plus/pres/welcome +28 -0
- package/lib/API/pm2-plus/process-selector.js +52 -0
- package/lib/API/schema.json +375 -0
- package/lib/API.js +1980 -0
- package/lib/Client.js +793 -0
- package/lib/Common.js +949 -0
- package/lib/Configuration.js +309 -0
- package/lib/Daemon.js +468 -0
- package/lib/Event.js +37 -0
- package/lib/God/ActionMethods.js +955 -0
- package/lib/God/ClusterMode.js +192 -0
- package/lib/God/ForkMode.js +205 -0
- package/lib/God/Methods.js +292 -0
- package/lib/God/Reload.js +300 -0
- package/lib/God/StdioLogger.js +239 -0
- package/lib/God.js +653 -0
- package/lib/HttpInterface.js +75 -0
- package/lib/OtelManager.js +74 -0
- package/lib/ProcessContainer.js +321 -0
- package/lib/ProcessContainerBun.js +355 -0
- package/lib/ProcessContainerFork.js +42 -0
- package/lib/ProcessContainerForkBun.js +31 -0
- package/lib/ProcessUtils.js +74 -0
- package/lib/TreeKill.js +111 -0
- package/lib/Utility.js +304 -0
- package/lib/VersionCheck.js +46 -0
- package/lib/Watcher.js +117 -0
- package/lib/Worker.js +200 -0
- package/lib/binaries/CLI.js +1092 -0
- package/lib/binaries/DevCLI.js +183 -0
- package/lib/binaries/Runtime.js +101 -0
- package/lib/binaries/Runtime4Docker.js +192 -0
- package/lib/completion.js +229 -0
- package/lib/completion.sh +40 -0
- package/lib/motd +36 -0
- package/lib/templates/Dockerfiles/Dockerfile-nodejs.tpl +8 -0
- package/lib/templates/ecosystem-es.tpl +24 -0
- package/lib/templates/ecosystem-simple-es.tpl +8 -0
- package/lib/templates/ecosystem-simple.tpl +6 -0
- package/lib/templates/ecosystem.tpl +22 -0
- package/lib/templates/init-scripts/launchd.tpl +35 -0
- package/lib/templates/init-scripts/openrc.tpl +52 -0
- package/lib/templates/init-scripts/pm2-init-amazon.sh +86 -0
- package/lib/templates/init-scripts/rcd-openbsd.tpl +41 -0
- package/lib/templates/init-scripts/rcd.tpl +44 -0
- package/lib/templates/init-scripts/smf.tpl +43 -0
- package/lib/templates/init-scripts/systemd-online.tpl +22 -0
- package/lib/templates/init-scripts/systemd.tpl +22 -0
- package/lib/templates/init-scripts/upstart.tpl +103 -0
- package/lib/templates/logrotate.d/pm2 +10 -0
- package/lib/templates/sample-apps/http-server/README.md +14 -0
- package/lib/templates/sample-apps/http-server/api.js +9 -0
- package/lib/templates/sample-apps/http-server/ecosystem.config.js +14 -0
- package/lib/templates/sample-apps/http-server/package.json +11 -0
- package/lib/templates/sample-apps/pm2-plus-metrics-actions/README.md +45 -0
- package/lib/templates/sample-apps/pm2-plus-metrics-actions/custom-metrics.js +66 -0
- package/lib/templates/sample-apps/pm2-plus-metrics-actions/ecosystem.config.js +12 -0
- package/lib/templates/sample-apps/pm2-plus-metrics-actions/package.json +11 -0
- package/lib/templates/sample-apps/python-app/README.md +4 -0
- package/lib/templates/sample-apps/python-app/echo.py +7 -0
- package/lib/templates/sample-apps/python-app/ecosystem.config.js +12 -0
- package/lib/templates/sample-apps/python-app/package.json +11 -0
- package/lib/tools/Config.js +251 -0
- package/lib/tools/SysMetrics.js +375 -0
- package/lib/tools/copydirSync.js +101 -0
- package/lib/tools/deleteFolderRecursive.js +19 -0
- package/lib/tools/find-package-json.js +74 -0
- package/lib/tools/fmt.js +72 -0
- package/lib/tools/interpreter.js +88 -0
- package/lib/tools/isbinaryfile.js +94 -0
- package/lib/tools/json5.js +752 -0
- package/lib/tools/multimeter/bar.js +111 -0
- package/lib/tools/multimeter/charm/encode.js +18 -0
- package/lib/tools/multimeter/charm/index.js +305 -0
- package/lib/tools/multimeter/index.js +76 -0
- package/lib/tools/open.js +56 -0
- package/lib/tools/passwd.js +58 -0
- package/lib/tools/pm2-config-keys.js +165 -0
- package/lib/tools/prompt.js +76 -0
- package/lib/tools/serviceStop.js +149 -0
- package/lib/tools/sexec.js +55 -0
- package/lib/tools/treeify.js +113 -0
- package/lib/tools/typestrip.js +55 -0
- package/lib/tools/which.js +120 -0
- package/lib/tools/xdg-open +861 -0
- package/modules/blessed/LICENSE +20 -0
- package/modules/blessed/README.md +34 -0
- package/modules/blessed/index.js +1 -0
- package/modules/blessed/lib/alias.js +526 -0
- package/modules/blessed/lib/blessed.js +32 -0
- package/modules/blessed/lib/colors.js +530 -0
- package/modules/blessed/lib/events.js +189 -0
- package/modules/blessed/lib/gpmclient.js +221 -0
- package/modules/blessed/lib/helpers.js +165 -0
- package/modules/blessed/lib/keys.js +339 -0
- package/modules/blessed/lib/program.js +4297 -0
- package/modules/blessed/lib/tput.js +3022 -0
- package/modules/blessed/lib/unicode.js +885 -0
- package/modules/blessed/lib/widget.js +32 -0
- package/modules/blessed/lib/widgets/box.js +34 -0
- package/modules/blessed/lib/widgets/element.js +2570 -0
- package/modules/blessed/lib/widgets/list.js +599 -0
- package/modules/blessed/lib/widgets/log.js +83 -0
- package/modules/blessed/lib/widgets/node.js +282 -0
- package/modules/blessed/lib/widgets/screen.js +2298 -0
- package/modules/blessed/lib/widgets/scrollablebox.js +389 -0
- package/modules/blessed/lib/widgets/scrollabletext.js +35 -0
- package/modules/blessed/lib/widgets/text.js +35 -0
- package/modules/blessed/usr/linux +0 -0
- package/modules/blessed/usr/windows-ansi +0 -0
- package/modules/blessed/usr/xterm +0 -0
- package/modules/blessed/usr/xterm-256color +0 -0
- package/modules/blessed/usr/xterm.termcap +243 -0
- package/modules/chokidar/LICENSE +21 -0
- package/modules/chokidar/VENDORED.md +76 -0
- package/modules/chokidar/index.js +979 -0
- package/modules/chokidar/lib/brace-expand.js +180 -0
- package/modules/chokidar/lib/constants.js +66 -0
- package/modules/chokidar/lib/fsevents-handler.js +526 -0
- package/modules/chokidar/lib/nodefs-handler.js +654 -0
- package/modules/fclone.js +49 -0
- package/modules/pm2-axon/index.js +2 -0
- package/modules/pm2-axon/lib/configurable/History.md +5 -0
- package/modules/pm2-axon/lib/configurable/Makefile +7 -0
- package/modules/pm2-axon/lib/configurable/Readme.md +57 -0
- package/modules/pm2-axon/lib/configurable/index.js +2 -0
- package/modules/pm2-axon/lib/configurable/lib/configurable.js +47 -0
- package/modules/pm2-axon/lib/configurable/package.json +68 -0
- package/modules/pm2-axon/lib/index.js +44 -0
- package/modules/pm2-axon/lib/plugins/queue.js +71 -0
- package/modules/pm2-axon/lib/plugins/round-robin.js +55 -0
- package/modules/pm2-axon/lib/sockets/pub-emitter.js +26 -0
- package/modules/pm2-axon/lib/sockets/pub.js +77 -0
- package/modules/pm2-axon/lib/sockets/pull.js +37 -0
- package/modules/pm2-axon/lib/sockets/push.js +32 -0
- package/modules/pm2-axon/lib/sockets/rep.js +73 -0
- package/modules/pm2-axon/lib/sockets/req.js +101 -0
- package/modules/pm2-axon/lib/sockets/sock.js +430 -0
- package/modules/pm2-axon/lib/sockets/sub-emitter.js +92 -0
- package/modules/pm2-axon/lib/sockets/sub.js +147 -0
- package/modules/pm2-axon/lib/utils.js +19 -0
- package/modules/pm2-axon-rpc/index.js +3 -0
- package/modules/pm2-axon-rpc/lib/client.js +63 -0
- package/modules/pm2-axon-rpc/lib/server.js +139 -0
- package/modules/pm2-io-agent/LICENSE +661 -0
- package/modules/pm2-io-agent/README.md +62 -0
- package/modules/pm2-io-agent/config.js +30 -0
- package/modules/pm2-io-agent/constants.js +118 -0
- package/modules/pm2-io-agent/index.js +2 -0
- package/modules/pm2-io-agent/src/InteractorClient.js +513 -0
- package/modules/pm2-io-agent/src/InteractorDaemon.js +455 -0
- package/modules/pm2-io-agent/src/PM2Client.js +112 -0
- package/modules/pm2-io-agent/src/PM2Interface.js +180 -0
- package/modules/pm2-io-agent/src/TransporterInterface.js +173 -0
- package/modules/pm2-io-agent/src/Utility.js +392 -0
- package/modules/pm2-io-agent/src/WatchDog.js +70 -0
- package/modules/pm2-io-agent/src/push/DataRetriever.js +77 -0
- package/modules/pm2-io-agent/src/push/PushInteractor.js +206 -0
- package/modules/pm2-io-agent/src/push/TransactionAggregator.js +670 -0
- package/modules/pm2-io-agent/src/reverse/ReverseInteractor.js +128 -0
- package/modules/pm2-io-agent/src/transporters/Transporter.js +129 -0
- package/modules/pm2-io-agent/src/transporters/WebsocketTransport.js +202 -0
- package/modules/pm2-io-agent/src/utils/BinaryHeap.js +135 -0
- package/modules/pm2-io-agent/src/utils/EDS.js +111 -0
- package/modules/pm2-io-agent/src/utils/probes/Histogram.js +204 -0
- package/modules/pm2-io-agent/src/utils/units.js +10 -0
- package/modules/pm2-io-bpm/configuration.js +141 -0
- package/modules/pm2-io-bpm/constants.js +10 -0
- package/modules/pm2-io-bpm/featureManager.js +110 -0
- package/modules/pm2-io-bpm/features/dependencies.js +48 -0
- package/modules/pm2-io-bpm/features/events.js +50 -0
- package/modules/pm2-io-bpm/features/metrics.js +102 -0
- package/modules/pm2-io-bpm/features/notify.js +238 -0
- package/modules/pm2-io-bpm/features/profiling.js +70 -0
- package/modules/pm2-io-bpm/features/tracing.js +174 -0
- package/modules/pm2-io-bpm/index.js +11 -0
- package/modules/pm2-io-bpm/metrics/eventLoopMetrics.js +136 -0
- package/modules/pm2-io-bpm/metrics/httpMetrics.js +175 -0
- package/modules/pm2-io-bpm/metrics/network.js +132 -0
- package/modules/pm2-io-bpm/metrics/runtime.js +161 -0
- package/modules/pm2-io-bpm/metrics/v8.js +104 -0
- package/modules/pm2-io-bpm/otel/constants.js +7 -0
- package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/platform/index.js +17 -0
- package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/platform/node/index.js +17 -0
- package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/platform/node/util.js +51 -0
- package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/transform.js +137 -0
- package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/types.js +24 -0
- package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/utils.js +23 -0
- package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/zipkin.js +149 -0
- package/modules/pm2-io-bpm/pmx.js +380 -0
- package/modules/pm2-io-bpm/profilers/addonProfiler.js +193 -0
- package/modules/pm2-io-bpm/profilers/inspectorProfiler.js +302 -0
- package/modules/pm2-io-bpm/serviceManager.js +21 -0
- package/modules/pm2-io-bpm/services/actions.js +159 -0
- package/modules/pm2-io-bpm/services/inspector.js +43 -0
- package/modules/pm2-io-bpm/services/metrics.js +186 -0
- package/modules/pm2-io-bpm/services/runtimeStats.js +54 -0
- package/modules/pm2-io-bpm/services/transport.js +11 -0
- package/modules/pm2-io-bpm/transports/IPCTransport.js +115 -0
- package/modules/pm2-io-bpm/utils/BinaryHeap.js +134 -0
- package/modules/pm2-io-bpm/utils/EDS.js +113 -0
- package/modules/pm2-io-bpm/utils/EWMA.js +32 -0
- package/modules/pm2-io-bpm/utils/autocast.js +61 -0
- package/modules/pm2-io-bpm/utils/metrics/counter.js +33 -0
- package/modules/pm2-io-bpm/utils/metrics/gauge.js +23 -0
- package/modules/pm2-io-bpm/utils/metrics/histogram.js +192 -0
- package/modules/pm2-io-bpm/utils/metrics/meter.js +46 -0
- package/modules/pm2-io-bpm/utils/miscellaneous.js +19 -0
- package/modules/pm2-io-bpm/utils/module.js +67 -0
- package/modules/pm2-io-bpm/utils/shimmer.js +19 -0
- package/modules/pm2-io-bpm/utils/stackParser.js +160 -0
- package/modules/pm2-io-bpm/utils/transactionAggregator.js +429 -0
- package/modules/pm2-io-bpm/utils/units.js +16 -0
- package/modules/vizion/LICENSE +13 -0
- package/modules/vizion/README.md +133 -0
- package/modules/vizion/index.js +1 -0
- package/modules/vizion/lib/git/git.js +247 -0
- package/modules/vizion/lib/vizion.js +52 -0
- package/package.json +170 -4
- package/paths.js +121 -0
- package/pm2 +11 -0
- package/types/index.d.ts +732 -0
- package/types/tsconfig.json +14 -0
|
@@ -0,0 +1,429 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { EventEmitter } = require('events')
|
|
4
|
+
const Debug = require('debug')
|
|
5
|
+
const EWMA = require('./EWMA')
|
|
6
|
+
const Histogram = require('./metrics/histogram')
|
|
7
|
+
|
|
8
|
+
const fclone = (data) => JSON.parse(JSON.stringify(data))
|
|
9
|
+
const log = Debug('axm:features:tracing:aggregator')
|
|
10
|
+
|
|
11
|
+
class TransactionAggregator extends EventEmitter {
|
|
12
|
+
constructor () {
|
|
13
|
+
super()
|
|
14
|
+
|
|
15
|
+
this._spanTypes = ['redis', 'mysql', 'pg', 'mongo', 'outbound_http']
|
|
16
|
+
this._cache = {
|
|
17
|
+
routes: {},
|
|
18
|
+
meta: {
|
|
19
|
+
trace_count: 0,
|
|
20
|
+
http_meter: new EWMA(),
|
|
21
|
+
db_meter: new EWMA(),
|
|
22
|
+
histogram: new Histogram({ measurement: 'median' }),
|
|
23
|
+
db_histograms: {}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
this._privacyRegex = /":(?!\[|{)\\"[^"]*\\"|":(["'])(?:(?=(\\?))\2.)*?\1|":(?!\[|{)[^,}\]]*|":\[[^{]*]/g
|
|
27
|
+
this._worker = undefined
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
init (sendInterval) {
|
|
31
|
+
sendInterval = sendInterval || 30000
|
|
32
|
+
this._worker = setInterval(_ => {
|
|
33
|
+
let data = this.prepareAggregationforShipping()
|
|
34
|
+
this.emit('packet', { data })
|
|
35
|
+
}, sendInterval)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
destroy () {
|
|
39
|
+
if (this._worker !== undefined) {
|
|
40
|
+
clearInterval(this._worker)
|
|
41
|
+
}
|
|
42
|
+
this._cache.routes = {}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
getAggregation () {
|
|
46
|
+
return this._cache
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
validateData (packet) {
|
|
50
|
+
if (!packet) {
|
|
51
|
+
log('Packet malformated', packet)
|
|
52
|
+
return false
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (!packet.spans || !packet.spans[0]) {
|
|
56
|
+
log('Trace without spans: %s', Object.keys(packet.data))
|
|
57
|
+
return false
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (!packet.spans[0].labels) {
|
|
61
|
+
log('Trace spans without labels: %s', Object.keys(packet.spans))
|
|
62
|
+
return false
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return true
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Main method to aggregate and compute stats for traces
|
|
70
|
+
*
|
|
71
|
+
* @param {Object} packet
|
|
72
|
+
*/
|
|
73
|
+
aggregate (packet) {
|
|
74
|
+
if (this.validateData(packet) === false) return false
|
|
75
|
+
|
|
76
|
+
// Get http path of current span
|
|
77
|
+
let path = packet.spans[0].labels['http/path']
|
|
78
|
+
// Cleanup spans
|
|
79
|
+
if (process.env.PM2_APM_CENSOR_SPAMS !== '0') {
|
|
80
|
+
this.censorSpans(packet.spans)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// remove spans with startTime == endTime
|
|
84
|
+
packet.spans = packet.spans.filter((span) => {
|
|
85
|
+
return span.endTime !== span.startTime
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
// compute duration of child spans
|
|
89
|
+
packet.spans.forEach((span) => {
|
|
90
|
+
span.mean = Math.round(new Date(span.endTime).getTime() - new Date(span.startTime).getTime())
|
|
91
|
+
delete span.endTime
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
// Update app meta (mean_latency, http_meter, db_meter, trace_count)
|
|
95
|
+
packet.spans.forEach((span) => {
|
|
96
|
+
if (!span.name || !span.kind) return false
|
|
97
|
+
|
|
98
|
+
if (span.kind === 'RPC_SERVER') {
|
|
99
|
+
this._cache.meta.histogram.update(span.mean)
|
|
100
|
+
return this._cache.meta.http_meter.update(1)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Override outbount http queries for processing
|
|
104
|
+
if (span.labels && span.labels['http/method'] && span.labels['http/status_code']) {
|
|
105
|
+
span.labels['service'] = span.name
|
|
106
|
+
span.name = 'outbound_http'
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
for (let i = 0; i < this._spanTypes.length; i++) {
|
|
110
|
+
if (span.name.indexOf(this._spanTypes[i]) > -1) {
|
|
111
|
+
this._cache.meta.db_meter.update(1)
|
|
112
|
+
if (!this._cache.meta.db_histograms[this._spanTypes[i]]) {
|
|
113
|
+
this._cache.meta.db_histograms[this._spanTypes[i]] = new Histogram({ measurement: 'mean' })
|
|
114
|
+
}
|
|
115
|
+
this._cache.meta.db_histograms[this._spanTypes[i]].update(span.mean)
|
|
116
|
+
break
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
this._cache.meta.trace_count++
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Handle traces aggregation
|
|
125
|
+
*/
|
|
126
|
+
if (path[0] === '/' && path !== '/') {
|
|
127
|
+
path = path.substr(1, path.length - 1)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
let matched = this.matchPath(path, this._cache.routes)
|
|
131
|
+
|
|
132
|
+
if (!matched) {
|
|
133
|
+
this._cache.routes[path] = []
|
|
134
|
+
this.mergeTrace(this._cache.routes[path], packet)
|
|
135
|
+
} else {
|
|
136
|
+
this.mergeTrace(this._cache.routes[matched], packet)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return this._cache
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Merge new trace and compute mean, min, max, count
|
|
144
|
+
*
|
|
145
|
+
* @param {Object} aggregated previous aggregated route
|
|
146
|
+
* @param {Object} trace
|
|
147
|
+
*/
|
|
148
|
+
mergeTrace (aggregated, trace) {
|
|
149
|
+
if (!aggregated || !trace) return
|
|
150
|
+
|
|
151
|
+
// if the trace doesn't any spans stop aggregation here
|
|
152
|
+
if (trace.spans.length === 0) return
|
|
153
|
+
|
|
154
|
+
// create data structure if needed
|
|
155
|
+
if (!aggregated.variances) aggregated.variances = []
|
|
156
|
+
if (!aggregated.meta) {
|
|
157
|
+
aggregated.meta = {
|
|
158
|
+
histogram: new Histogram({ measurement: 'median' }),
|
|
159
|
+
meter: new EWMA()
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
aggregated.meta.histogram.update(trace.spans[0].mean)
|
|
164
|
+
aggregated.meta.meter.update()
|
|
165
|
+
|
|
166
|
+
const merge = (variance) => {
|
|
167
|
+
// no variance found so its a new one
|
|
168
|
+
if (variance == null) {
|
|
169
|
+
delete trace.projectId
|
|
170
|
+
delete trace.traceId
|
|
171
|
+
trace.histogram = new Histogram({ measurement: 'median' })
|
|
172
|
+
trace.histogram.update(trace.spans[0].mean)
|
|
173
|
+
|
|
174
|
+
trace.spans.forEach((span) => {
|
|
175
|
+
span.histogram = new Histogram({ measurement: 'median' })
|
|
176
|
+
span.histogram.update(span.mean)
|
|
177
|
+
delete span.mean
|
|
178
|
+
})
|
|
179
|
+
|
|
180
|
+
// parse strackrace
|
|
181
|
+
// this.parseStacktrace(trace.spans)
|
|
182
|
+
aggregated.variances.push(trace)
|
|
183
|
+
} else {
|
|
184
|
+
// variance found, merge spans
|
|
185
|
+
variance.histogram.update(trace.spans[0].mean)
|
|
186
|
+
|
|
187
|
+
// update duration of spans to be mean
|
|
188
|
+
this.updateSpanDuration(variance.spans, trace.spans)
|
|
189
|
+
|
|
190
|
+
// delete stacktrace before merging
|
|
191
|
+
trace.spans.forEach((span) => {
|
|
192
|
+
delete span.labels.stacktrace
|
|
193
|
+
})
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// for every variance, check spans same variance
|
|
198
|
+
for (let i = 0; i < aggregated.variances.length; i++) {
|
|
199
|
+
if (this.compareList(aggregated.variances[i].spans, trace.spans)) {
|
|
200
|
+
return merge(aggregated.variances[i])
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
// else its a new variance
|
|
204
|
+
return merge(null)
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Parkour simultaneously both spans list to update value of the first one using value of the second one
|
|
209
|
+
* The first should be variance already aggregated for which we want to merge the second one
|
|
210
|
+
* The second one is a new trace, so we need to re-compute mean/min/max time for each spans
|
|
211
|
+
*/
|
|
212
|
+
updateSpanDuration (spans, newSpans) {
|
|
213
|
+
for (let i = 0; i < spans.length; i++) {
|
|
214
|
+
if (!newSpans[i]) continue
|
|
215
|
+
spans[i].histogram.update(newSpans[i].mean)
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Compare two spans list by going down on each span and comparing child and attribute
|
|
221
|
+
*/
|
|
222
|
+
compareList (one, two) {
|
|
223
|
+
if (one.length !== two.length) return false
|
|
224
|
+
|
|
225
|
+
for (let i = 0; i < one.length; i++) {
|
|
226
|
+
if (one[i].name !== two[i].name) return false
|
|
227
|
+
if (one[i].kind !== two[i].kind) return false
|
|
228
|
+
if (!one[i].labels && two[i].labels) return false
|
|
229
|
+
if (one[i].labels && !two[i].labels) return false
|
|
230
|
+
if (one[i].labels.length !== two[i].labels.length) return false
|
|
231
|
+
}
|
|
232
|
+
return true
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Will return the route if we found an already matched route
|
|
237
|
+
*/
|
|
238
|
+
matchPath (path, routes) {
|
|
239
|
+
// empty route is / without the fist slash
|
|
240
|
+
if (!path || !routes) return false
|
|
241
|
+
if (path === '/') return routes[path] ? path : null
|
|
242
|
+
|
|
243
|
+
// remove the last slash if exist
|
|
244
|
+
if (path[path.length - 1] === '/') {
|
|
245
|
+
path = path.substr(0, path.length - 1)
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// split to get array of segment
|
|
249
|
+
path = path.split('/')
|
|
250
|
+
|
|
251
|
+
// if the path has only one segment, we just need to compare the key
|
|
252
|
+
if (path.length === 1) return routes[path[0]] ? routes[path[0]] : null
|
|
253
|
+
|
|
254
|
+
// check in routes already stored for match
|
|
255
|
+
let keys = Object.keys(routes)
|
|
256
|
+
for (let i = 0; i < keys.length; i++) {
|
|
257
|
+
let route = keys[i]
|
|
258
|
+
let segments = route.split('/')
|
|
259
|
+
|
|
260
|
+
if (segments.length !== path.length) continue
|
|
261
|
+
|
|
262
|
+
for (let j = path.length - 1; j >= 0; j--) {
|
|
263
|
+
// different segment, try to find if new route or not
|
|
264
|
+
if (path[j] !== segments[j]) {
|
|
265
|
+
// if the aggregator already have matched that segment with a wildcard and the next segment is the same
|
|
266
|
+
if (this.isIdentifier(path[j]) && segments[j] === '*' && path[j - 1] === segments[j - 1]) {
|
|
267
|
+
return segments.join('/')
|
|
268
|
+
// case a let in url match, so we continue because they must be other let in url
|
|
269
|
+
} else if (path[j - 1] !== undefined && path[j - 1] === segments[j - 1] && this.isIdentifier(path[j]) && this.isIdentifier(segments[j])) {
|
|
270
|
+
segments[j] = '*'
|
|
271
|
+
// update routes in cache
|
|
272
|
+
routes[segments.join('/')] = routes[route]
|
|
273
|
+
delete routes[keys[i]]
|
|
274
|
+
return segments.join('/')
|
|
275
|
+
} else {
|
|
276
|
+
break
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// if finish to iterate over segment of path, we must be on the same route
|
|
281
|
+
if (j === 0) return segments.join('/')
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Normalize aggregation
|
|
288
|
+
*/
|
|
289
|
+
prepareAggregationforShipping () {
|
|
290
|
+
let routes = this._cache.routes
|
|
291
|
+
|
|
292
|
+
const normalized = {
|
|
293
|
+
routes: [],
|
|
294
|
+
meta: {
|
|
295
|
+
trace_count: this._cache.meta.trace_count,
|
|
296
|
+
http_meter: Math.round(this._cache.meta.http_meter.rate(1000) * 100) / 100,
|
|
297
|
+
db_meter: Math.round(this._cache.meta.db_meter.rate(1000) * 100) / 100,
|
|
298
|
+
http_percentiles: {
|
|
299
|
+
median: this._cache.meta.histogram.percentiles([0.5])[0.5],
|
|
300
|
+
p95: this._cache.meta.histogram.percentiles([0.95])[0.95],
|
|
301
|
+
p99: this._cache.meta.histogram.percentiles([0.99])[0.99]
|
|
302
|
+
},
|
|
303
|
+
db_percentiles: {}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
// compute percentiles for each db spans if they exist
|
|
308
|
+
this._spanTypes.forEach((name) => {
|
|
309
|
+
let histogram = this._cache.meta.db_histograms[name]
|
|
310
|
+
if (!histogram) return
|
|
311
|
+
normalized.meta.db_percentiles[name] = histogram.percentiles([0.5])[0.5]
|
|
312
|
+
})
|
|
313
|
+
|
|
314
|
+
Object.keys(routes).forEach((path) => {
|
|
315
|
+
let data = routes[path]
|
|
316
|
+
|
|
317
|
+
// hard check for invalid data
|
|
318
|
+
if (!data.variances || data.variances.length === 0) return
|
|
319
|
+
|
|
320
|
+
// get top 5 variances of the same route
|
|
321
|
+
const variances = data.variances.sort((a, b) => {
|
|
322
|
+
return b.count - a.count
|
|
323
|
+
}).slice(0, 5)
|
|
324
|
+
|
|
325
|
+
// create a copy without reference to stored one
|
|
326
|
+
let routeCopy = {
|
|
327
|
+
path: path === '/' ? '/' : '/' + path,
|
|
328
|
+
meta: {
|
|
329
|
+
min: data.meta.histogram.getMin(),
|
|
330
|
+
max: data.meta.histogram.getMax(),
|
|
331
|
+
count: data.meta.histogram.getCount(),
|
|
332
|
+
meter: Math.round(data.meta.meter.rate(1000) * 100) / 100,
|
|
333
|
+
median: data.meta.histogram.percentiles([0.5])[0.5],
|
|
334
|
+
p95: data.meta.histogram.percentiles([0.95])[0.95]
|
|
335
|
+
},
|
|
336
|
+
variances: []
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
variances.forEach((variance) => {
|
|
340
|
+
// hard check for invalid data
|
|
341
|
+
if (!variance.spans || variance.spans.length === 0) return
|
|
342
|
+
|
|
343
|
+
// deep copy of variances data
|
|
344
|
+
let tmp = {
|
|
345
|
+
spans: [],
|
|
346
|
+
count: variance.histogram.getCount(),
|
|
347
|
+
min: variance.histogram.getMin(),
|
|
348
|
+
max: variance.histogram.getMax(),
|
|
349
|
+
median: variance.histogram.percentiles([0.5])[0.5],
|
|
350
|
+
p95: variance.histogram.percentiles([0.95])[0.95]
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
// get data for each span
|
|
354
|
+
variance.spans.forEach((oldSpan) => {
|
|
355
|
+
const span = fclone({
|
|
356
|
+
name: oldSpan.name,
|
|
357
|
+
labels: oldSpan.labels,
|
|
358
|
+
kind: oldSpan.kind,
|
|
359
|
+
startTime: oldSpan.startTime,
|
|
360
|
+
min: oldSpan.histogram ? oldSpan.histogram.getMin() : undefined,
|
|
361
|
+
max: oldSpan.histogram ? oldSpan.histogram.getMax() : undefined,
|
|
362
|
+
median: oldSpan.histogram ? oldSpan.histogram.percentiles([0.5])[0.5] : undefined
|
|
363
|
+
})
|
|
364
|
+
tmp.spans.push(span)
|
|
365
|
+
})
|
|
366
|
+
// push serialized into normalized data
|
|
367
|
+
routeCopy.variances.push(tmp)
|
|
368
|
+
})
|
|
369
|
+
// push the route into normalized data
|
|
370
|
+
normalized.routes.push(routeCopy)
|
|
371
|
+
})
|
|
372
|
+
log(`sending formatted trace to remote endpoint`)
|
|
373
|
+
return normalized
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* Check if the string can be a id of some sort
|
|
378
|
+
*
|
|
379
|
+
* @param {String} id
|
|
380
|
+
*/
|
|
381
|
+
isIdentifier (id) {
|
|
382
|
+
id = typeof (id) !== 'string' ? id + '' : id
|
|
383
|
+
|
|
384
|
+
// uuid v1/v4 with/without dash
|
|
385
|
+
if (id.match(/[0-9a-f]{8}-[0-9a-f]{4}-[14][0-9a-f]{3}-[0-9a-f]{4}-[0-9a-f]{12}|[0-9a-f]{12}[14][0-9a-f]{19}/i)) {
|
|
386
|
+
return true
|
|
387
|
+
// if number
|
|
388
|
+
} else if (id.match(/\d+/)) {
|
|
389
|
+
return true
|
|
390
|
+
// if suit of nbr/letters
|
|
391
|
+
} else if (id.match(/[0-9]+[a-z]+|[a-z]+[0-9]+/)) {
|
|
392
|
+
return true
|
|
393
|
+
// if match pattern with multiple char spaced by . - _ @
|
|
394
|
+
} else if (id.match(/((?:[0-9a-zA-Z]+[@\-_.][0-9a-zA-Z]+|[0-9a-zA-Z]+[@\-_.]|[@\-_.][0-9a-zA-Z]+)+)/)) {
|
|
395
|
+
return true
|
|
396
|
+
}
|
|
397
|
+
return false
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* Cleanup trace data
|
|
402
|
+
* - delete result(s)
|
|
403
|
+
* - replace labels value with a question mark
|
|
404
|
+
*
|
|
405
|
+
* @param {Object} spans list of span for a trace
|
|
406
|
+
*/
|
|
407
|
+
censorSpans (spans) {
|
|
408
|
+
if (!spans) return log('spans is null')
|
|
409
|
+
|
|
410
|
+
spans.forEach((span) => {
|
|
411
|
+
if (!span.labels) return
|
|
412
|
+
|
|
413
|
+
delete span.labels.results
|
|
414
|
+
delete span.labels.result
|
|
415
|
+
delete span.spanId
|
|
416
|
+
delete span.parentSpanId
|
|
417
|
+
delete span.labels.values
|
|
418
|
+
delete span.labels.stacktrace
|
|
419
|
+
|
|
420
|
+
Object.keys(span.labels).forEach((key) => {
|
|
421
|
+
if (typeof (span.labels[key]) === 'string' && key !== 'stacktrace') {
|
|
422
|
+
span.labels[key] = span.labels[key].replace(this._privacyRegex, '\": \"?\"')
|
|
423
|
+
}
|
|
424
|
+
})
|
|
425
|
+
})
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
module.exports = { TransactionAggregator }
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const MILLISECONDS = 1
|
|
4
|
+
const SECONDS = 1000 * MILLISECONDS
|
|
5
|
+
const MINUTES = 60 * SECONDS
|
|
6
|
+
const HOURS = 60 * MINUTES
|
|
7
|
+
|
|
8
|
+
module.exports = {
|
|
9
|
+
NANOSECONDS: 1 / (1000 * 1000),
|
|
10
|
+
MICROSECONDS: 1 / 1000,
|
|
11
|
+
MILLISECONDS: MILLISECONDS,
|
|
12
|
+
SECONDS: SECONDS,
|
|
13
|
+
MINUTES: MINUTES,
|
|
14
|
+
HOURS: HOURS,
|
|
15
|
+
DAYS: 24 * HOURS
|
|
16
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Copyright 2016 Keymetrics, Inc.
|
|
2
|
+
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License.
|
|
5
|
+
You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
See the License for the specific language governing permissions and
|
|
13
|
+
limitations under the License.
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
|
|
2
|
+
# Repository parser
|
|
3
|
+
|
|
4
|
+
Git/Subversion/Mercurial repository metadata parser
|
|
5
|
+
|
|
6
|
+
[]
|
|
7
|
+
|
|
8
|
+
## Example
|
|
9
|
+
|
|
10
|
+
```javascript
|
|
11
|
+
var vizion = require('vizion');
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Grab metadata for svn/git/hg repositories
|
|
15
|
+
*/
|
|
16
|
+
vizion.analyze({
|
|
17
|
+
folder : '/tmp/folder'
|
|
18
|
+
}, function(err, meta) {
|
|
19
|
+
if (err) throw new Error(err);
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
*
|
|
23
|
+
* meta = {
|
|
24
|
+
* type : 'git',
|
|
25
|
+
* ahead : false,
|
|
26
|
+
* unstaged : false,
|
|
27
|
+
* branch : 'development',
|
|
28
|
+
* remotes : [ 'http', 'http ssl', 'origin' ],
|
|
29
|
+
* remote : 'origin',
|
|
30
|
+
* commment : 'This is a comment',
|
|
31
|
+
* update_time : Tue Oct 28 2014 14:33:30 GMT+0100 (CET),
|
|
32
|
+
* url : 'https://github.com/keymetrics/vizion.git',
|
|
33
|
+
* revision : 'f0a1d45936cf7a3c969e4caba96546fd23255796',
|
|
34
|
+
* next_rev : null, // null if its latest in the branch
|
|
35
|
+
* prev_rev : '6d6932dac9c82f8a29ff40c1d5300569c24aa2c8'
|
|
36
|
+
* }
|
|
37
|
+
*
|
|
38
|
+
*/
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Check if a local repository is up to date with its remote
|
|
43
|
+
*/
|
|
44
|
+
vizion.isUpToDate({
|
|
45
|
+
folder : '/tmp/folder'
|
|
46
|
+
}, function(err, meta) {
|
|
47
|
+
if (err) throw new Error(err);
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
*
|
|
51
|
+
* meta = {
|
|
52
|
+
* is_up_to_date : false,
|
|
53
|
+
* new_revision : '6d6932dac9c82f8a29ff40c1d5300569c24aa2c8'
|
|
54
|
+
* current_revision : 'f0a1d45936cf7a3c969e4caba96546fd23255796'
|
|
55
|
+
* }
|
|
56
|
+
*
|
|
57
|
+
*/
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Update the local repository to latest commit found on the remote for its current branch
|
|
62
|
+
* - on fail it rollbacks to the latest commit
|
|
63
|
+
*/
|
|
64
|
+
vizion.update({
|
|
65
|
+
folder : '/tmp/folder'
|
|
66
|
+
}, function(err, meta) {
|
|
67
|
+
if (err) throw new Error(err);
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
*
|
|
71
|
+
* meta = {
|
|
72
|
+
* success : true,
|
|
73
|
+
* current_revision : '6d6932dac9c82f8a29ff40c1d5300569c24aa2c8'
|
|
74
|
+
* }
|
|
75
|
+
*
|
|
76
|
+
*/
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Revert to a specified commit
|
|
81
|
+
* - Eg: this does a git reset --hard <commit_revision>
|
|
82
|
+
*/
|
|
83
|
+
vizion.revertTo({
|
|
84
|
+
revision : 'f0a1d45936cf7a3c969e4caba96546fd23255796',
|
|
85
|
+
folder : '/tmp/folder'
|
|
86
|
+
}, function(err, data) {
|
|
87
|
+
if (err) throw new Error(err);
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
*
|
|
91
|
+
* data = {
|
|
92
|
+
* success : true,
|
|
93
|
+
* }
|
|
94
|
+
*
|
|
95
|
+
*/
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* If a previous commit exists it checkouts on it
|
|
100
|
+
*/
|
|
101
|
+
vizion.prev({
|
|
102
|
+
folder : '/tmp/folder'
|
|
103
|
+
}, function(err, meta) {
|
|
104
|
+
if (err) throw new Error(err);
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
*
|
|
108
|
+
* meta = {
|
|
109
|
+
* success : true,
|
|
110
|
+
* current_revision : '6d6932dac9c82f8a29ff40c1d5300569c24aa2c8'
|
|
111
|
+
* }
|
|
112
|
+
*
|
|
113
|
+
*/
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* If a more recent commit exists it checkouts on it
|
|
118
|
+
*/
|
|
119
|
+
vizion.next({
|
|
120
|
+
folder : '/tmp/folder'
|
|
121
|
+
}, function(err, meta) {
|
|
122
|
+
if (err) throw new Error(err);
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
*
|
|
126
|
+
* meta = {
|
|
127
|
+
* success : false,
|
|
128
|
+
* current_revision : '6d6932dac9c82f8a29ff40c1d5300569c24aa2c8'
|
|
129
|
+
* }
|
|
130
|
+
*
|
|
131
|
+
*/
|
|
132
|
+
});
|
|
133
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./lib/vizion.js');
|