-
-
Notifications
You must be signed in to change notification settings - Fork 312
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update libp2p to ESM version (#4114)
* WIP * Revert eslint changes * Revert dependency update * Revert dependencies * Revert yarn.lock * Update yarn.lock * Update noise * Fix lint errors * Update discv5 * Fix linter errors * Fix check-types * Fix up libp2p connection manager handling * Update gossipsub * Add import statement * Use upstream GossipsubEvents type * Remove stray lint disable comment * Only ping a single peer when it connects * Update gossipsub * libp2p-gossipsub 3.5.0 * Use libp2p-noise 7.0.3 * Use @libp2p/mplex 4.0.3 * Fix write heap dump in libp2p esm branch (#4387) * Remove 'require' check in writeHeapDump * Fix BELLATRIX_FORK_EPOCH * Update libp2p dependencies * Bump libp2p * Fix heap memory issue * Fix some tests * Fix type error * Fix req/resp 'index out of bounds' issue * Fix linter errors * Add libp2p metrics and dashboard * Update gossipsub and set max outbound buffer size * Update @libp2p/tcp * Update uint8arrays * v0.0.0 * Lint libp2p grafana dashboard * Add leveldown dev dependency * Set msgIdToStrFn to Buffer.toString * Do not set udp to enr (#4591) * Fix e2e reqresp test * Fix lint * Fix unit tests * Update yarn.lock after merge * Update libp2p Co-authored-by: Tuyen Nguyen <[email protected]> Co-authored-by: tuyennhv <[email protected]>
- Loading branch information
1 parent
1beeb2b
commit c2377f2
Showing
105 changed files
with
2,618 additions
and
1,649 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import {Libp2p} from "libp2p"; | ||
import {GaugeExtra} from "../utils/gauge.js"; | ||
import {RegistryMetricCreator} from "../utils/registryMetricCreator.js"; | ||
|
||
export type ILibp2pMetrics = ReturnType<typeof createLibp2pMetrics>; | ||
|
||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/explicit-function-return-type | ||
export function createLibp2pMetrics(libp2p: Libp2p, register: RegistryMetricCreator) { | ||
const libp2pMetrics = libp2p.metrics; | ||
if (libp2pMetrics === undefined) { | ||
return; | ||
} | ||
|
||
const metrics: Record<string, GaugeExtra<string>> = {}; | ||
|
||
const ensureLibp2pMetrics = async (): Promise<void> => { | ||
// protocol metrics | ||
const protocols = libp2pMetrics.getProtocols(); | ||
protocols.forEach((protocol) => { | ||
const protocolStat = libp2pMetrics.forProtocol(protocol); | ||
if (protocolStat === undefined) { | ||
return; | ||
} | ||
|
||
// create metric if undefined | ||
if (metrics[protocol] === undefined) { | ||
const name = `libp2p_protocol_${protocol}_bytes`.replace(/(\/|-|\.)/g, "_"); | ||
metrics[protocol] = register.gauge<"direction">({ | ||
name, | ||
help: name, | ||
labelNames: ["direction"], | ||
}); | ||
} | ||
|
||
// set metric | ||
const protocolSnapshot = protocolStat.getSnapshot(); | ||
metrics[protocol].set({direction: "received"}, Number(protocolSnapshot.dataReceived)); | ||
metrics[protocol].set({direction: "sent"}, Number(protocolSnapshot.dataSent)); | ||
}); | ||
|
||
// component metrics | ||
for (const [systemName, systemMetrics] of libp2pMetrics.getComponentMetrics().entries()) { | ||
for (const [componentName, componentMetrics] of systemMetrics.entries()) { | ||
for (const [metricName, trackedMetric] of componentMetrics.entries()) { | ||
// In practice `systemName` is always libp2p | ||
const name = `${systemName}_${componentName}_${metricName}`.replace(/-/g, "_"); | ||
|
||
// create metric if undefined | ||
if (metrics[name] === undefined) { | ||
metrics[name] = register.gauge({ | ||
name, | ||
help: trackedMetric.help ?? name, | ||
labelNames: trackedMetric.label !== undefined ? [trackedMetric.label] : [], | ||
}); | ||
} | ||
|
||
// set metric | ||
const m = await trackedMetric.calculate(); | ||
if (typeof m === "number") { | ||
metrics[name].set(m); | ||
} else { | ||
const labelName = trackedMetric.label ?? name; | ||
Object.entries(m).forEach(([label, value]) => { | ||
metrics[name].set({[labelName]: label}, value); | ||
}); | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
|
||
metrics.global = register.gauge<"direction">({ | ||
name: "libp2p_global_stats", | ||
help: "libp2p global stats", | ||
labelNames: ["direction"], | ||
collect: async () => { | ||
const globalSnapshot = libp2pMetrics.getGlobal().getSnapshot(); | ||
metrics.global.set({direction: "received"}, Number(globalSnapshot.dataReceived)); | ||
metrics.global.set({direction: "sent"}, Number(globalSnapshot.dataSent)); | ||
|
||
await ensureLibp2pMetrics(); | ||
}, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.