mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-04-25 10:32:14 +00:00
chore: update deps (#1285)
This commit is contained in:
parent
5af93883ce
commit
e6f646ed36
@ -98,7 +98,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@achingbrain/nat-port-mapper": "^1.0.3",
|
"@achingbrain/nat-port-mapper": "^1.0.3",
|
||||||
"@libp2p/components": "^2.0.0",
|
"@libp2p/components": "^2.0.1",
|
||||||
"@libp2p/connection": "^4.0.0",
|
"@libp2p/connection": "^4.0.0",
|
||||||
"@libp2p/crypto": "^1.0.0",
|
"@libp2p/crypto": "^1.0.0",
|
||||||
"@libp2p/interface-address-manager": "^1.0.1",
|
"@libp2p/interface-address-manager": "^1.0.1",
|
||||||
@ -106,7 +106,7 @@
|
|||||||
"@libp2p/interface-connection-encrypter": "^1.0.2",
|
"@libp2p/interface-connection-encrypter": "^1.0.2",
|
||||||
"@libp2p/interface-content-routing": "^1.0.1",
|
"@libp2p/interface-content-routing": "^1.0.1",
|
||||||
"@libp2p/interface-dht": "^1.0.0",
|
"@libp2p/interface-dht": "^1.0.0",
|
||||||
"@libp2p/interface-metrics": "^1.0.2",
|
"@libp2p/interface-metrics": "^2.0.0",
|
||||||
"@libp2p/interface-peer-discovery": "^1.0.0",
|
"@libp2p/interface-peer-discovery": "^1.0.0",
|
||||||
"@libp2p/interface-peer-id": "^1.0.2",
|
"@libp2p/interface-peer-id": "^1.0.2",
|
||||||
"@libp2p/interface-peer-info": "^1.0.1",
|
"@libp2p/interface-peer-info": "^1.0.1",
|
||||||
@ -124,7 +124,7 @@
|
|||||||
"@libp2p/peer-id-factory": "^1.0.9",
|
"@libp2p/peer-id-factory": "^1.0.9",
|
||||||
"@libp2p/peer-record": "^3.0.0",
|
"@libp2p/peer-record": "^3.0.0",
|
||||||
"@libp2p/peer-store": "^3.0.0",
|
"@libp2p/peer-store": "^3.0.0",
|
||||||
"@libp2p/tracked-map": "^2.0.0",
|
"@libp2p/tracked-map": "^2.0.1",
|
||||||
"@libp2p/utils": "^3.0.0",
|
"@libp2p/utils": "^3.0.0",
|
||||||
"@multiformats/mafmt": "^11.0.2",
|
"@multiformats/mafmt": "^11.0.2",
|
||||||
"@multiformats/multiaddr": "^10.1.8",
|
"@multiformats/multiaddr": "^10.1.8",
|
||||||
@ -178,7 +178,7 @@
|
|||||||
"@libp2p/interface-mocks": "^3.0.1",
|
"@libp2p/interface-mocks": "^3.0.1",
|
||||||
"@libp2p/interop": "^2.0.0",
|
"@libp2p/interop": "^2.0.0",
|
||||||
"@libp2p/kad-dht": "^3.0.0",
|
"@libp2p/kad-dht": "^3.0.0",
|
||||||
"@libp2p/mdns": "^2.0.0",
|
"@libp2p/mdns": "^3.0.0",
|
||||||
"@libp2p/mplex": "^4.0.0",
|
"@libp2p/mplex": "^4.0.0",
|
||||||
"@libp2p/pubsub": "^3.0.1",
|
"@libp2p/pubsub": "^3.0.1",
|
||||||
"@libp2p/tcp": "^3.0.0",
|
"@libp2p/tcp": "^3.0.0",
|
||||||
|
@ -7,7 +7,6 @@ import retimer from 'retimer'
|
|||||||
import type { AbortOptions } from '@libp2p/interfaces'
|
import type { AbortOptions } from '@libp2p/interfaces'
|
||||||
import { CustomEvent, EventEmitter } from '@libp2p/interfaces/events'
|
import { CustomEvent, EventEmitter } from '@libp2p/interfaces/events'
|
||||||
import type { Startable } from '@libp2p/interfaces/startable'
|
import type { Startable } from '@libp2p/interfaces/startable'
|
||||||
import { trackedMap } from '@libp2p/tracked-map'
|
|
||||||
import { codes } from '../errors.js'
|
import { codes } from '../errors.js'
|
||||||
import { isPeerId, PeerId } from '@libp2p/interface-peer-id'
|
import { isPeerId, PeerId } from '@libp2p/interface-peer-id'
|
||||||
import { setMaxListeners } from 'events'
|
import { setMaxListeners } from 'events'
|
||||||
@ -36,8 +35,8 @@ const defaultOptions: Partial<ConnectionManagerInit> = {
|
|||||||
movingAverageInterval: 60000
|
movingAverageInterval: 60000
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const METRICS_SYSTEM = 'libp2p'
|
||||||
const METRICS_COMPONENT = 'connection-manager'
|
const METRICS_COMPONENT = 'connection-manager'
|
||||||
const METRICS_PEER_CONNECTIONS = 'peer-connections'
|
|
||||||
const STARTUP_RECONNECT_TIMEOUT = 60000
|
const STARTUP_RECONNECT_TIMEOUT = 60000
|
||||||
|
|
||||||
export interface ConnectionManagerInit {
|
export interface ConnectionManagerInit {
|
||||||
@ -162,11 +161,7 @@ export class DefaultConnectionManager extends EventEmitter<ConnectionManagerEven
|
|||||||
/**
|
/**
|
||||||
* Map of connections per peer
|
* Map of connections per peer
|
||||||
*/
|
*/
|
||||||
this.connections = trackedMap({
|
this.connections = new Map()
|
||||||
component: METRICS_COMPONENT,
|
|
||||||
metric: METRICS_PEER_CONNECTIONS,
|
|
||||||
metrics: this.components.getMetrics()
|
|
||||||
})
|
|
||||||
|
|
||||||
this.started = false
|
this.started = false
|
||||||
this._checkMetrics = this._checkMetrics.bind(this)
|
this._checkMetrics = this._checkMetrics.bind(this)
|
||||||
@ -193,6 +188,94 @@ export class DefaultConnectionManager extends EventEmitter<ConnectionManagerEven
|
|||||||
this.components = components
|
this.components = components
|
||||||
|
|
||||||
this.dialer.init(components)
|
this.dialer.init(components)
|
||||||
|
|
||||||
|
// track inbound/outbound connections
|
||||||
|
this.components.getMetrics()?.updateComponentMetric({
|
||||||
|
system: METRICS_SYSTEM,
|
||||||
|
component: METRICS_COMPONENT,
|
||||||
|
metric: 'connections',
|
||||||
|
label: 'direction',
|
||||||
|
value: () => {
|
||||||
|
const metric = {
|
||||||
|
inbound: 0,
|
||||||
|
outbound: 0
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const conns of this.connections.values()) {
|
||||||
|
for (const conn of conns) {
|
||||||
|
if (conn.stat.direction === 'inbound') {
|
||||||
|
metric.inbound++
|
||||||
|
} else {
|
||||||
|
metric.outbound++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return metric
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// track total number of streams per protocol
|
||||||
|
this.components.getMetrics()?.updateComponentMetric({
|
||||||
|
system: METRICS_SYSTEM,
|
||||||
|
component: METRICS_COMPONENT,
|
||||||
|
metric: 'protocol-streams-total',
|
||||||
|
label: 'protocol',
|
||||||
|
value: () => {
|
||||||
|
const metric: Record<string, number> = {}
|
||||||
|
|
||||||
|
for (const conns of this.connections.values()) {
|
||||||
|
for (const conn of conns) {
|
||||||
|
for (const stream of conn.streams) {
|
||||||
|
const key = `${stream.stat.direction} ${stream.stat.protocol ?? 'unnegotiated'}`
|
||||||
|
|
||||||
|
metric[key] = (metric[key] ?? 0) + 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return metric
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// track 90th percentile of streams per protocol
|
||||||
|
this.components.getMetrics()?.updateComponentMetric({
|
||||||
|
system: METRICS_SYSTEM,
|
||||||
|
component: METRICS_COMPONENT,
|
||||||
|
metric: 'protocol-streams-per-connection-90th-percentile',
|
||||||
|
label: 'protocol',
|
||||||
|
value: () => {
|
||||||
|
const allStreams: Record<string, number[]> = {}
|
||||||
|
|
||||||
|
for (const conns of this.connections.values()) {
|
||||||
|
for (const conn of conns) {
|
||||||
|
const streams: Record<string, number> = {}
|
||||||
|
|
||||||
|
for (const stream of conn.streams) {
|
||||||
|
const key = `${stream.stat.direction} ${stream.stat.protocol ?? 'unnegotiated'}`
|
||||||
|
|
||||||
|
streams[key] = (streams[key] ?? 0) + 1
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const [protocol, count] of Object.entries(streams)) {
|
||||||
|
allStreams[protocol] = allStreams[protocol] ?? []
|
||||||
|
allStreams[protocol].push(count)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const metric: Record<string, number> = {}
|
||||||
|
|
||||||
|
for (let [protocol, counts] of Object.entries(allStreams)) {
|
||||||
|
counts = counts.sort((a, b) => a - b)
|
||||||
|
|
||||||
|
const index = Math.floor(counts.length * 0.9)
|
||||||
|
metric[protocol] = counts[index]
|
||||||
|
}
|
||||||
|
|
||||||
|
return metric
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
isStarted () {
|
isStarted () {
|
||||||
|
@ -3,7 +3,7 @@ import each from 'it-foreach'
|
|||||||
import LRU from 'hashlru'
|
import LRU from 'hashlru'
|
||||||
import { METRICS as defaultOptions } from '../constants.js'
|
import { METRICS as defaultOptions } from '../constants.js'
|
||||||
import { DefaultStats, StatsInit } from './stats.js'
|
import { DefaultStats, StatsInit } from './stats.js'
|
||||||
import type { ComponentMetricsUpdate, Metrics, Stats, TrackStreamOptions } from '@libp2p/interface-metrics'
|
import type { ComponentMetricsUpdate, Metrics, Stats, TrackedMetric, TrackStreamOptions } from '@libp2p/interface-metrics'
|
||||||
import type { PeerId } from '@libp2p/interface-peer-id'
|
import type { PeerId } from '@libp2p/interface-peer-id'
|
||||||
import type { Startable } from '@libp2p/interfaces/startable'
|
import type { Startable } from '@libp2p/interfaces/startable'
|
||||||
import type { Duplex } from 'it-stream-types'
|
import type { Duplex } from 'it-stream-types'
|
||||||
@ -41,7 +41,7 @@ export class DefaultMetrics implements Metrics, Startable {
|
|||||||
private readonly protocolStats: Map<string, DefaultStats>
|
private readonly protocolStats: Map<string, DefaultStats>
|
||||||
private readonly oldPeers: ReturnType<typeof LRU>
|
private readonly oldPeers: ReturnType<typeof LRU>
|
||||||
private running: boolean
|
private running: boolean
|
||||||
private readonly systems: Map<string, Map<string, Map<string, number>>>
|
private readonly systems: Map<string, Map<string, Map<string, TrackedMetric>>>
|
||||||
private readonly statsInit: StatsInit
|
private readonly statsInit: StatsInit
|
||||||
|
|
||||||
constructor (init: MetricsInit) {
|
constructor (init: MetricsInit) {
|
||||||
@ -115,7 +115,7 @@ export class DefaultMetrics implements Metrics, Startable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
updateComponentMetric (update: ComponentMetricsUpdate) {
|
updateComponentMetric (update: ComponentMetricsUpdate) {
|
||||||
const { system = 'libp2p', component, metric, value } = update
|
const { system = 'libp2p', component, metric, value, label, help } = update
|
||||||
|
|
||||||
if (!this.systems.has(system)) {
|
if (!this.systems.has(system)) {
|
||||||
this.systems.set(system, new Map())
|
this.systems.set(system, new Map())
|
||||||
@ -137,7 +137,11 @@ export class DefaultMetrics implements Metrics, Startable {
|
|||||||
throw new Error('Unknown metric component')
|
throw new Error('Unknown metric component')
|
||||||
}
|
}
|
||||||
|
|
||||||
componentMetrics.set(metric, value)
|
componentMetrics.set(metric, {
|
||||||
|
label,
|
||||||
|
help,
|
||||||
|
calculate: typeof value !== 'function' ? () => value : value
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -296,6 +296,6 @@ describe('Metrics', () => {
|
|||||||
|
|
||||||
expect(metrics.getComponentMetrics()).to.have.lengthOf(1)
|
expect(metrics.getComponentMetrics()).to.have.lengthOf(1)
|
||||||
expect(metrics.getComponentMetrics().get('libp2p')?.get(component)).to.have.lengthOf(1)
|
expect(metrics.getComponentMetrics().get('libp2p')?.get(component)).to.have.lengthOf(1)
|
||||||
expect(metrics.getComponentMetrics().get('libp2p')?.get(component)?.get(metric)).to.equal(value)
|
expect(metrics.getComponentMetrics().get('libp2p')?.get(component)?.get(metric)?.calculate()).to.equal(value)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user