Skip to content

Commit

Permalink
5.0.0 - bump packages
Browse files Browse the repository at this point in the history
  • Loading branch information
Unitech committed Mar 30, 2021
1 parent 7b09b73 commit fcc5e84
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 140 deletions.
23 changes: 11 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pm2/io",
"version": "4.3.5",
"version": "5.0.0",
"description": "PM2.io NodeJS APM",
"main": "build/main/index.js",
"typings": "build/main/index.d.ts",
Expand Down Expand Up @@ -40,6 +40,7 @@
"node": ">=6.0"
},
"devDependencies": {
"@pm2/node-runtime-stats": "^0.3.2",
"@types/chai": "4.1.4",
"@types/express": "~4.16.1",
"@types/ioredis": "~4.0.6",
Expand All @@ -48,23 +49,22 @@
"@types/node": "~10.12.21",
"@types/redis": "~2.8.10",
"chai": "4.1.2",
"mocha": "~7.1.0",
"nock": "~10.0.6",
"nyc": "~13.1.0",
"source-map-support": "~0.5.9",
"ts-node": "~7.0.1",
"tslint": "~5.11.0",
"tslint-config-standard": "~8.0.1",
"typescript": "~3.2.2",
"@pm2/node-runtime-stats": "^0.3.2",
"express": "^4.17.1",
"ioredis": "^4.16.3",
"koa": "^2.11.0",
"mocha": "~7.1.0",
"mongodb-core": "^3.2.7",
"mysql": "^2.18.1",
"mysql2": "^2.1.0",
"nock": "~10.0.6",
"nyc": "~13.1.0",
"pg": "^7.18.2",
"redis": "^3.0.2",
"source-map-support": "~0.5.9",
"ts-node": "~7.0.1",
"tslint": "~5.11.0",
"tslint-config-standard": "~8.0.1",
"typescript": "~3.2.2",
"vue": "^2.6.11",
"vue-server-renderer": "^2.6.11"
},
Expand All @@ -85,9 +85,8 @@
"dependencies": {
"@opencensus/core": "0.0.9",
"@opencensus/propagation-b3": "0.0.8",
"@pm2/agent-node": "^1.1.10",
"async": "~2.6.1",
"debug": "4.1.1",
"debug": "~4.3.1",
"eventemitter2": "^6.3.1",
"require-in-the-middle": "^5.0.0",
"semver": "6.3.0",
Expand Down
33 changes: 18 additions & 15 deletions src/services/transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { Action } from './actions'
import { Metric, InternalMetric } from './metrics'
import { IPCTransport } from '../transports/IPCTransport'
import { WebsocketTransport } from '../transports/WebsocketTransport'
// import { WebsocketTransport } from '../transports/WebsocketTransport'
import { EventEmitter2 } from 'eventemitter2'

export class TransportConfig {
Expand Down Expand Up @@ -80,18 +80,21 @@ export interface Transport extends EventEmitter2 {
* Init a transporter implementation with a specific config
*/
export function createTransport (name: string, config: TransportConfig): Transport {
switch (name) {
case 'ipc': {
const transport = new IPCTransport()
transport.init(config)
return transport
}
case 'websocket': {
const transport = new WebsocketTransport()
transport.init(config)
return transport
}
}
console.error(`Failed to find transport implementation: ${name}`)
return process.exit(1)
const transport = new IPCTransport()
transport.init(config)
return transport
// switch (name) {
// case 'ipc': {
// const transport = new IPCTransport()
// transport.init(config)
// return transport
// }
// case 'websocket': {
// const transport = new WebsocketTransport()
// transport.init(config)
// return transport
// }
// }
// console.error(`Failed to find transport implementation: ${name}`)
// return process.exit(1)
}
222 changes: 111 additions & 111 deletions src/transports/WebsocketTransport.ts
Original file line number Diff line number Diff line change
@@ -1,125 +1,125 @@
import { Transport, TransportConfig } from '../services/transport'
import Debug from 'debug'
import { Action } from '../services/actions'
import { InternalMetric } from '../services/metrics'
import { EventEmitter2 } from 'eventemitter2'
// import { Transport, TransportConfig } from '../services/transport'
// import Debug from 'debug'
// import { Action } from '../services/actions'
// import { InternalMetric } from '../services/metrics'
// import { EventEmitter2 } from 'eventemitter2'

class SerializedAction {
action_name: string // tslint:disable-line
action_type: string // tslint:disable-line
opts: Object | null | undefined
arity: number
}
// class SerializedAction {
// action_name: string // tslint:disable-line
// action_type: string // tslint:disable-line
// opts: Object | null | undefined
// arity: number
// }

export class ProcessMetadata {
axm_actions: SerializedAction[] // tslint:disable-line
axm_monitor: Object // tslint:disable-line
axm_options: Object // tslint:disable-line
axm_dynamic?: Object // tslint:disable-line
interpreter?: string
versionning?: Object
}
// export class ProcessMetadata {
// axm_actions: SerializedAction[] // tslint:disable-line
// axm_monitor: Object // tslint:disable-line
// axm_options: Object // tslint:disable-line
// axm_dynamic?: Object // tslint:disable-line
// interpreter?: string
// versionning?: Object
// }

export class WebsocketTransport extends EventEmitter2 implements Transport {
// export class WebsocketTransport extends EventEmitter2 implements Transport {

private config: TransportConfig
private agent: any
private process: ProcessMetadata
private initiated: Boolean = false // tslint:disable-line
private logger: Function = Debug('axm:transport:websocket')
// private config: TransportConfig
// private agent: any
// private process: ProcessMetadata
// private initiated: Boolean = false // tslint:disable-line
// private logger: Function = Debug('axm:transport:websocket')

init (config: TransportConfig): Transport {
if (this.initiated === true) {
console.error(`Trying to re-init the transport, please avoid`)
return this
}
this.initiated = true
const AgentNode = require('@pm2/agent-node')
this.logger('Init new transport service')
this.config = config
this.process = {
axm_actions: [],
axm_options: {},
axm_monitor: {}
}
this.agent = new AgentNode(this.config, this.process)
if (this.agent instanceof Error) {
throw this.agent
}
this.agent.sendLogs = config.sendLogs || false
this.agent.start()
this.agent.transport.on('**', (data) => {
this.logger(`Received reverse message from websocket transport`)
this.emit('data', data)
})
this.logger('Agent launched')
return this
}
// init (config: TransportConfig): Transport {
// if (this.initiated === true) {
// console.error(`Trying to re-init the transport, please avoid`)
// return this
// }
// this.initiated = true
// const AgentNode = require('@pm2/agent-node')
// this.logger('Init new transport service')
// this.config = config
// this.process = {
// axm_actions: [],
// axm_options: {},
// axm_monitor: {}
// }
// this.agent = new AgentNode(this.config, this.process)
// if (this.agent instanceof Error) {
// throw this.agent
// }
// this.agent.sendLogs = config.sendLogs || false
// this.agent.start()
// this.agent.transport.on('**', (data) => {
// this.logger(`Received reverse message from websocket transport`)
// this.emit('data', data)
// })
// this.logger('Agent launched')
// return this
// }

setMetrics (metrics: InternalMetric[]) {
return this.process.axm_monitor = metrics.reduce((object, metric: InternalMetric) => {
if (typeof metric.name !== 'string') return object
object[metric.name] = {
unit: metric.unit,
type: metric.id,
value: metric.value
}
if (metric.historic == false)
object[metric.name] = false
return object
}, {})
}
// setMetrics (metrics: InternalMetric[]) {
// return this.process.axm_monitor = metrics.reduce((object, metric: InternalMetric) => {
// if (typeof metric.name !== 'string') return object
// object[metric.name] = {
// unit: metric.unit,
// type: metric.id,
// value: metric.value
// }
// if (metric.historic == false)
// object[metric.name] = false
// return object
// }, {})
// }

addAction (action: Action) {
this.logger(`Add action: ${action.name}:${action.type}`)
const serializedAction: SerializedAction = {
action_name: action.name,
action_type: action.type,
arity: action.arity,
opts: action.opts
}
this.process.axm_actions.push(serializedAction)
}
// addAction (action: Action) {
// this.logger(`Add action: ${action.name}:${action.type}`)
// const serializedAction: SerializedAction = {
// action_name: action.name,
// action_type: action.type,
// arity: action.arity,
// opts: action.opts
// }
// this.process.axm_actions.push(serializedAction)
// }

setOptions (options) {
this.logger(`Set options: [${Object.keys(options).join(',')}]`)
return this.process.axm_options = Object.assign(this.process.axm_options, options)
}
// setOptions (options) {
// this.logger(`Set options: [${Object.keys(options).join(',')}]`)
// return this.process.axm_options = Object.assign(this.process.axm_options, options)
// }

private getFormattedPayload (channel: string, payload: any) {
// Reformat for backend
switch (channel) {
case 'axm:reply':
return { data: payload }
case 'process:exception':
return { data: payload }
case 'human:event': {
const name = payload.__name
payload.__name = undefined
return { name, data: payload }
}
}
return payload
}
// private getFormattedPayload (channel: string, payload: any) {
// // Reformat for backend
// switch (channel) {
// case 'axm:reply':
// return { data: payload }
// case 'process:exception':
// return { data: payload }
// case 'human:event': {
// const name = payload.__name
// payload.__name = undefined
// return { name, data: payload }
// }
// }
// return payload
// }

send (channel: string, payload: Object) {
return this.agent.send(channel, this.getFormattedPayload(channel, payload)) ? 0 : -1
}
// send (channel: string, payload: Object) {
// return this.agent.send(channel, this.getFormattedPayload(channel, payload)) ? 0 : -1
// }

destroy () {
this.agent.transport.disconnect()
this.logger('destroy')
}
// destroy () {
// this.agent.transport.disconnect()
// this.logger('destroy')
// }

removeListener () {
return this.agent.transport.removeListener.apply(this, arguments)
}
// removeListener () {
// return this.agent.transport.removeListener.apply(this, arguments)
// }

removeAllListeners () {
return this.agent.transport.removeAllListeners.apply(this, arguments)
}
// removeAllListeners () {
// return this.agent.transport.removeAllListeners.apply(this, arguments)
// }

on () {
return this.agent.transport.on.apply(this, arguments)
}
}
// on () {
// return this.agent.transport.on.apply(this, arguments)
// }
// }
4 changes: 2 additions & 2 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ $MOCHA ./test/api.spec.ts
$MOCHA ./test/metrics/http.spec.ts
$MOCHA ./test/metrics/runtime.spec.ts
$MOCHA ./test/entrypoint.spec.ts
$MOCHA ./test/standalone/tracing.spec.ts
$MOCHA ./test/standalone/events.spec.ts
# $MOCHA ./test/standalone/tracing.spec.ts
# $MOCHA ./test/standalone/events.spec.ts
$MOCHA ./test/features/events.spec.ts
$MOCHA ./test/features/tracing.spec.ts
$MOCHA ./test/metrics/eventloop.spec.ts
Expand Down

0 comments on commit fcc5e84

Please sign in to comment.