@milaboratories/pl-middle-layer 1.76.5 → 2.0.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/dist/index.cjs +3 -9
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/middle_layer/block.cjs +1 -1
- package/dist/middle_layer/block.js +1 -1
- package/dist/middle_layer/build_stamp.cjs +1 -1
- package/dist/middle_layer/build_stamp.js +1 -1
- package/dist/middle_layer/driver_kit.cjs +2 -2
- package/dist/middle_layer/driver_kit.cjs.map +1 -1
- package/dist/middle_layer/driver_kit.js +2 -2
- package/dist/middle_layer/driver_kit.js.map +1 -1
- package/dist/middle_layer/folders.cjs +1 -1
- package/dist/middle_layer/folders.d.ts +1 -1
- package/dist/middle_layer/folders.js +1 -1
- package/dist/middle_layer/frontend_path.cjs +1 -1
- package/dist/middle_layer/frontend_path.js +1 -1
- package/dist/middle_layer/index.cjs +3 -0
- package/dist/middle_layer/index.d.ts +2 -1
- package/dist/middle_layer/index.js +2 -1
- package/dist/middle_layer/instance_stats.cjs +125 -0
- package/dist/middle_layer/instance_stats.cjs.map +1 -0
- package/dist/middle_layer/instance_stats.d.ts +16 -0
- package/dist/middle_layer/instance_stats.d.ts.map +1 -0
- package/dist/middle_layer/instance_stats.js +122 -0
- package/dist/middle_layer/instance_stats.js.map +1 -0
- package/dist/middle_layer/middle_layer.cjs +14 -1
- package/dist/middle_layer/middle_layer.cjs.map +1 -1
- package/dist/middle_layer/middle_layer.d.ts +10 -2
- package/dist/middle_layer/middle_layer.d.ts.map +1 -1
- package/dist/middle_layer/middle_layer.js +14 -1
- package/dist/middle_layer/middle_layer.js.map +1 -1
- package/dist/middle_layer/ops.cjs.map +1 -1
- package/dist/middle_layer/ops.d.ts +1 -14
- package/dist/middle_layer/ops.d.ts.map +1 -1
- package/dist/middle_layer/ops.js.map +1 -1
- package/dist/middle_layer/project.cjs +2 -2
- package/dist/middle_layer/project.d.ts +1 -1
- package/dist/middle_layer/project.js +2 -2
- package/dist/middle_layer/project_list.cjs +1 -1
- package/dist/middle_layer/project_list.d.ts +1 -1
- package/dist/middle_layer/project_list.js +1 -1
- package/dist/middle_layer/project_overview.cjs +1 -1
- package/dist/middle_layer/project_overview.js +1 -1
- package/dist/middle_layer/sharing_list.cjs +1 -1
- package/dist/middle_layer/sharing_list.d.ts +1 -1
- package/dist/middle_layer/sharing_list.js +1 -1
- package/dist/middle_layer/template_list.cjs +1 -1
- package/dist/middle_layer/template_list.js +1 -1
- package/dist/middle_layer/types.d.ts +1 -1
- package/dist/network_check/network_check.cjs +2 -2
- package/dist/network_check/network_check.cjs.map +1 -1
- package/dist/network_check/network_check.js +2 -2
- package/dist/network_check/network_check.js.map +1 -1
- package/dist/network_check/pings.cjs +1 -1
- package/dist/network_check/pings.js +1 -1
- package/dist/pool/result_pool.d.ts +1 -1
- package/package.json +24 -24
- package/src/index.ts +0 -1
- package/src/middle_layer/close_dead_link.test.ts +0 -1
- package/src/middle_layer/driver_kit.ts +1 -2
- package/src/middle_layer/index.ts +1 -0
- package/src/middle_layer/init_latency_benchmark.test.ts +0 -1
- package/src/middle_layer/instance_stats.test.ts +135 -0
- package/src/middle_layer/instance_stats.ts +173 -0
- package/src/middle_layer/middle_layer.ts +16 -0
- package/src/middle_layer/ops.ts +0 -15
- package/src/middle_layer/render.test.ts +11 -3
- package/src/middle_layer/tree_snapshot_scenarios.test.ts +0 -1
- package/src/network_check/network_check.ts +2 -14
- package/src/test/with_ml.ts +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ops.cjs","names":["ConsoleLoggerAdapter","PFrameDriverOpsDefaults","path"],"sources":["../../src/middle_layer/ops.ts"],"sourcesContent":["import type { TemporalSynchronizedTreeOps } from \"./types\";\nimport type {\n DownloadBlobToURLDriverOps,\n DownloadDriverOps,\n DownloadUrlDriverOps,\n OpenFileDialogCallback,\n VirtualLocalStorageSpec,\n} from \"@milaboratories/pl-drivers\";\nimport type { UploadDriverOps } from \"@milaboratories/pl-drivers\";\nimport type { LogsStreamDriverOps } from \"@milaboratories/pl-drivers\";\nimport type { MiLogger } from \"@milaboratories/ts-helpers\";\nimport { ConsoleLoggerAdapter } from \"@milaboratories/ts-helpers\";\nimport type { LocalStorageProjection } from \"@milaboratories/pl-drivers\";\nimport path from \"node:path\";\nimport { PFrameDriverOpsDefaults, type PFrameDriverOps, type ParquetCacheOps } from \"../pool\";\n\n/** Paths part of {@link DriverKitOps}. */\nexport type DriverKitOpsPaths = {\n /** Common root where to put downloaded blobs / downloaded blob cache */\n readonly blobDownloadPath: string;\n\n /** Common root for a cache for range queries. */\n readonly blobDownloadRangesCachePath: string;\n\n /** Common root where to put downloaded blobs with */\n readonly downloadBlobToURLPath: string;\n\n /**\n * List of pl storages that have projections in local file system.\n *\n * This option affect two drivers:\n *\n * (1) LS driver generates \"index\" handles instead of \"upload\" for paths inside those locations\n *\n * (2) Download driver directly serves content retrieval requests for blobs from listed storages,\n * and don't apply any caching for such blobs (i.e. preventing duplication of files for Downloaded\n * type handles, making OnDemand and Downloaded handles equivalent)\n *\n * */\n readonly localProjections: LocalStorageProjection[];\n\n /**\n * List of virtual storages that will allow homogeneous access to local FSs through LS API.\n * If undefined, default list will be created.\n * */\n readonly virtualLocalStoragesOverride?: VirtualLocalStorageSpec[];\n\n /** Path to the directory where pframes will spill temporary files and store materialized views */\n readonly pframesSpillPath: string;\n\n /**\n * Path to the directory backing the persistent parquet blob cache. Unlike\n * {@link pframesSpillPath} this directory is NOT emptied on startup - the cache\n * (and its lifetime counters) is meant to survive restarts.\n */\n readonly parquetCachePath: string;\n};\n\n/** Options required to initialize full set of middle layer driver kit */\nexport type DriverKitOpsSettings = {\n //\n // Common\n //\n\n readonly logger: MiLogger;\n\n //\n // Signer\n //\n\n /**\n * Local secret, that is used to sign and verify different pieces of information\n * that can be used to access local data, like local paths for ongoing uploads.\n *\n * Use {@link MiddleLayer.generateLocalSecret} to generate sufficiently random string.\n * */\n readonly localSecret: string;\n\n //\n // Blob Driver\n //\n\n /**\n * Settings related to the download driver making operations with blobs. This driver is also used\n * to download logs when source process terminates and log terns into a blob\n */\n readonly blobDriverOps: DownloadDriverOps;\n\n //\n // Frontend Driver\n //\n\n /** Settings related to the frontend driver that downloads frontends. */\n readonly frontendDownloadDriverOps: DownloadUrlDriverOps;\n\n //\n // Blob To URL Driver\n //\n\n readonly downloadBlobToURLDriverOps: DownloadBlobToURLDriverOps;\n\n //\n // Upload Driver\n //\n\n /**\n * Settings related to the upload driver that actually performs upload and helps render upload\n * and indexing progresses from related pl resources.\n * */\n readonly uploadDriverOps: UploadDriverOps;\n\n //\n // Log streaming ops\n // (static logs are served via the blob driver)\n //\n\n /** Settings related to the streaming log driver */\n readonly logStreamDriverOps: LogsStreamDriverOps;\n\n //\n // LS Driver\n //\n\n /**\n * Callback to access system file open dialog, must be provided by the environment,\n * to allow for {@link showOpenSingleFileDialog} / {@link showOpenMultipleFilesDialog}\n * calls from the UI.\n */\n readonly openFileDialogCallback: OpenFileDialogCallback;\n\n //\n // PFrame Driver\n //\n\n /** Settings related to the PFrame driver */\n readonly pFrameDriverOps: PFrameDriverOps;\n\n /**\n * Tuning for the persistent parquet blob cache. Its directory is\n * {@link DriverKitOpsPaths.parquetCachePath}; this carries only the\n * size/eviction knobs.\n */\n readonly parquetCacheOps: ParquetCacheOps;\n};\n\nexport type DriverKitOps = DriverKitOpsPaths & DriverKitOpsSettings;\n\n/** Some defaults fot MiddleLayerOps. */\nexport const DefaultDriverKitOpsSettings: Pick<\n DriverKitOpsSettings,\n | \"logger\"\n | \"blobDriverOps\"\n | \"frontendDownloadDriverOps\"\n | \"downloadBlobToURLDriverOps\"\n | \"uploadDriverOps\"\n | \"logStreamDriverOps\"\n | \"pFrameDriverOps\"\n | \"parquetCacheOps\"\n> = {\n logger: new ConsoleLoggerAdapter(),\n blobDriverOps: {\n cacheSoftSizeBytes: 8 * 1024 * 1024 * 1024, // 8 GB\n rangesCacheMaxSizeBytes: 8 * 1024 * 1024 * 1024, // 8 GB\n nConcurrentDownloads: 10,\n },\n frontendDownloadDriverOps: {\n cacheSoftSizeBytes: 1 * 1024 * 1024 * 1024, // 1 GB\n withGunzip: true,\n nConcurrentDownloads: 50,\n },\n downloadBlobToURLDriverOps: {\n cacheSoftSizeBytes: 1 * 1024 * 1024 * 1024, // 1 GB\n nConcurrentDownloads: 10,\n },\n uploadDriverOps: {\n nConcurrentPartUploads: 10,\n nConcurrentGetProgresses: 10,\n pollingInterval: 1000,\n stopPollingDelay: 1000,\n },\n logStreamDriverOps: {\n nConcurrentGetLogs: 10,\n pollingInterval: 1000,\n stopPollingDelay: 1000,\n },\n pFrameDriverOps: PFrameDriverOpsDefaults,\n parquetCacheOps: {\n maxSizeBytes: 8 * 1024 * 1024 * 1024, // 8 GB\n admissionFraction: 0.2, // a single file may occupy at most 20% of the budget\n maxFilesTracked: 50_000, // ghost (previously-evicted) files remembered to guide readmission\n },\n};\n\nexport function DefaultDriverKitOpsPaths(\n workDir: string,\n): Pick<\n DriverKitOpsPaths,\n | \"blobDownloadPath\"\n | \"blobDownloadRangesCachePath\"\n | \"downloadBlobToURLPath\"\n | \"pframesSpillPath\"\n | \"parquetCachePath\"\n> {\n return {\n blobDownloadPath: path.join(workDir, \"download\"),\n blobDownloadRangesCachePath: path.join(workDir, \"downloadRangesCache\"),\n downloadBlobToURLPath: path.join(workDir, \"downloadToURL\"),\n pframesSpillPath: path.join(workDir, \"pframes\"),\n parquetCachePath: path.join(workDir, \"parquetCache\"),\n };\n}\n\n/** Fields with default values are marked as optional here. */\nexport type DriverKitOpsConstructor = Omit<\n DriverKitOpsSettings,\n keyof typeof DefaultDriverKitOpsSettings\n> &\n Partial<typeof DefaultDriverKitOpsSettings> &\n Omit<DriverKitOpsPaths, keyof ReturnType<typeof DefaultDriverKitOpsPaths>> &\n Partial<ReturnType<typeof DefaultDriverKitOpsPaths>>;\n\nexport type MiddleLayerOpsPaths = DriverKitOpsPaths & {\n /** Common root where to put frontend code. */\n readonly frontendDownloadPath: string;\n\n /**\n * Directory holding persisted project tree mirrors, one file per project. Like\n * {@link DriverKitOpsPaths.parquetCachePath} and unlike the spill directories, it is NOT\n * emptied on startup: surviving a restart is the entire point. It is pruned instead, see\n * {@link TreeSnapshotOps.maxSizeBytes}.\n */\n readonly treeSnapshotPath: string;\n};\n\n/** Tuning for the persisted project tree mirrors. Their directory is\n * {@link MiddleLayerOpsPaths.treeSnapshotPath}; this carries the behaviour knobs. */\nexport type TreeSnapshotOps = {\n /**\n * Whether project tree mirrors are persisted and restored at all.\n *\n * On by default. This is an operational kill switch, for a deployment where the cache\n * directory turns out to be unwritable or otherwise troublesome, not a rollout gate: the\n * floor of the feature is current behaviour, since a cache that never hits is a cold open.\n */\n readonly enabled: boolean;\n\n /**\n * Minimum wall-clock gap between periodic writes for one project.\n *\n * Can be generous, because a stale snapshot is less complete rather than wrong: final\n * resources never change and are never refetched, so this only bounds how much recent work\n * comes back from the non-final frontier on restore.\n */\n readonly writeInterval: number;\n\n /** Total bytes the snapshot directory may occupy after startup eviction. Needed because a\n * heavy project runs to roughly ten megabytes. */\n readonly maxSizeBytes: number;\n};\n\n/** Debug options for middle layer. */\nexport type MiddleLayerDebugOptions = {\n /** If true, will dump initial tree state to the file with root resource id as name. */\n dumpInitialTreeState: boolean;\n};\n\n/** Configuration controlling different aspects of middle layer behaviour. */\nexport type MiddleLayerOpsSettings = DriverKitOpsSettings & {\n /** Debug options. */\n readonly debugOps: MiddleLayerDebugOptions;\n\n /** Contain temporal options controlling how often should pl trees be\n * synchronized with the pl server. */\n readonly defaultTreeOptions: TemporalSynchronizedTreeOps;\n\n /** Defines interval in milliseconds for running periodic project maintenance job.\n * Project maintenance includes background staging rendering and cached outputs cleanup. */\n readonly projectRefreshInterval: number;\n\n /** How often to check for dev block updates */\n readonly devBlockUpdateRecheckInterval: number;\n\n /** Prioritize this channel if update is available in this block */\n readonly preferredUpdateChannel?: string;\n\n /** Default lifetime applied to a targeted shared envelope at creation, as\n * `sharedAt + envelopeTtlMs`. Share-with-everybody envelopes never expire\n * (`expiresAt: null`) and ignore this. */\n readonly envelopeTtlMs: number;\n\n /** Settings for persisting project tree mirrors to disk, so reopening a project transfers\n * what changed rather than the tree again. */\n readonly treeSnapshotOps: TreeSnapshotOps;\n};\n\nexport type MiddleLayerOps = MiddleLayerOpsSettings & MiddleLayerOpsPaths;\n\n/** Some defaults fot MiddleLayerOps. */\nexport const DefaultMiddleLayerOpsSettings: Pick<\n MiddleLayerOps,\n | keyof typeof DefaultDriverKitOpsSettings\n | \"defaultTreeOptions\"\n | \"projectRefreshInterval\"\n | \"devBlockUpdateRecheckInterval\"\n | \"debugOps\"\n | \"envelopeTtlMs\"\n | \"treeSnapshotOps\"\n> = {\n ...DefaultDriverKitOpsSettings,\n defaultTreeOptions: {\n pollingInterval: 200,\n stopPollingDelay: 2500,\n initialTreeLoadingTimeout: 100 * 60 * 60 * 1000, // disable timeout for loading project tree (100 hours)\n },\n debugOps: {\n dumpInitialTreeState: false,\n },\n devBlockUpdateRecheckInterval: 1000,\n projectRefreshInterval: 2000,\n envelopeTtlMs: 14 * 24 * 3600 * 1000, // 14 days\n treeSnapshotOps: {\n enabled: true,\n writeInterval: 5 * 60 * 1000, // 5 minutes\n maxSizeBytes: 256 * 1024 * 1024, // 256 MB, roughly 25 heavy projects\n },\n};\n\nexport function DefaultMiddleLayerOpsPaths(\n workDir: string,\n): Pick<\n MiddleLayerOpsPaths,\n keyof ReturnType<typeof DefaultDriverKitOpsPaths> | \"frontendDownloadPath\" | \"treeSnapshotPath\"\n> {\n return {\n ...DefaultDriverKitOpsPaths(workDir),\n frontendDownloadPath: path.join(workDir, \"frontend\"),\n treeSnapshotPath: path.join(workDir, \"treeSnapshots\"),\n };\n}\n\nexport type MiddleLayerOpsConstructor = Omit<\n MiddleLayerOpsSettings,\n keyof typeof DefaultMiddleLayerOpsSettings\n> &\n Partial<typeof DefaultMiddleLayerOpsSettings> &\n Omit<MiddleLayerOpsPaths, keyof Awaited<ReturnType<typeof DefaultMiddleLayerOpsPaths>>> &\n Partial<Awaited<ReturnType<typeof DefaultMiddleLayerOpsPaths>>>;\n"],"mappings":";;;;;;;AAoJA,MAAa,8BAUT;CACF,QAAQ,K,oCAAIA,EAAAA,CAAAA,qBAAqB;CACjC,eAAe;EACb,oBAAoB;EACpB,yBAAyB;EACzB,sBAAsB;CACxB;CACA,2BAA2B;EACzB,oBAAoB;EACpB,YAAY;EACZ,sBAAsB;CACxB;CACA,4BAA4B;EAC1B,oBAAoB;EACpB,sBAAsB;CACxB;CACA,iBAAiB;EACf,wBAAwB;EACxB,0BAA0B;EAC1B,iBAAiB;EACjB,kBAAkB;CACpB;CACA,oBAAoB;EAClB,oBAAoB;EACpB,iBAAiB;EACjB,kBAAkB;CACpB;CACA,iBAAiBC,eAAAA;CACjB,iBAAiB;EACf,cAAc;EACd,mBAAmB;EACnB,iBAAiB;CACnB;AACF;AAEA,SAAgB,yBACd,SAQA;CACA,OAAO;EACL,kBAAkBC,UAAAA,QAAK,KAAK,SAAS,UAAU;EAC/C,6BAA6BA,UAAAA,QAAK,KAAK,SAAS,qBAAqB;EACrE,uBAAuBA,UAAAA,QAAK,KAAK,SAAS,eAAe;EACzD,kBAAkBA,UAAAA,QAAK,KAAK,SAAS,SAAS;EAC9C,kBAAkBA,UAAAA,QAAK,KAAK,SAAS,cAAc;CACrD;AACF;;AAwFA,MAAa,gCAST;CACF,GAAG;CACH,oBAAoB;EAClB,iBAAiB;EACjB,kBAAkB;EAClB,2BAA2B;CAC7B;CACA,UAAU,EACR,sBAAsB,MACxB;CACA,+BAA+B;CAC/B,wBAAwB;CACxB,eAAe;CACf,iBAAiB;EACf,SAAS;EACT,eAAe;EACf,cAAc;CAChB;AACF;AAEA,SAAgB,2BACd,SAIA;CACA,OAAO;EACL,GAAG,yBAAyB,OAAO;EACnC,sBAAsBA,UAAAA,QAAK,KAAK,SAAS,UAAU;EACnD,kBAAkBA,UAAAA,QAAK,KAAK,SAAS,eAAe;CACtD;AACF"}
|
|
1
|
+
{"version":3,"file":"ops.cjs","names":["ConsoleLoggerAdapter","PFrameDriverOpsDefaults","path"],"sources":["../../src/middle_layer/ops.ts"],"sourcesContent":["import type { TemporalSynchronizedTreeOps } from \"./types\";\nimport type {\n DownloadBlobToURLDriverOps,\n DownloadDriverOps,\n DownloadUrlDriverOps,\n OpenFileDialogCallback,\n VirtualLocalStorageSpec,\n} from \"@milaboratories/pl-drivers\";\nimport type { UploadDriverOps } from \"@milaboratories/pl-drivers\";\nimport type { LogsStreamDriverOps } from \"@milaboratories/pl-drivers\";\nimport type { MiLogger } from \"@milaboratories/ts-helpers\";\nimport { ConsoleLoggerAdapter } from \"@milaboratories/ts-helpers\";\nimport path from \"node:path\";\nimport { PFrameDriverOpsDefaults, type PFrameDriverOps, type ParquetCacheOps } from \"../pool\";\n\n/** Paths part of {@link DriverKitOps}. */\nexport type DriverKitOpsPaths = {\n /** Common root where to put downloaded blobs / downloaded blob cache */\n readonly blobDownloadPath: string;\n\n /** Common root for a cache for range queries. */\n readonly blobDownloadRangesCachePath: string;\n\n /** Common root where to put downloaded blobs with */\n readonly downloadBlobToURLPath: string;\n\n /**\n * List of virtual storages that will allow homogeneous access to local FSs through LS API.\n * If undefined, default list will be created.\n * */\n readonly virtualLocalStoragesOverride?: VirtualLocalStorageSpec[];\n\n /** Path to the directory where pframes will spill temporary files and store materialized views */\n readonly pframesSpillPath: string;\n\n /**\n * Path to the directory backing the persistent parquet blob cache. Unlike\n * {@link pframesSpillPath} this directory is NOT emptied on startup - the cache\n * (and its lifetime counters) is meant to survive restarts.\n */\n readonly parquetCachePath: string;\n};\n\n/** Options required to initialize full set of middle layer driver kit */\nexport type DriverKitOpsSettings = {\n //\n // Common\n //\n\n readonly logger: MiLogger;\n\n //\n // Signer\n //\n\n /**\n * Local secret, that is used to sign and verify different pieces of information\n * that can be used to access local data, like local paths for ongoing uploads.\n *\n * Use {@link MiddleLayer.generateLocalSecret} to generate sufficiently random string.\n * */\n readonly localSecret: string;\n\n //\n // Blob Driver\n //\n\n /**\n * Settings related to the download driver making operations with blobs. This driver is also used\n * to download logs when source process terminates and log terns into a blob\n */\n readonly blobDriverOps: DownloadDriverOps;\n\n //\n // Frontend Driver\n //\n\n /** Settings related to the frontend driver that downloads frontends. */\n readonly frontendDownloadDriverOps: DownloadUrlDriverOps;\n\n //\n // Blob To URL Driver\n //\n\n readonly downloadBlobToURLDriverOps: DownloadBlobToURLDriverOps;\n\n //\n // Upload Driver\n //\n\n /**\n * Settings related to the upload driver that actually performs upload and helps render upload\n * and indexing progresses from related pl resources.\n * */\n readonly uploadDriverOps: UploadDriverOps;\n\n //\n // Log streaming ops\n // (static logs are served via the blob driver)\n //\n\n /** Settings related to the streaming log driver */\n readonly logStreamDriverOps: LogsStreamDriverOps;\n\n //\n // LS Driver\n //\n\n /**\n * Callback to access system file open dialog, must be provided by the environment,\n * to allow for {@link showOpenSingleFileDialog} / {@link showOpenMultipleFilesDialog}\n * calls from the UI.\n */\n readonly openFileDialogCallback: OpenFileDialogCallback;\n\n //\n // PFrame Driver\n //\n\n /** Settings related to the PFrame driver */\n readonly pFrameDriverOps: PFrameDriverOps;\n\n /**\n * Tuning for the persistent parquet blob cache. Its directory is\n * {@link DriverKitOpsPaths.parquetCachePath}; this carries only the\n * size/eviction knobs.\n */\n readonly parquetCacheOps: ParquetCacheOps;\n};\n\nexport type DriverKitOps = DriverKitOpsPaths & DriverKitOpsSettings;\n\n/** Some defaults fot MiddleLayerOps. */\nexport const DefaultDriverKitOpsSettings: Pick<\n DriverKitOpsSettings,\n | \"logger\"\n | \"blobDriverOps\"\n | \"frontendDownloadDriverOps\"\n | \"downloadBlobToURLDriverOps\"\n | \"uploadDriverOps\"\n | \"logStreamDriverOps\"\n | \"pFrameDriverOps\"\n | \"parquetCacheOps\"\n> = {\n logger: new ConsoleLoggerAdapter(),\n blobDriverOps: {\n cacheSoftSizeBytes: 8 * 1024 * 1024 * 1024, // 8 GB\n rangesCacheMaxSizeBytes: 8 * 1024 * 1024 * 1024, // 8 GB\n nConcurrentDownloads: 10,\n },\n frontendDownloadDriverOps: {\n cacheSoftSizeBytes: 1 * 1024 * 1024 * 1024, // 1 GB\n withGunzip: true,\n nConcurrentDownloads: 50,\n },\n downloadBlobToURLDriverOps: {\n cacheSoftSizeBytes: 1 * 1024 * 1024 * 1024, // 1 GB\n nConcurrentDownloads: 10,\n },\n uploadDriverOps: {\n nConcurrentPartUploads: 10,\n nConcurrentGetProgresses: 10,\n pollingInterval: 1000,\n stopPollingDelay: 1000,\n },\n logStreamDriverOps: {\n nConcurrentGetLogs: 10,\n pollingInterval: 1000,\n stopPollingDelay: 1000,\n },\n pFrameDriverOps: PFrameDriverOpsDefaults,\n parquetCacheOps: {\n maxSizeBytes: 8 * 1024 * 1024 * 1024, // 8 GB\n admissionFraction: 0.2, // a single file may occupy at most 20% of the budget\n maxFilesTracked: 50_000, // ghost (previously-evicted) files remembered to guide readmission\n },\n};\n\nexport function DefaultDriverKitOpsPaths(\n workDir: string,\n): Pick<\n DriverKitOpsPaths,\n | \"blobDownloadPath\"\n | \"blobDownloadRangesCachePath\"\n | \"downloadBlobToURLPath\"\n | \"pframesSpillPath\"\n | \"parquetCachePath\"\n> {\n return {\n blobDownloadPath: path.join(workDir, \"download\"),\n blobDownloadRangesCachePath: path.join(workDir, \"downloadRangesCache\"),\n downloadBlobToURLPath: path.join(workDir, \"downloadToURL\"),\n pframesSpillPath: path.join(workDir, \"pframes\"),\n parquetCachePath: path.join(workDir, \"parquetCache\"),\n };\n}\n\n/** Fields with default values are marked as optional here. */\nexport type DriverKitOpsConstructor = Omit<\n DriverKitOpsSettings,\n keyof typeof DefaultDriverKitOpsSettings\n> &\n Partial<typeof DefaultDriverKitOpsSettings> &\n Omit<DriverKitOpsPaths, keyof ReturnType<typeof DefaultDriverKitOpsPaths>> &\n Partial<ReturnType<typeof DefaultDriverKitOpsPaths>>;\n\nexport type MiddleLayerOpsPaths = DriverKitOpsPaths & {\n /** Common root where to put frontend code. */\n readonly frontendDownloadPath: string;\n\n /**\n * Directory holding persisted project tree mirrors, one file per project. Like\n * {@link DriverKitOpsPaths.parquetCachePath} and unlike the spill directories, it is NOT\n * emptied on startup: surviving a restart is the entire point. It is pruned instead, see\n * {@link TreeSnapshotOps.maxSizeBytes}.\n */\n readonly treeSnapshotPath: string;\n};\n\n/** Tuning for the persisted project tree mirrors. Their directory is\n * {@link MiddleLayerOpsPaths.treeSnapshotPath}; this carries the behaviour knobs. */\nexport type TreeSnapshotOps = {\n /**\n * Whether project tree mirrors are persisted and restored at all.\n *\n * On by default. This is an operational kill switch, for a deployment where the cache\n * directory turns out to be unwritable or otherwise troublesome, not a rollout gate: the\n * floor of the feature is current behaviour, since a cache that never hits is a cold open.\n */\n readonly enabled: boolean;\n\n /**\n * Minimum wall-clock gap between periodic writes for one project.\n *\n * Can be generous, because a stale snapshot is less complete rather than wrong: final\n * resources never change and are never refetched, so this only bounds how much recent work\n * comes back from the non-final frontier on restore.\n */\n readonly writeInterval: number;\n\n /** Total bytes the snapshot directory may occupy after startup eviction. Needed because a\n * heavy project runs to roughly ten megabytes. */\n readonly maxSizeBytes: number;\n};\n\n/** Debug options for middle layer. */\nexport type MiddleLayerDebugOptions = {\n /** If true, will dump initial tree state to the file with root resource id as name. */\n dumpInitialTreeState: boolean;\n};\n\n/** Configuration controlling different aspects of middle layer behaviour. */\nexport type MiddleLayerOpsSettings = DriverKitOpsSettings & {\n /** Debug options. */\n readonly debugOps: MiddleLayerDebugOptions;\n\n /** Contain temporal options controlling how often should pl trees be\n * synchronized with the pl server. */\n readonly defaultTreeOptions: TemporalSynchronizedTreeOps;\n\n /** Defines interval in milliseconds for running periodic project maintenance job.\n * Project maintenance includes background staging rendering and cached outputs cleanup. */\n readonly projectRefreshInterval: number;\n\n /** How often to check for dev block updates */\n readonly devBlockUpdateRecheckInterval: number;\n\n /** Prioritize this channel if update is available in this block */\n readonly preferredUpdateChannel?: string;\n\n /** Default lifetime applied to a targeted shared envelope at creation, as\n * `sharedAt + envelopeTtlMs`. Share-with-everybody envelopes never expire\n * (`expiresAt: null`) and ignore this. */\n readonly envelopeTtlMs: number;\n\n /** Settings for persisting project tree mirrors to disk, so reopening a project transfers\n * what changed rather than the tree again. */\n readonly treeSnapshotOps: TreeSnapshotOps;\n};\n\nexport type MiddleLayerOps = MiddleLayerOpsSettings & MiddleLayerOpsPaths;\n\n/** Some defaults fot MiddleLayerOps. */\nexport const DefaultMiddleLayerOpsSettings: Pick<\n MiddleLayerOps,\n | keyof typeof DefaultDriverKitOpsSettings\n | \"defaultTreeOptions\"\n | \"projectRefreshInterval\"\n | \"devBlockUpdateRecheckInterval\"\n | \"debugOps\"\n | \"envelopeTtlMs\"\n | \"treeSnapshotOps\"\n> = {\n ...DefaultDriverKitOpsSettings,\n defaultTreeOptions: {\n pollingInterval: 200,\n stopPollingDelay: 2500,\n initialTreeLoadingTimeout: 100 * 60 * 60 * 1000, // disable timeout for loading project tree (100 hours)\n },\n debugOps: {\n dumpInitialTreeState: false,\n },\n devBlockUpdateRecheckInterval: 1000,\n projectRefreshInterval: 2000,\n envelopeTtlMs: 14 * 24 * 3600 * 1000, // 14 days\n treeSnapshotOps: {\n enabled: true,\n writeInterval: 5 * 60 * 1000, // 5 minutes\n maxSizeBytes: 256 * 1024 * 1024, // 256 MB, roughly 25 heavy projects\n },\n};\n\nexport function DefaultMiddleLayerOpsPaths(\n workDir: string,\n): Pick<\n MiddleLayerOpsPaths,\n keyof ReturnType<typeof DefaultDriverKitOpsPaths> | \"frontendDownloadPath\" | \"treeSnapshotPath\"\n> {\n return {\n ...DefaultDriverKitOpsPaths(workDir),\n frontendDownloadPath: path.join(workDir, \"frontend\"),\n treeSnapshotPath: path.join(workDir, \"treeSnapshots\"),\n };\n}\n\nexport type MiddleLayerOpsConstructor = Omit<\n MiddleLayerOpsSettings,\n keyof typeof DefaultMiddleLayerOpsSettings\n> &\n Partial<typeof DefaultMiddleLayerOpsSettings> &\n Omit<MiddleLayerOpsPaths, keyof Awaited<ReturnType<typeof DefaultMiddleLayerOpsPaths>>> &\n Partial<Awaited<ReturnType<typeof DefaultMiddleLayerOpsPaths>>>;\n"],"mappings":";;;;;;;AAqIA,MAAa,8BAUT;CACF,QAAQ,K,oCAAIA,EAAAA,CAAAA,qBAAqB;CACjC,eAAe;EACb,oBAAoB;EACpB,yBAAyB;EACzB,sBAAsB;CACxB;CACA,2BAA2B;EACzB,oBAAoB;EACpB,YAAY;EACZ,sBAAsB;CACxB;CACA,4BAA4B;EAC1B,oBAAoB;EACpB,sBAAsB;CACxB;CACA,iBAAiB;EACf,wBAAwB;EACxB,0BAA0B;EAC1B,iBAAiB;EACjB,kBAAkB;CACpB;CACA,oBAAoB;EAClB,oBAAoB;EACpB,iBAAiB;EACjB,kBAAkB;CACpB;CACA,iBAAiBC,eAAAA;CACjB,iBAAiB;EACf,cAAc;EACd,mBAAmB;EACnB,iBAAiB;CACnB;AACF;AAEA,SAAgB,yBACd,SAQA;CACA,OAAO;EACL,kBAAkBC,UAAAA,QAAK,KAAK,SAAS,UAAU;EAC/C,6BAA6BA,UAAAA,QAAK,KAAK,SAAS,qBAAqB;EACrE,uBAAuBA,UAAAA,QAAK,KAAK,SAAS,eAAe;EACzD,kBAAkBA,UAAAA,QAAK,KAAK,SAAS,SAAS;EAC9C,kBAAkBA,UAAAA,QAAK,KAAK,SAAS,cAAc;CACrD;AACF;;AAwFA,MAAa,gCAST;CACF,GAAG;CACH,oBAAoB;EAClB,iBAAiB;EACjB,kBAAkB;EAClB,2BAA2B;CAC7B;CACA,UAAU,EACR,sBAAsB,MACxB;CACA,+BAA+B;CAC/B,wBAAwB;CACxB,eAAe;CACf,iBAAiB;EACf,SAAS;EACT,eAAe;EACf,cAAc;CAChB;AACF;AAEA,SAAgB,2BACd,SAIA;CACA,OAAO;EACL,GAAG,yBAAyB,OAAO;EACnC,sBAAsBA,UAAAA,QAAK,KAAK,SAAS,UAAU;EACnD,kBAAkBA,UAAAA,QAAK,KAAK,SAAS,eAAe;CACtD;AACF"}
|
|
@@ -2,7 +2,7 @@ import { TemporalSynchronizedTreeOps } from "./types.js";
|
|
|
2
2
|
import { PFrameDriverOps, ParquetCacheOps } from "../pool/driver.js";
|
|
3
3
|
import "../pool/index.js";
|
|
4
4
|
import { MiLogger } from "@milaboratories/ts-helpers";
|
|
5
|
-
import { DownloadBlobToURLDriverOps, DownloadDriverOps, DownloadUrlDriverOps,
|
|
5
|
+
import { DownloadBlobToURLDriverOps, DownloadDriverOps, DownloadUrlDriverOps, LogsStreamDriverOps, OpenFileDialogCallback, UploadDriverOps, VirtualLocalStorageSpec } from "@milaboratories/pl-drivers";
|
|
6
6
|
/** Paths part of {@link DriverKitOps}. */
|
|
7
7
|
export type DriverKitOpsPaths = {
|
|
8
8
|
/** Common root where to put downloaded blobs / downloaded blob cache */
|
|
@@ -11,19 +11,6 @@ export type DriverKitOpsPaths = {
|
|
|
11
11
|
readonly blobDownloadRangesCachePath: string;
|
|
12
12
|
/** Common root where to put downloaded blobs with */
|
|
13
13
|
readonly downloadBlobToURLPath: string;
|
|
14
|
-
/**
|
|
15
|
-
* List of pl storages that have projections in local file system.
|
|
16
|
-
*
|
|
17
|
-
* This option affect two drivers:
|
|
18
|
-
*
|
|
19
|
-
* (1) LS driver generates "index" handles instead of "upload" for paths inside those locations
|
|
20
|
-
*
|
|
21
|
-
* (2) Download driver directly serves content retrieval requests for blobs from listed storages,
|
|
22
|
-
* and don't apply any caching for such blobs (i.e. preventing duplication of files for Downloaded
|
|
23
|
-
* type handles, making OnDemand and Downloaded handles equivalent)
|
|
24
|
-
*
|
|
25
|
-
* */
|
|
26
|
-
readonly localProjections: LocalStorageProjection[];
|
|
27
14
|
/**
|
|
28
15
|
* List of virtual storages that will allow homogeneous access to local FSs through LS API.
|
|
29
16
|
* If undefined, default list will be created.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ops.d.ts","names":[],"sources":["../../src/middle_layer/ops.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"ops.d.ts","names":[],"sources":["../../src/middle_layer/ops.ts"],"mappings":";;;;;;YAgBY;;WAED;;WAGA;;WAGA;;;;;WAMA,+BAA+B;;WAG/B;;;;;;WAOA;;;YAIC;WAKD,QAAQ;;;;;;;WAYR;;;;;WAUA,eAAe;;WAOf,2BAA2B;WAM3B,4BAA4B;;;;;WAU5B,iBAAiB;;WAQjB,oBAAoB;;;;;;WAWpB,wBAAwB;;WAOxB,iBAAiB;;;;;;WAOjB,iBAAiB;;YAGhB,eAAe,oBAAoB;;qBAGlC,6BAA6B,KACxC;wBA4Cc,yBACd,kBACC,KACD;;YAiBU,0BAA0B,KACpC,mCACa,+BAEb,eAAe,+BACf,KAAK,yBAAyB,kBAAkB,6BAChD,QAAQ,kBAAkB;YAEhB,sBAAsB;;WAEvB;;;;;;;WAQA;;;;YAKC;;;;;;;;WAQD;;;;;;;;WASA;;;WAIA;;;YAIC;;EAEV;;;YAIU,yBAAyB;;WAE1B,UAAU;;;WAIV,oBAAoB;;;WAIpB;;WAGA;;WAGA;;;;WAKA;;;WAIA,iBAAiB;;YAGhB,iBAAiB,yBAAyB;;qBAGzC,+BAA+B,KAC1C,6BACe;wBA2BD,2BACd,kBACC,KACD,2BACM,kBAAkB;YASd,4BAA4B,KACtC,qCACa,iCAEb,eAAe,iCACf,KAAK,2BAA2B,QAAQ,kBAAkB,gCAC1D,QAAQ,QAAQ,kBAAkB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ops.js","names":[],"sources":["../../src/middle_layer/ops.ts"],"sourcesContent":["import type { TemporalSynchronizedTreeOps } from \"./types\";\nimport type {\n DownloadBlobToURLDriverOps,\n DownloadDriverOps,\n DownloadUrlDriverOps,\n OpenFileDialogCallback,\n VirtualLocalStorageSpec,\n} from \"@milaboratories/pl-drivers\";\nimport type { UploadDriverOps } from \"@milaboratories/pl-drivers\";\nimport type { LogsStreamDriverOps } from \"@milaboratories/pl-drivers\";\nimport type { MiLogger } from \"@milaboratories/ts-helpers\";\nimport { ConsoleLoggerAdapter } from \"@milaboratories/ts-helpers\";\nimport type { LocalStorageProjection } from \"@milaboratories/pl-drivers\";\nimport path from \"node:path\";\nimport { PFrameDriverOpsDefaults, type PFrameDriverOps, type ParquetCacheOps } from \"../pool\";\n\n/** Paths part of {@link DriverKitOps}. */\nexport type DriverKitOpsPaths = {\n /** Common root where to put downloaded blobs / downloaded blob cache */\n readonly blobDownloadPath: string;\n\n /** Common root for a cache for range queries. */\n readonly blobDownloadRangesCachePath: string;\n\n /** Common root where to put downloaded blobs with */\n readonly downloadBlobToURLPath: string;\n\n /**\n * List of pl storages that have projections in local file system.\n *\n * This option affect two drivers:\n *\n * (1) LS driver generates \"index\" handles instead of \"upload\" for paths inside those locations\n *\n * (2) Download driver directly serves content retrieval requests for blobs from listed storages,\n * and don't apply any caching for such blobs (i.e. preventing duplication of files for Downloaded\n * type handles, making OnDemand and Downloaded handles equivalent)\n *\n * */\n readonly localProjections: LocalStorageProjection[];\n\n /**\n * List of virtual storages that will allow homogeneous access to local FSs through LS API.\n * If undefined, default list will be created.\n * */\n readonly virtualLocalStoragesOverride?: VirtualLocalStorageSpec[];\n\n /** Path to the directory where pframes will spill temporary files and store materialized views */\n readonly pframesSpillPath: string;\n\n /**\n * Path to the directory backing the persistent parquet blob cache. Unlike\n * {@link pframesSpillPath} this directory is NOT emptied on startup - the cache\n * (and its lifetime counters) is meant to survive restarts.\n */\n readonly parquetCachePath: string;\n};\n\n/** Options required to initialize full set of middle layer driver kit */\nexport type DriverKitOpsSettings = {\n //\n // Common\n //\n\n readonly logger: MiLogger;\n\n //\n // Signer\n //\n\n /**\n * Local secret, that is used to sign and verify different pieces of information\n * that can be used to access local data, like local paths for ongoing uploads.\n *\n * Use {@link MiddleLayer.generateLocalSecret} to generate sufficiently random string.\n * */\n readonly localSecret: string;\n\n //\n // Blob Driver\n //\n\n /**\n * Settings related to the download driver making operations with blobs. This driver is also used\n * to download logs when source process terminates and log terns into a blob\n */\n readonly blobDriverOps: DownloadDriverOps;\n\n //\n // Frontend Driver\n //\n\n /** Settings related to the frontend driver that downloads frontends. */\n readonly frontendDownloadDriverOps: DownloadUrlDriverOps;\n\n //\n // Blob To URL Driver\n //\n\n readonly downloadBlobToURLDriverOps: DownloadBlobToURLDriverOps;\n\n //\n // Upload Driver\n //\n\n /**\n * Settings related to the upload driver that actually performs upload and helps render upload\n * and indexing progresses from related pl resources.\n * */\n readonly uploadDriverOps: UploadDriverOps;\n\n //\n // Log streaming ops\n // (static logs are served via the blob driver)\n //\n\n /** Settings related to the streaming log driver */\n readonly logStreamDriverOps: LogsStreamDriverOps;\n\n //\n // LS Driver\n //\n\n /**\n * Callback to access system file open dialog, must be provided by the environment,\n * to allow for {@link showOpenSingleFileDialog} / {@link showOpenMultipleFilesDialog}\n * calls from the UI.\n */\n readonly openFileDialogCallback: OpenFileDialogCallback;\n\n //\n // PFrame Driver\n //\n\n /** Settings related to the PFrame driver */\n readonly pFrameDriverOps: PFrameDriverOps;\n\n /**\n * Tuning for the persistent parquet blob cache. Its directory is\n * {@link DriverKitOpsPaths.parquetCachePath}; this carries only the\n * size/eviction knobs.\n */\n readonly parquetCacheOps: ParquetCacheOps;\n};\n\nexport type DriverKitOps = DriverKitOpsPaths & DriverKitOpsSettings;\n\n/** Some defaults fot MiddleLayerOps. */\nexport const DefaultDriverKitOpsSettings: Pick<\n DriverKitOpsSettings,\n | \"logger\"\n | \"blobDriverOps\"\n | \"frontendDownloadDriverOps\"\n | \"downloadBlobToURLDriverOps\"\n | \"uploadDriverOps\"\n | \"logStreamDriverOps\"\n | \"pFrameDriverOps\"\n | \"parquetCacheOps\"\n> = {\n logger: new ConsoleLoggerAdapter(),\n blobDriverOps: {\n cacheSoftSizeBytes: 8 * 1024 * 1024 * 1024, // 8 GB\n rangesCacheMaxSizeBytes: 8 * 1024 * 1024 * 1024, // 8 GB\n nConcurrentDownloads: 10,\n },\n frontendDownloadDriverOps: {\n cacheSoftSizeBytes: 1 * 1024 * 1024 * 1024, // 1 GB\n withGunzip: true,\n nConcurrentDownloads: 50,\n },\n downloadBlobToURLDriverOps: {\n cacheSoftSizeBytes: 1 * 1024 * 1024 * 1024, // 1 GB\n nConcurrentDownloads: 10,\n },\n uploadDriverOps: {\n nConcurrentPartUploads: 10,\n nConcurrentGetProgresses: 10,\n pollingInterval: 1000,\n stopPollingDelay: 1000,\n },\n logStreamDriverOps: {\n nConcurrentGetLogs: 10,\n pollingInterval: 1000,\n stopPollingDelay: 1000,\n },\n pFrameDriverOps: PFrameDriverOpsDefaults,\n parquetCacheOps: {\n maxSizeBytes: 8 * 1024 * 1024 * 1024, // 8 GB\n admissionFraction: 0.2, // a single file may occupy at most 20% of the budget\n maxFilesTracked: 50_000, // ghost (previously-evicted) files remembered to guide readmission\n },\n};\n\nexport function DefaultDriverKitOpsPaths(\n workDir: string,\n): Pick<\n DriverKitOpsPaths,\n | \"blobDownloadPath\"\n | \"blobDownloadRangesCachePath\"\n | \"downloadBlobToURLPath\"\n | \"pframesSpillPath\"\n | \"parquetCachePath\"\n> {\n return {\n blobDownloadPath: path.join(workDir, \"download\"),\n blobDownloadRangesCachePath: path.join(workDir, \"downloadRangesCache\"),\n downloadBlobToURLPath: path.join(workDir, \"downloadToURL\"),\n pframesSpillPath: path.join(workDir, \"pframes\"),\n parquetCachePath: path.join(workDir, \"parquetCache\"),\n };\n}\n\n/** Fields with default values are marked as optional here. */\nexport type DriverKitOpsConstructor = Omit<\n DriverKitOpsSettings,\n keyof typeof DefaultDriverKitOpsSettings\n> &\n Partial<typeof DefaultDriverKitOpsSettings> &\n Omit<DriverKitOpsPaths, keyof ReturnType<typeof DefaultDriverKitOpsPaths>> &\n Partial<ReturnType<typeof DefaultDriverKitOpsPaths>>;\n\nexport type MiddleLayerOpsPaths = DriverKitOpsPaths & {\n /** Common root where to put frontend code. */\n readonly frontendDownloadPath: string;\n\n /**\n * Directory holding persisted project tree mirrors, one file per project. Like\n * {@link DriverKitOpsPaths.parquetCachePath} and unlike the spill directories, it is NOT\n * emptied on startup: surviving a restart is the entire point. It is pruned instead, see\n * {@link TreeSnapshotOps.maxSizeBytes}.\n */\n readonly treeSnapshotPath: string;\n};\n\n/** Tuning for the persisted project tree mirrors. Their directory is\n * {@link MiddleLayerOpsPaths.treeSnapshotPath}; this carries the behaviour knobs. */\nexport type TreeSnapshotOps = {\n /**\n * Whether project tree mirrors are persisted and restored at all.\n *\n * On by default. This is an operational kill switch, for a deployment where the cache\n * directory turns out to be unwritable or otherwise troublesome, not a rollout gate: the\n * floor of the feature is current behaviour, since a cache that never hits is a cold open.\n */\n readonly enabled: boolean;\n\n /**\n * Minimum wall-clock gap between periodic writes for one project.\n *\n * Can be generous, because a stale snapshot is less complete rather than wrong: final\n * resources never change and are never refetched, so this only bounds how much recent work\n * comes back from the non-final frontier on restore.\n */\n readonly writeInterval: number;\n\n /** Total bytes the snapshot directory may occupy after startup eviction. Needed because a\n * heavy project runs to roughly ten megabytes. */\n readonly maxSizeBytes: number;\n};\n\n/** Debug options for middle layer. */\nexport type MiddleLayerDebugOptions = {\n /** If true, will dump initial tree state to the file with root resource id as name. */\n dumpInitialTreeState: boolean;\n};\n\n/** Configuration controlling different aspects of middle layer behaviour. */\nexport type MiddleLayerOpsSettings = DriverKitOpsSettings & {\n /** Debug options. */\n readonly debugOps: MiddleLayerDebugOptions;\n\n /** Contain temporal options controlling how often should pl trees be\n * synchronized with the pl server. */\n readonly defaultTreeOptions: TemporalSynchronizedTreeOps;\n\n /** Defines interval in milliseconds for running periodic project maintenance job.\n * Project maintenance includes background staging rendering and cached outputs cleanup. */\n readonly projectRefreshInterval: number;\n\n /** How often to check for dev block updates */\n readonly devBlockUpdateRecheckInterval: number;\n\n /** Prioritize this channel if update is available in this block */\n readonly preferredUpdateChannel?: string;\n\n /** Default lifetime applied to a targeted shared envelope at creation, as\n * `sharedAt + envelopeTtlMs`. Share-with-everybody envelopes never expire\n * (`expiresAt: null`) and ignore this. */\n readonly envelopeTtlMs: number;\n\n /** Settings for persisting project tree mirrors to disk, so reopening a project transfers\n * what changed rather than the tree again. */\n readonly treeSnapshotOps: TreeSnapshotOps;\n};\n\nexport type MiddleLayerOps = MiddleLayerOpsSettings & MiddleLayerOpsPaths;\n\n/** Some defaults fot MiddleLayerOps. */\nexport const DefaultMiddleLayerOpsSettings: Pick<\n MiddleLayerOps,\n | keyof typeof DefaultDriverKitOpsSettings\n | \"defaultTreeOptions\"\n | \"projectRefreshInterval\"\n | \"devBlockUpdateRecheckInterval\"\n | \"debugOps\"\n | \"envelopeTtlMs\"\n | \"treeSnapshotOps\"\n> = {\n ...DefaultDriverKitOpsSettings,\n defaultTreeOptions: {\n pollingInterval: 200,\n stopPollingDelay: 2500,\n initialTreeLoadingTimeout: 100 * 60 * 60 * 1000, // disable timeout for loading project tree (100 hours)\n },\n debugOps: {\n dumpInitialTreeState: false,\n },\n devBlockUpdateRecheckInterval: 1000,\n projectRefreshInterval: 2000,\n envelopeTtlMs: 14 * 24 * 3600 * 1000, // 14 days\n treeSnapshotOps: {\n enabled: true,\n writeInterval: 5 * 60 * 1000, // 5 minutes\n maxSizeBytes: 256 * 1024 * 1024, // 256 MB, roughly 25 heavy projects\n },\n};\n\nexport function DefaultMiddleLayerOpsPaths(\n workDir: string,\n): Pick<\n MiddleLayerOpsPaths,\n keyof ReturnType<typeof DefaultDriverKitOpsPaths> | \"frontendDownloadPath\" | \"treeSnapshotPath\"\n> {\n return {\n ...DefaultDriverKitOpsPaths(workDir),\n frontendDownloadPath: path.join(workDir, \"frontend\"),\n treeSnapshotPath: path.join(workDir, \"treeSnapshots\"),\n };\n}\n\nexport type MiddleLayerOpsConstructor = Omit<\n MiddleLayerOpsSettings,\n keyof typeof DefaultMiddleLayerOpsSettings\n> &\n Partial<typeof DefaultMiddleLayerOpsSettings> &\n Omit<MiddleLayerOpsPaths, keyof Awaited<ReturnType<typeof DefaultMiddleLayerOpsPaths>>> &\n Partial<Awaited<ReturnType<typeof DefaultMiddleLayerOpsPaths>>>;\n"],"mappings":";;;;;;AAoJA,MAAa,8BAUT;CACF,QAAQ,IAAI,qBAAqB;CACjC,eAAe;EACb,oBAAoB;EACpB,yBAAyB;EACzB,sBAAsB;CACxB;CACA,2BAA2B;EACzB,oBAAoB;EACpB,YAAY;EACZ,sBAAsB;CACxB;CACA,4BAA4B;EAC1B,oBAAoB;EACpB,sBAAsB;CACxB;CACA,iBAAiB;EACf,wBAAwB;EACxB,0BAA0B;EAC1B,iBAAiB;EACjB,kBAAkB;CACpB;CACA,oBAAoB;EAClB,oBAAoB;EACpB,iBAAiB;EACjB,kBAAkB;CACpB;CACA,iBAAiB;CACjB,iBAAiB;EACf,cAAc;EACd,mBAAmB;EACnB,iBAAiB;CACnB;AACF;AAEA,SAAgB,yBACd,SAQA;CACA,OAAO;EACL,kBAAkB,KAAK,KAAK,SAAS,UAAU;EAC/C,6BAA6B,KAAK,KAAK,SAAS,qBAAqB;EACrE,uBAAuB,KAAK,KAAK,SAAS,eAAe;EACzD,kBAAkB,KAAK,KAAK,SAAS,SAAS;EAC9C,kBAAkB,KAAK,KAAK,SAAS,cAAc;CACrD;AACF;;AAwFA,MAAa,gCAST;CACF,GAAG;CACH,oBAAoB;EAClB,iBAAiB;EACjB,kBAAkB;EAClB,2BAA2B;CAC7B;CACA,UAAU,EACR,sBAAsB,MACxB;CACA,+BAA+B;CAC/B,wBAAwB;CACxB,eAAe;CACf,iBAAiB;EACf,SAAS;EACT,eAAe;EACf,cAAc;CAChB;AACF;AAEA,SAAgB,2BACd,SAIA;CACA,OAAO;EACL,GAAG,yBAAyB,OAAO;EACnC,sBAAsB,KAAK,KAAK,SAAS,UAAU;EACnD,kBAAkB,KAAK,KAAK,SAAS,eAAe;CACtD;AACF"}
|
|
1
|
+
{"version":3,"file":"ops.js","names":[],"sources":["../../src/middle_layer/ops.ts"],"sourcesContent":["import type { TemporalSynchronizedTreeOps } from \"./types\";\nimport type {\n DownloadBlobToURLDriverOps,\n DownloadDriverOps,\n DownloadUrlDriverOps,\n OpenFileDialogCallback,\n VirtualLocalStorageSpec,\n} from \"@milaboratories/pl-drivers\";\nimport type { UploadDriverOps } from \"@milaboratories/pl-drivers\";\nimport type { LogsStreamDriverOps } from \"@milaboratories/pl-drivers\";\nimport type { MiLogger } from \"@milaboratories/ts-helpers\";\nimport { ConsoleLoggerAdapter } from \"@milaboratories/ts-helpers\";\nimport path from \"node:path\";\nimport { PFrameDriverOpsDefaults, type PFrameDriverOps, type ParquetCacheOps } from \"../pool\";\n\n/** Paths part of {@link DriverKitOps}. */\nexport type DriverKitOpsPaths = {\n /** Common root where to put downloaded blobs / downloaded blob cache */\n readonly blobDownloadPath: string;\n\n /** Common root for a cache for range queries. */\n readonly blobDownloadRangesCachePath: string;\n\n /** Common root where to put downloaded blobs with */\n readonly downloadBlobToURLPath: string;\n\n /**\n * List of virtual storages that will allow homogeneous access to local FSs through LS API.\n * If undefined, default list will be created.\n * */\n readonly virtualLocalStoragesOverride?: VirtualLocalStorageSpec[];\n\n /** Path to the directory where pframes will spill temporary files and store materialized views */\n readonly pframesSpillPath: string;\n\n /**\n * Path to the directory backing the persistent parquet blob cache. Unlike\n * {@link pframesSpillPath} this directory is NOT emptied on startup - the cache\n * (and its lifetime counters) is meant to survive restarts.\n */\n readonly parquetCachePath: string;\n};\n\n/** Options required to initialize full set of middle layer driver kit */\nexport type DriverKitOpsSettings = {\n //\n // Common\n //\n\n readonly logger: MiLogger;\n\n //\n // Signer\n //\n\n /**\n * Local secret, that is used to sign and verify different pieces of information\n * that can be used to access local data, like local paths for ongoing uploads.\n *\n * Use {@link MiddleLayer.generateLocalSecret} to generate sufficiently random string.\n * */\n readonly localSecret: string;\n\n //\n // Blob Driver\n //\n\n /**\n * Settings related to the download driver making operations with blobs. This driver is also used\n * to download logs when source process terminates and log terns into a blob\n */\n readonly blobDriverOps: DownloadDriverOps;\n\n //\n // Frontend Driver\n //\n\n /** Settings related to the frontend driver that downloads frontends. */\n readonly frontendDownloadDriverOps: DownloadUrlDriverOps;\n\n //\n // Blob To URL Driver\n //\n\n readonly downloadBlobToURLDriverOps: DownloadBlobToURLDriverOps;\n\n //\n // Upload Driver\n //\n\n /**\n * Settings related to the upload driver that actually performs upload and helps render upload\n * and indexing progresses from related pl resources.\n * */\n readonly uploadDriverOps: UploadDriverOps;\n\n //\n // Log streaming ops\n // (static logs are served via the blob driver)\n //\n\n /** Settings related to the streaming log driver */\n readonly logStreamDriverOps: LogsStreamDriverOps;\n\n //\n // LS Driver\n //\n\n /**\n * Callback to access system file open dialog, must be provided by the environment,\n * to allow for {@link showOpenSingleFileDialog} / {@link showOpenMultipleFilesDialog}\n * calls from the UI.\n */\n readonly openFileDialogCallback: OpenFileDialogCallback;\n\n //\n // PFrame Driver\n //\n\n /** Settings related to the PFrame driver */\n readonly pFrameDriverOps: PFrameDriverOps;\n\n /**\n * Tuning for the persistent parquet blob cache. Its directory is\n * {@link DriverKitOpsPaths.parquetCachePath}; this carries only the\n * size/eviction knobs.\n */\n readonly parquetCacheOps: ParquetCacheOps;\n};\n\nexport type DriverKitOps = DriverKitOpsPaths & DriverKitOpsSettings;\n\n/** Some defaults fot MiddleLayerOps. */\nexport const DefaultDriverKitOpsSettings: Pick<\n DriverKitOpsSettings,\n | \"logger\"\n | \"blobDriverOps\"\n | \"frontendDownloadDriverOps\"\n | \"downloadBlobToURLDriverOps\"\n | \"uploadDriverOps\"\n | \"logStreamDriverOps\"\n | \"pFrameDriverOps\"\n | \"parquetCacheOps\"\n> = {\n logger: new ConsoleLoggerAdapter(),\n blobDriverOps: {\n cacheSoftSizeBytes: 8 * 1024 * 1024 * 1024, // 8 GB\n rangesCacheMaxSizeBytes: 8 * 1024 * 1024 * 1024, // 8 GB\n nConcurrentDownloads: 10,\n },\n frontendDownloadDriverOps: {\n cacheSoftSizeBytes: 1 * 1024 * 1024 * 1024, // 1 GB\n withGunzip: true,\n nConcurrentDownloads: 50,\n },\n downloadBlobToURLDriverOps: {\n cacheSoftSizeBytes: 1 * 1024 * 1024 * 1024, // 1 GB\n nConcurrentDownloads: 10,\n },\n uploadDriverOps: {\n nConcurrentPartUploads: 10,\n nConcurrentGetProgresses: 10,\n pollingInterval: 1000,\n stopPollingDelay: 1000,\n },\n logStreamDriverOps: {\n nConcurrentGetLogs: 10,\n pollingInterval: 1000,\n stopPollingDelay: 1000,\n },\n pFrameDriverOps: PFrameDriverOpsDefaults,\n parquetCacheOps: {\n maxSizeBytes: 8 * 1024 * 1024 * 1024, // 8 GB\n admissionFraction: 0.2, // a single file may occupy at most 20% of the budget\n maxFilesTracked: 50_000, // ghost (previously-evicted) files remembered to guide readmission\n },\n};\n\nexport function DefaultDriverKitOpsPaths(\n workDir: string,\n): Pick<\n DriverKitOpsPaths,\n | \"blobDownloadPath\"\n | \"blobDownloadRangesCachePath\"\n | \"downloadBlobToURLPath\"\n | \"pframesSpillPath\"\n | \"parquetCachePath\"\n> {\n return {\n blobDownloadPath: path.join(workDir, \"download\"),\n blobDownloadRangesCachePath: path.join(workDir, \"downloadRangesCache\"),\n downloadBlobToURLPath: path.join(workDir, \"downloadToURL\"),\n pframesSpillPath: path.join(workDir, \"pframes\"),\n parquetCachePath: path.join(workDir, \"parquetCache\"),\n };\n}\n\n/** Fields with default values are marked as optional here. */\nexport type DriverKitOpsConstructor = Omit<\n DriverKitOpsSettings,\n keyof typeof DefaultDriverKitOpsSettings\n> &\n Partial<typeof DefaultDriverKitOpsSettings> &\n Omit<DriverKitOpsPaths, keyof ReturnType<typeof DefaultDriverKitOpsPaths>> &\n Partial<ReturnType<typeof DefaultDriverKitOpsPaths>>;\n\nexport type MiddleLayerOpsPaths = DriverKitOpsPaths & {\n /** Common root where to put frontend code. */\n readonly frontendDownloadPath: string;\n\n /**\n * Directory holding persisted project tree mirrors, one file per project. Like\n * {@link DriverKitOpsPaths.parquetCachePath} and unlike the spill directories, it is NOT\n * emptied on startup: surviving a restart is the entire point. It is pruned instead, see\n * {@link TreeSnapshotOps.maxSizeBytes}.\n */\n readonly treeSnapshotPath: string;\n};\n\n/** Tuning for the persisted project tree mirrors. Their directory is\n * {@link MiddleLayerOpsPaths.treeSnapshotPath}; this carries the behaviour knobs. */\nexport type TreeSnapshotOps = {\n /**\n * Whether project tree mirrors are persisted and restored at all.\n *\n * On by default. This is an operational kill switch, for a deployment where the cache\n * directory turns out to be unwritable or otherwise troublesome, not a rollout gate: the\n * floor of the feature is current behaviour, since a cache that never hits is a cold open.\n */\n readonly enabled: boolean;\n\n /**\n * Minimum wall-clock gap between periodic writes for one project.\n *\n * Can be generous, because a stale snapshot is less complete rather than wrong: final\n * resources never change and are never refetched, so this only bounds how much recent work\n * comes back from the non-final frontier on restore.\n */\n readonly writeInterval: number;\n\n /** Total bytes the snapshot directory may occupy after startup eviction. Needed because a\n * heavy project runs to roughly ten megabytes. */\n readonly maxSizeBytes: number;\n};\n\n/** Debug options for middle layer. */\nexport type MiddleLayerDebugOptions = {\n /** If true, will dump initial tree state to the file with root resource id as name. */\n dumpInitialTreeState: boolean;\n};\n\n/** Configuration controlling different aspects of middle layer behaviour. */\nexport type MiddleLayerOpsSettings = DriverKitOpsSettings & {\n /** Debug options. */\n readonly debugOps: MiddleLayerDebugOptions;\n\n /** Contain temporal options controlling how often should pl trees be\n * synchronized with the pl server. */\n readonly defaultTreeOptions: TemporalSynchronizedTreeOps;\n\n /** Defines interval in milliseconds for running periodic project maintenance job.\n * Project maintenance includes background staging rendering and cached outputs cleanup. */\n readonly projectRefreshInterval: number;\n\n /** How often to check for dev block updates */\n readonly devBlockUpdateRecheckInterval: number;\n\n /** Prioritize this channel if update is available in this block */\n readonly preferredUpdateChannel?: string;\n\n /** Default lifetime applied to a targeted shared envelope at creation, as\n * `sharedAt + envelopeTtlMs`. Share-with-everybody envelopes never expire\n * (`expiresAt: null`) and ignore this. */\n readonly envelopeTtlMs: number;\n\n /** Settings for persisting project tree mirrors to disk, so reopening a project transfers\n * what changed rather than the tree again. */\n readonly treeSnapshotOps: TreeSnapshotOps;\n};\n\nexport type MiddleLayerOps = MiddleLayerOpsSettings & MiddleLayerOpsPaths;\n\n/** Some defaults fot MiddleLayerOps. */\nexport const DefaultMiddleLayerOpsSettings: Pick<\n MiddleLayerOps,\n | keyof typeof DefaultDriverKitOpsSettings\n | \"defaultTreeOptions\"\n | \"projectRefreshInterval\"\n | \"devBlockUpdateRecheckInterval\"\n | \"debugOps\"\n | \"envelopeTtlMs\"\n | \"treeSnapshotOps\"\n> = {\n ...DefaultDriverKitOpsSettings,\n defaultTreeOptions: {\n pollingInterval: 200,\n stopPollingDelay: 2500,\n initialTreeLoadingTimeout: 100 * 60 * 60 * 1000, // disable timeout for loading project tree (100 hours)\n },\n debugOps: {\n dumpInitialTreeState: false,\n },\n devBlockUpdateRecheckInterval: 1000,\n projectRefreshInterval: 2000,\n envelopeTtlMs: 14 * 24 * 3600 * 1000, // 14 days\n treeSnapshotOps: {\n enabled: true,\n writeInterval: 5 * 60 * 1000, // 5 minutes\n maxSizeBytes: 256 * 1024 * 1024, // 256 MB, roughly 25 heavy projects\n },\n};\n\nexport function DefaultMiddleLayerOpsPaths(\n workDir: string,\n): Pick<\n MiddleLayerOpsPaths,\n keyof ReturnType<typeof DefaultDriverKitOpsPaths> | \"frontendDownloadPath\" | \"treeSnapshotPath\"\n> {\n return {\n ...DefaultDriverKitOpsPaths(workDir),\n frontendDownloadPath: path.join(workDir, \"frontend\"),\n treeSnapshotPath: path.join(workDir, \"treeSnapshots\"),\n };\n}\n\nexport type MiddleLayerOpsConstructor = Omit<\n MiddleLayerOpsSettings,\n keyof typeof DefaultMiddleLayerOpsSettings\n> &\n Partial<typeof DefaultMiddleLayerOpsSettings> &\n Omit<MiddleLayerOpsPaths, keyof Awaited<ReturnType<typeof DefaultMiddleLayerOpsPaths>>> &\n Partial<Awaited<ReturnType<typeof DefaultMiddleLayerOpsPaths>>>;\n"],"mappings":";;;;;;AAqIA,MAAa,8BAUT;CACF,QAAQ,IAAI,qBAAqB;CACjC,eAAe;EACb,oBAAoB;EACpB,yBAAyB;EACzB,sBAAsB;CACxB;CACA,2BAA2B;EACzB,oBAAoB;EACpB,YAAY;EACZ,sBAAsB;CACxB;CACA,4BAA4B;EAC1B,oBAAoB;EACpB,sBAAsB;CACxB;CACA,iBAAiB;EACf,wBAAwB;EACxB,0BAA0B;EAC1B,iBAAiB;EACjB,kBAAkB;CACpB;CACA,oBAAoB;EAClB,oBAAoB;EACpB,iBAAiB;EACjB,kBAAkB;CACpB;CACA,iBAAiB;CACjB,iBAAiB;EACf,cAAc;EACd,mBAAmB;EACnB,iBAAiB;CACnB;AACF;AAEA,SAAgB,yBACd,SAQA;CACA,OAAO;EACL,kBAAkB,KAAK,KAAK,SAAS,UAAU;EAC/C,6BAA6B,KAAK,KAAK,SAAS,qBAAqB;EACrE,uBAAuB,KAAK,KAAK,SAAS,eAAe;EACzD,kBAAkB,KAAK,KAAK,SAAS,SAAS;EAC9C,kBAAkB,KAAK,KAAK,SAAS,cAAc;CACrD;AACF;;AAwFA,MAAa,gCAST;CACF,GAAG;CACH,oBAAoB;EAClB,iBAAiB;EACjB,kBAAkB;EAClB,2BAA2B;CAC7B;CACA,UAAU,EACR,sBAAsB,MACxB;CACA,+BAA+B;CAC/B,wBAAwB;CACxB,eAAe;CACf,iBAAiB;EACf,SAAS;EACT,eAAe;EACf,cAAc;CAChB;AACF;AAEA,SAAgB,2BACd,SAIA;CACA,OAAO;EACL,GAAG,yBAAyB,OAAO;EACnC,sBAAsB,KAAK,KAAK,SAAS,UAAU;EACnD,kBAAkB,KAAK,KAAK,SAAS,eAAe;CACtD;AACF"}
|
|
@@ -17,13 +17,13 @@ let _platforma_sdk_model = require("@platforma-sdk/model");
|
|
|
17
17
|
let _milaboratories_ts_helpers = require("@milaboratories/ts-helpers");
|
|
18
18
|
let node_fs_promises = require("node:fs/promises");
|
|
19
19
|
node_fs_promises = require_runtime.__toESM(node_fs_promises, 1);
|
|
20
|
+
let _milaboratories_computable = require("@milaboratories/computable");
|
|
21
|
+
let node_timers_promises = require("node:timers/promises");
|
|
20
22
|
let _milaboratories_pl_client = require("@milaboratories/pl-client");
|
|
21
23
|
let _milaboratories_pl_tree = require("@milaboratories/pl-tree");
|
|
22
|
-
let _milaboratories_computable = require("@milaboratories/computable");
|
|
23
24
|
let node_crypto = require("node:crypto");
|
|
24
25
|
let canonicalize = require("canonicalize");
|
|
25
26
|
canonicalize = require_runtime.__toESM(canonicalize, 1);
|
|
26
|
-
let node_timers_promises = require("node:timers/promises");
|
|
27
27
|
// src/middle_layer/project.ts
|
|
28
28
|
function stringifyForDump(object) {
|
|
29
29
|
return JSON.stringify(object, (key, value) => {
|
|
@@ -7,9 +7,9 @@ import { MiddleLayerEnvironment } from "./middle_layer.js";
|
|
|
7
7
|
import { AuthorMarker, BlockSettings, BlockStateInternalV3, ProjectOverview } from "@milaboratories/pl-model-middle-layer";
|
|
8
8
|
import { MiLogger } from "@milaboratories/ts-helpers";
|
|
9
9
|
import { NavigationState } from "@milaboratories/pl-model-common";
|
|
10
|
+
import { Computable, ComputableStableDefined } from "@milaboratories/computable";
|
|
10
11
|
import { PlClient, SignedResourceId } from "@milaboratories/pl-client";
|
|
11
12
|
import { ExtendedResourceData, SynchronizedTreeState } from "@milaboratories/pl-tree";
|
|
12
|
-
import { Computable, ComputableStableDefined } from "@milaboratories/computable";
|
|
13
13
|
/** Data access object, to manipulate and read single opened (!) project data. */
|
|
14
14
|
export declare class Project {
|
|
15
15
|
private readonly env;
|
|
@@ -15,12 +15,12 @@ import { cacheBlockPackTemplate } from "../mutator/template/template_cache.js";
|
|
|
15
15
|
import { BLOCK_STORAGE_FACADE_VERSION, checkBlockFlag, extractConfig } from "@platforma-sdk/model";
|
|
16
16
|
import { cachedDeserialize, createInfiniteRetryState, nextInfiniteRetryState, notEmpty } from "@milaboratories/ts-helpers";
|
|
17
17
|
import fsp from "node:fs/promises";
|
|
18
|
+
import { Computable } from "@milaboratories/computable";
|
|
19
|
+
import { setTimeout } from "node:timers/promises";
|
|
18
20
|
import { DefaultRetryOptions, Pl, TreeFinality, ensureSignedResourceIdNotNull, field, isNotFoundError, isPermissionDenied, isTimeoutOrCancelError, isUnauthenticated, parseSignedResourceId, resourceIdToString, treeFilter } from "@milaboratories/pl-client";
|
|
19
21
|
import { SynchronizedTreeState, TreeStateUpdateError, treeDumpStats } from "@milaboratories/pl-tree";
|
|
20
|
-
import { Computable } from "@milaboratories/computable";
|
|
21
22
|
import { randomUUID } from "node:crypto";
|
|
22
23
|
import canonicalize from "canonicalize";
|
|
23
|
-
import { setTimeout } from "node:timers/promises";
|
|
24
24
|
// src/middle_layer/project.ts
|
|
25
25
|
function stringifyForDump(object) {
|
|
26
26
|
return JSON.stringify(object, (key, value) => {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
const require_project_model = require("../model/project_model.cjs");
|
|
2
2
|
let _milaboratories_pl_model_common = require("@milaboratories/pl-model-common");
|
|
3
|
+
let _milaboratories_computable = require("@milaboratories/computable");
|
|
3
4
|
let _milaboratories_pl_client = require("@milaboratories/pl-client");
|
|
4
5
|
let _milaboratories_pl_tree = require("@milaboratories/pl-tree");
|
|
5
|
-
let _milaboratories_computable = require("@milaboratories/computable");
|
|
6
6
|
// src/middle_layer/project_list.ts
|
|
7
7
|
const ProjectsField = "projects";
|
|
8
8
|
const ProjectsResourceType = {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import "../model/project_model.js";
|
|
2
2
|
import "./types.js";
|
|
3
3
|
import "./middle_layer.js";
|
|
4
|
+
import { WatchableValue } from "@milaboratories/computable";
|
|
4
5
|
import { PlClient, PlTransaction, ResourceType, SignedResourceId } from "@milaboratories/pl-client";
|
|
5
6
|
import "@milaboratories/pl-tree";
|
|
6
|
-
import { WatchableValue } from "@milaboratories/computable";
|
|
7
7
|
export declare const ProjectsField = "projects";
|
|
8
8
|
export declare const ProjectsResourceType: ResourceType;
|
|
9
9
|
//# sourceMappingURL=project_list.d.ts.map
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ProjectCreatedTimestamp, ProjectLastModifiedTimestamp, ProjectMetaKey, ProjectResourceType } from "../model/project_model.js";
|
|
2
2
|
import { asProjectId } from "@milaboratories/pl-model-common";
|
|
3
|
+
import { Computable } from "@milaboratories/computable";
|
|
3
4
|
import { field, isNullSignedResourceId, resourceIdToString, resourceTypesEqual, treeFilter } from "@milaboratories/pl-client";
|
|
4
5
|
import { SynchronizedTreeState } from "@milaboratories/pl-tree";
|
|
5
|
-
import { Computable } from "@milaboratories/computable";
|
|
6
6
|
// src/middle_layer/project_list.ts
|
|
7
7
|
const ProjectsField = "projects";
|
|
8
8
|
const ProjectsResourceType = {
|
|
@@ -8,8 +8,8 @@ const require_render = require("./render.cjs");
|
|
|
8
8
|
const require_util$1 = require("./util.cjs");
|
|
9
9
|
let _platforma_sdk_model = require("@platforma-sdk/model");
|
|
10
10
|
let _milaboratories_ts_helpers = require("@milaboratories/ts-helpers");
|
|
11
|
-
let _milaboratories_pl_client = require("@milaboratories/pl-client");
|
|
12
11
|
let _milaboratories_computable = require("@milaboratories/computable");
|
|
12
|
+
let _milaboratories_pl_client = require("@milaboratories/pl-client");
|
|
13
13
|
let es_toolkit = require("es-toolkit");
|
|
14
14
|
// src/middle_layer/project_overview.ts
|
|
15
15
|
function argsEquals(a, b) {
|
|
@@ -8,8 +8,8 @@ import { computableFromCfgOrRF } from "./render.js";
|
|
|
8
8
|
import { getBlockPackInfo } from "./util.js";
|
|
9
9
|
import { BLOCK_STORAGE_FACADE_VERSION, extractCodeWithInfo, wrapCallback } from "@platforma-sdk/model";
|
|
10
10
|
import { notEmpty } from "@milaboratories/ts-helpers";
|
|
11
|
-
import { resourceIdToString } from "@milaboratories/pl-client";
|
|
12
11
|
import { Computable } from "@milaboratories/computable";
|
|
12
|
+
import { resourceIdToString } from "@milaboratories/pl-client";
|
|
13
13
|
import { isEqual, omitBy } from "es-toolkit";
|
|
14
14
|
// src/middle_layer/project_overview.ts
|
|
15
15
|
function argsEquals(a, b) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const require_sharing_model = require("../model/sharing_model.cjs");
|
|
2
|
+
let _milaboratories_computable = require("@milaboratories/computable");
|
|
2
3
|
let _milaboratories_pl_client = require("@milaboratories/pl-client");
|
|
3
4
|
let _milaboratories_pl_tree = require("@milaboratories/pl-tree");
|
|
4
|
-
let _milaboratories_computable = require("@milaboratories/computable");
|
|
5
5
|
// src/middle_layer/sharing_list.ts
|
|
6
6
|
/**
|
|
7
7
|
* Reactive view of the donor's own outbox. Reads each live envelope's immutable
|
|
@@ -2,9 +2,9 @@ import { EnvelopeMode, EnvelopePayloadKind, ShareId } from "../model/sharing_mod
|
|
|
2
2
|
import "./middle_layer.js";
|
|
3
3
|
import { FolderId } from "@milaboratories/pl-model-middle-layer";
|
|
4
4
|
import { ProjectId, TemplateId } from "@milaboratories/pl-model-common";
|
|
5
|
+
import { Computable } from "@milaboratories/computable";
|
|
5
6
|
import { PlClient, SignedResourceId } from "@milaboratories/pl-client";
|
|
6
7
|
import { SynchronizedTreeState } from "@milaboratories/pl-tree";
|
|
7
|
-
import { Computable } from "@milaboratories/computable";
|
|
8
8
|
/** What a folder share carries, as both share lists show it. */
|
|
9
9
|
export interface EnvelopeFolderSummary {
|
|
10
10
|
label: string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SharedEnvelopeResourceType, SharingOutboxResourceType, SharingStateResourceType, envelopeFolderRoot, envelopeProjectMap, hiddenFieldShareId, isHiddenField, normalizeEnvelopeData } from "../model/sharing_model.js";
|
|
2
|
+
import { Computable } from "@milaboratories/computable";
|
|
2
3
|
import { isEveryoneUserLogin, resourceType, resourceTypesEqual, treeFilter } from "@milaboratories/pl-client";
|
|
3
4
|
import { SynchronizedTreeState } from "@milaboratories/pl-tree";
|
|
4
|
-
import { Computable } from "@milaboratories/computable";
|
|
5
5
|
// src/middle_layer/sharing_list.ts
|
|
6
6
|
/**
|
|
7
7
|
* Reactive view of the donor's own outbox. Reads each live envelope's immutable
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
let _milaboratories_pl_model_middle_layer = require("@milaboratories/pl-model-middle-layer");
|
|
2
2
|
let _milaboratories_pl_model_common = require("@milaboratories/pl-model-common");
|
|
3
|
+
let _milaboratories_computable = require("@milaboratories/computable");
|
|
3
4
|
let _milaboratories_pl_client = require("@milaboratories/pl-client");
|
|
4
5
|
let _milaboratories_pl_tree = require("@milaboratories/pl-tree");
|
|
5
|
-
let _milaboratories_computable = require("@milaboratories/computable");
|
|
6
6
|
// src/middle_layer/template_list.ts
|
|
7
7
|
const TemplatesField = "templates";
|
|
8
8
|
const TemplatesResourceType = {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { normalizeDescription } from "@milaboratories/pl-model-middle-layer";
|
|
2
2
|
import { asTemplateId } from "@milaboratories/pl-model-common";
|
|
3
|
+
import { Computable } from "@milaboratories/computable";
|
|
3
4
|
import { resourceIdToString, resourceTypesEqual, treeFilter } from "@milaboratories/pl-client";
|
|
4
5
|
import { SynchronizedTreeState } from "@milaboratories/pl-tree";
|
|
5
|
-
import { Computable } from "@milaboratories/computable";
|
|
6
6
|
// src/middle_layer/template_list.ts
|
|
7
7
|
const TemplatesField = "templates";
|
|
8
8
|
const TemplatesResourceType = {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SynchronizedTreeOps, SynchronizedTreeState } from "@milaboratories/pl-tree";
|
|
2
1
|
import { Computable } from "@milaboratories/computable";
|
|
2
|
+
import { SynchronizedTreeOps, SynchronizedTreeState } from "@milaboratories/pl-tree";
|
|
3
3
|
export type TemporalSynchronizedTreeOps = Pick<SynchronizedTreeOps, "pollingInterval" | "stopPollingDelay" | "logStat" | "initialTreeLoadingTimeout" | "traversalMode">;
|
|
4
4
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -91,9 +91,9 @@ async function initNetworkCheck(plCredentials, plUser, plPassword, optsOverrides
|
|
|
91
91
|
const httpClient = uaClient.ll.httpDispatcher;
|
|
92
92
|
const logger = new _milaboratories_ts_helpers.ConsoleLoggerAdapter();
|
|
93
93
|
const signer = new _milaboratories_ts_helpers.HmacSha256Signer("localSecret");
|
|
94
|
-
const downloadClient = (0, _milaboratories_pl_drivers.createDownloadClient)(logger, client
|
|
94
|
+
const downloadClient = (0, _milaboratories_pl_drivers.createDownloadClient)(logger, client);
|
|
95
95
|
const uploadBlobClient = (0, _milaboratories_pl_drivers.createUploadBlobClient)(client, logger);
|
|
96
|
-
const lsDriver = await _milaboratories_pl_drivers.LsDriver.init(logger, client, signer,
|
|
96
|
+
const lsDriver = await _milaboratories_pl_drivers.LsDriver.init(logger, client, signer, () => Promise.resolve([]), []);
|
|
97
97
|
const terminate = async () => {
|
|
98
98
|
downloadClient.close();
|
|
99
99
|
uploadBlobClient.close();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"network_check.cjs","names":["channel","createTempFile","createBigTempFile","backendPings","blockRegistryOverviewPings","blockGARegistryOverviewPings","blockRegistryUiPings","blockGARegistryUiPings","autoUpdateCdnPings","uploadTemplate","uploadFile","downloadFile","softwareCheck","pythonSoftware","downloadFromEveryStorage","plAddressToConfig","randomUUID","UnauthenticatedPlClient","PlClient","ConsoleLoggerAdapter","HmacSha256Signer","createDownloadClient","createUploadBlobClient","LsDriver","reportToString"],"sources":["../../src/network_check/network_check.ts"],"sourcesContent":["/** A utility to check network problems and gather statistics.\n * It's useful when we cannot connect to the server of a company\n * because of security reasons,\n * but they can send us and their DevOps team this report.\n *\n * What we check:\n * - pings to backend\n * - block registry for block overview and ui.\n * - autoupdate CDN.\n * - upload workflow to backend (workflow part via our API).\n * - the desktop could do multipart upload.\n * - the desktop could download files from S3.\n * - backend could download software and run it.\n * - backend could run python software.\n * - try to get something from every storage to work storage.\n *\n * We don't check backend access to S3 storage, it is checked on the start of backend.\n */\n\nimport type { AuthInformation, PlClientConfig } from \"@milaboratories/pl-client\";\nimport { PlClient, UnauthenticatedPlClient, plAddressToConfig } from \"@milaboratories/pl-client\";\nimport type { MiLogger, Signer } from \"@milaboratories/ts-helpers\";\nimport { ConsoleLoggerAdapter, HmacSha256Signer } from \"@milaboratories/ts-helpers\";\nimport { channel } from \"node:diagnostics_channel\";\nimport type { ClientDownload, ClientUpload } from \"@milaboratories/pl-drivers\";\nimport { LsDriver, createDownloadClient, createUploadBlobClient } from \"@milaboratories/pl-drivers\";\nimport type { HttpNetworkReport, NetworkReport } from \"./pings\";\nimport {\n autoUpdateCdnPings,\n backendPings,\n blockGARegistryOverviewPings,\n blockGARegistryUiPings,\n blockRegistryOverviewPings,\n blockRegistryUiPings,\n reportToString,\n} from \"./pings\";\nimport type { Dispatcher } from \"undici\";\nimport type { TemplateReport } from \"./template\";\nimport {\n uploadTemplate,\n uploadFile,\n downloadFile,\n createTempFile,\n pythonSoftware,\n softwareCheck,\n createBigTempFile,\n downloadFromEveryStorage,\n} from \"./template\";\nimport { randomUUID } from \"node:crypto\";\n\n/** All reports we need to collect. */\ninterface NetworkReports {\n plPings: NetworkReport<string>[];\n\n blockRegistryOverviewChecks: HttpNetworkReport[];\n blockGARegistryOverviewChecks: HttpNetworkReport[];\n blockRegistryUiChecks: HttpNetworkReport[];\n blockGARegistryUiChecks: HttpNetworkReport[];\n\n autoUpdateCdnChecks: HttpNetworkReport[];\n\n uploadTemplateCheck: TemplateReport;\n uploadFileCheck: TemplateReport;\n downloadFileCheck: TemplateReport;\n softwareCheck: TemplateReport;\n pythonSoftwareCheck: TemplateReport;\n storageToDownloadReport: Record<string, TemplateReport>;\n}\n\nexport interface CheckNetworkOpts {\n /** Signal to abort all network checks. */\n signal?: AbortSignal;\n\n /** Platforma Backend pings options. */\n pingCheckDurationMs: number;\n pingTimeoutMs: number;\n maxPingsPerSecond: number;\n\n /** An options for CDN and block registry. */\n httpTimeoutMs: number;\n\n /** Block registry pings options. */\n blockRegistryDurationMs: number;\n maxRegistryChecksPerSecond: number;\n blockRegistryUrl: string;\n blockGARegistryUrl: string;\n blockOverviewPath: string;\n blockUiPath: string;\n\n /** CDN for auto-update pings options. */\n autoUpdateCdnDurationMs: number;\n maxAutoUpdateCdnChecksPerSecond: number;\n autoUpdateCdnUrl: string;\n\n /** Body limit for requests. */\n bodyLimit: number;\n\n /** Limit for the size of files to download from every storage. */\n everyStorageBytesLimit: number;\n /** Minimal size of files to create a directory from for every storage. */\n everyStorageMinFileSize: number;\n /** Maximal size of files to create a directory from for every storage. */\n everyStorageMaxFileSize: number;\n /** How many files to check from every storage. */\n everyStorageNFilesToCheck: number;\n /** Minimal number of ls requests for every storage. */\n everyStorageMinLsRequests: number;\n}\n\n/** Checks connectivity to Platforma Backend, to block registry\n * and to auto-update CDN,\n * and generates a string report. */\nexport async function checkNetwork(\n plCredentials: string,\n plUser: string | undefined,\n plPassword: string | undefined,\n optsOverrides: Partial<CheckNetworkOpts> = {},\n): Promise<string> {\n const undiciLogs: any[] = [];\n // Subscribe to all Undici diagnostic events\n undiciEvents.forEach((event) => {\n const diagnosticChannel = channel(event);\n diagnosticChannel.subscribe((message: any) => {\n const timestamp = new Date().toISOString();\n const data = { ...message };\n if (data?.response?.headers) {\n data.response = { ...data.response };\n data.response.headers = data.response.headers.slice();\n data.response.headers = data.response.headers.map((h: any) => h.toString());\n }\n\n // we try to upload big files, don't include the buffer in the report.\n if (data?.request?.body) {\n data.request = { ...data.request };\n data.request.body = `too big`;\n }\n\n undiciLogs.push(\n JSON.stringify({\n timestamp,\n event,\n data,\n }),\n );\n });\n });\n\n try {\n const {\n logger,\n plConfig,\n client,\n signer,\n downloadClient,\n uploadBlobClient,\n lsDriver,\n httpClient,\n ops,\n } = await initNetworkCheck(plCredentials, plUser, plPassword, optsOverrides);\n\n const { filePath: filePathToDownload, fileContent: fileContentToDownload } =\n await createTempFile();\n const { filePath: filePathToUpload } = await createBigTempFile();\n\n const report: NetworkReports = {\n plPings: await backendPings(ops, plConfig),\n blockRegistryOverviewChecks: await blockRegistryOverviewPings(ops, httpClient),\n blockGARegistryOverviewChecks: await blockGARegistryOverviewPings(ops, httpClient),\n blockRegistryUiChecks: await blockRegistryUiPings(ops, httpClient),\n blockGARegistryUiChecks: await blockGARegistryUiPings(ops, httpClient),\n\n autoUpdateCdnChecks: await autoUpdateCdnPings(ops, httpClient),\n\n uploadTemplateCheck: await uploadTemplate(logger, client, \"Jack\"),\n uploadFileCheck: await uploadFile(\n logger,\n signer,\n lsDriver,\n uploadBlobClient,\n client,\n filePathToUpload,\n ),\n downloadFileCheck: await downloadFile(\n logger,\n client,\n lsDriver,\n uploadBlobClient,\n downloadClient,\n filePathToDownload,\n fileContentToDownload,\n ),\n softwareCheck: await softwareCheck(client),\n pythonSoftwareCheck: await pythonSoftware(client, \"Jack\"),\n storageToDownloadReport: await downloadFromEveryStorage(logger, client, lsDriver, {\n minLsRequests: ops.everyStorageMinLsRequests,\n bytesLimit: ops.everyStorageBytesLimit,\n minFileSize: ops.everyStorageMinFileSize,\n maxFileSize: ops.everyStorageMaxFileSize,\n nFilesToCheck: ops.everyStorageNFilesToCheck,\n }),\n };\n\n return reportsToString(report, plCredentials, ops, undiciLogs);\n } catch (e) {\n return `Unhandled error while checking the network: ${e}`;\n }\n}\n\nexport async function initNetworkCheck(\n plCredentials: string,\n plUser: string | undefined,\n plPassword: string | undefined,\n optsOverrides: Partial<CheckNetworkOpts> = {},\n): Promise<{\n logger: MiLogger;\n plConfig: PlClientConfig;\n signer: Signer;\n client: PlClient;\n downloadClient: ClientDownload;\n uploadBlobClient: ClientUpload;\n lsDriver: LsDriver;\n httpClient: Dispatcher;\n ops: CheckNetworkOpts;\n terminate: () => Promise<void>;\n}> {\n const ops: CheckNetworkOpts = {\n pingCheckDurationMs: 10000,\n pingTimeoutMs: 3000,\n maxPingsPerSecond: 50,\n\n httpTimeoutMs: 3000,\n\n blockRegistryDurationMs: 3000,\n maxRegistryChecksPerSecond: 1,\n\n blockRegistryUrl: \"https://blocks.pl-open.science\",\n blockGARegistryUrl: \"https://blocks-ga.pl-open.science\",\n blockOverviewPath: \"v2/overview.json\",\n blockUiPath: \"v2/milaboratories/samples-and-data/1.7.0/ui.tgz\",\n\n autoUpdateCdnDurationMs: 5000,\n maxAutoUpdateCdnChecksPerSecond: 1,\n autoUpdateCdnUrl:\n \"https://cdn.platforma.bio/software/platforma-desktop-v2/windows/amd64/latest.yml\",\n\n bodyLimit: 300,\n\n everyStorageBytesLimit: 1024,\n everyStorageMinFileSize: 1024,\n everyStorageMaxFileSize: 200 * 1024 * 1024, // 200 MB\n everyStorageNFilesToCheck: 300,\n everyStorageMinLsRequests: 50,\n ...optsOverrides,\n };\n\n const plConfig = plAddressToConfig(plCredentials, {\n defaultRequestTimeout: ops.pingTimeoutMs,\n });\n\n // exposing alternative root for fields not to interfere with\n // projects of the user.\n plConfig.alternativeRoot = `check_network_${randomUUID()}`;\n\n const uaClient = await UnauthenticatedPlClient.build(plConfig);\n\n let auth: AuthInformation = {};\n if (plUser && plPassword) {\n auth = await uaClient.login(plUser, plPassword);\n }\n\n const client = await PlClient.init(plCredentials, { authInformation: auth });\n\n const httpClient = uaClient.ll.httpDispatcher;\n const logger = new ConsoleLoggerAdapter();\n\n // FIXME: do we need to get an actual secret?\n const signer = new HmacSha256Signer(\"localSecret\");\n\n // We could initialize middle-layer here, but for now it seems like an overkill.\n // Here's the code to do it:\n //\n // const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'platforma-network-check-'));\n // const ml = await MiddleLayer.init(client, tmpDir, {\n // logger,\n // localSecret: '',\n // localProjections: [],\n // openFileDialogCallback: () => Promise.resolve([]),\n // preferredUpdateChannel: 'stable',\n // });\n\n const downloadClient = createDownloadClient(logger, client, []);\n const uploadBlobClient = createUploadBlobClient(client, logger);\n\n const lsDriver = await LsDriver.init(logger, client, signer, [], () => Promise.resolve([]), []);\n\n const terminate = async () => {\n downloadClient.close();\n uploadBlobClient.close();\n await httpClient.close();\n await client.close();\n };\n\n return {\n logger,\n plConfig,\n client,\n signer,\n downloadClient,\n uploadBlobClient,\n lsDriver,\n httpClient,\n ops,\n terminate,\n };\n}\n\nfunction reportsToString(\n report: NetworkReports,\n plEndpoint: string,\n opts: CheckNetworkOpts,\n undiciLogs: any[],\n): string {\n const successPings = report.plPings.filter((p) => p.response.ok);\n const failedPings = report.plPings.filter((p) => !p.response.ok);\n const successPingsBodies = [\n ...new Set(successPings.map((p) => JSON.stringify((p.response as any).value))),\n ];\n\n const summary = (ok: boolean) => (ok ? \"OK\" : \"FAILED\");\n const templateSummary = (report: TemplateReport) =>\n report.status === \"ok\" ? \"OK\" : report.status === \"warn\" ? \"WARN\" : \"FAILED\";\n\n const pings = reportToString(report.plPings);\n const blockRegistryOverview = reportToString(report.blockRegistryOverviewChecks);\n const blockGARegistryOverview = reportToString(report.blockGARegistryOverviewChecks);\n const blockRegistryUi = reportToString(report.blockRegistryUiChecks);\n const blockGARegistryUi = reportToString(report.blockGARegistryUiChecks);\n const autoUpdateCdn = reportToString(report.autoUpdateCdnChecks);\n\n const storagesSummary = Object.entries(report.storageToDownloadReport)\n .map(([storage, report]) => `${templateSummary(report)} ${storage} storage check`)\n .join(\"\\n\");\n\n return `\n${summary(pings.ok)} pings to Platforma Backend\n${summary(blockRegistryOverview.ok)} block registry overview\n${summary(blockGARegistryOverview.ok)} block ga registry overview\n${summary(blockRegistryUi.ok)} block registry ui\n${summary(blockGARegistryUi.ok)} block ga registry ui\n${summary(autoUpdateCdn.ok)} auto-update CDN\n${templateSummary(report.uploadTemplateCheck)} upload template\n${templateSummary(report.uploadFileCheck)} upload file\n${templateSummary(report.downloadFileCheck)} download file\n${templateSummary(report.softwareCheck)} software check\n${templateSummary(report.pythonSoftwareCheck)} python software check\n${storagesSummary}\n\ndetails:\npl endpoint: ${plEndpoint};\noptions: ${JSON.stringify(opts, null, 2)}.\n\nUpload template response: ${report.uploadTemplateCheck.message}\n\nUpload file response: ${report.uploadFileCheck.message}\n\nDownload file response: ${report.downloadFileCheck.message}\n\nSoftware check response: ${report.softwareCheck.message}\nPython software check response: ${report.pythonSoftwareCheck.message}\nStorage to download responses: ${JSON.stringify(report.storageToDownloadReport, null, 2)}\n\nPlatforma pings: ${pings.details}\n\nBlock registry overview responses: ${blockRegistryOverview.details}\n\nBlock ga registry overview responses: ${blockGARegistryOverview.details}\n\nBlock registry ui responses: ${blockRegistryUi.details}\n\nBlock ga registry ui responses: ${blockGARegistryUi.details}\n\nAuto-update CDN responses: ${autoUpdateCdn.details}\n\ndumps:\nBlock registry overview dumps:\n${JSON.stringify(report.blockRegistryOverviewChecks, null, 2)}\n\nBlock ga registry overview dumps:\n${JSON.stringify(report.blockGARegistryOverviewChecks, null, 2)}\n\nBlock registry ui dumps:\n${JSON.stringify(report.blockRegistryUiChecks, null, 2)}\n\nBlock ga registry ui dumps:\n${JSON.stringify(report.blockGARegistryUiChecks, null, 2)}\n\nAuto-update CDN dumps:\n${JSON.stringify(report.autoUpdateCdnChecks, null, 2)}\n\nPlatforma pings error dumps:\n${JSON.stringify(failedPings, null, 2)}\n\nPlatforma pings success dump examples:\n${JSON.stringify(successPingsBodies, null, 2)}\n\nUndici logs:\n${undiciLogs.join(\"\\n\")}\n`;\n}\n\n// List of Undici diagnostic channels\nconst undiciEvents: string[] = [\n \"undici:request:create\", // When a new request is created\n \"undici:request:bodySent\", // When the request body is sent\n \"undici:request:headers\", // When request headers are sent\n \"undici:request:error\", // When a request encounters an error\n \"undici:request:trailers\", // When a response completes.\n\n \"undici:client:sendHeaders\",\n \"undici:client:beforeConnect\",\n \"undici:client:connected\",\n \"undici:client:connectError\",\n\n \"undici:socket:close\", // When a socket is closed\n \"undici:socket:connect\", // When a socket connects\n \"undici:socket:error\", // When a socket encounters an error\n\n \"undici:pool:request\", // When a request is added to the pool\n \"undici:pool:connect\", // When a pool creates a new connection\n \"undici:pool:disconnect\", // When a pool connection is closed\n \"undici:pool:destroy\", // When a pool is destroyed\n \"undici:dispatcher:request\", // When a dispatcher processes a request\n \"undici:dispatcher:connect\", // When a dispatcher connects\n \"undici:dispatcher:disconnect\", // When a dispatcher disconnects\n \"undici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AGtD,KAAK,UAAU,OAAO,yBAAyB,MAAM,CAAC,EAAE;;;EAGxD,KAAK,UAAU,OAAO,qBAAqB,MAAM,CAAC,EAAE;;;EAGpD,KAAK,UAAU,aAAa,MAAM,CAAC,EAAE;;;EAGrC,KAAK,UAAU,oBAAoB,MAAM,CAAC,EAAE;;;EAG5C,WAAW,KAAK,IAAI,EAAE;;AAExB;AAGA,MAAM,eAAyB;CAC7B;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CAEA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF"}
|
|
1
|
+
{"version":3,"file":"network_check.cjs","names":["channel","createTempFile","createBigTempFile","backendPings","blockRegistryOverviewPings","blockGARegistryOverviewPings","blockRegistryUiPings","blockGARegistryUiPings","autoUpdateCdnPings","uploadTemplate","uploadFile","downloadFile","softwareCheck","pythonSoftware","downloadFromEveryStorage","plAddressToConfig","randomUUID","UnauthenticatedPlClient","PlClient","ConsoleLoggerAdapter","HmacSha256Signer","createDownloadClient","createUploadBlobClient","LsDriver","reportToString"],"sources":["../../src/network_check/network_check.ts"],"sourcesContent":["/** A utility to check network problems and gather statistics.\n * It's useful when we cannot connect to the server of a company\n * because of security reasons,\n * but they can send us and their DevOps team this report.\n *\n * What we check:\n * - pings to backend\n * - block registry for block overview and ui.\n * - autoupdate CDN.\n * - upload workflow to backend (workflow part via our API).\n * - the desktop could do multipart upload.\n * - the desktop could download files from S3.\n * - backend could download software and run it.\n * - backend could run python software.\n * - try to get something from every storage to work storage.\n *\n * We don't check backend access to S3 storage, it is checked on the start of backend.\n */\n\nimport type { AuthInformation, PlClientConfig } from \"@milaboratories/pl-client\";\nimport { PlClient, UnauthenticatedPlClient, plAddressToConfig } from \"@milaboratories/pl-client\";\nimport type { MiLogger, Signer } from \"@milaboratories/ts-helpers\";\nimport { ConsoleLoggerAdapter, HmacSha256Signer } from \"@milaboratories/ts-helpers\";\nimport { channel } from \"node:diagnostics_channel\";\nimport type { ClientDownload, ClientUpload } from \"@milaboratories/pl-drivers\";\nimport { LsDriver, createDownloadClient, createUploadBlobClient } from \"@milaboratories/pl-drivers\";\nimport type { HttpNetworkReport, NetworkReport } from \"./pings\";\nimport {\n autoUpdateCdnPings,\n backendPings,\n blockGARegistryOverviewPings,\n blockGARegistryUiPings,\n blockRegistryOverviewPings,\n blockRegistryUiPings,\n reportToString,\n} from \"./pings\";\nimport type { Dispatcher } from \"undici\";\nimport type { TemplateReport } from \"./template\";\nimport {\n uploadTemplate,\n uploadFile,\n downloadFile,\n createTempFile,\n pythonSoftware,\n softwareCheck,\n createBigTempFile,\n downloadFromEveryStorage,\n} from \"./template\";\nimport { randomUUID } from \"node:crypto\";\n\n/** All reports we need to collect. */\ninterface NetworkReports {\n plPings: NetworkReport<string>[];\n\n blockRegistryOverviewChecks: HttpNetworkReport[];\n blockGARegistryOverviewChecks: HttpNetworkReport[];\n blockRegistryUiChecks: HttpNetworkReport[];\n blockGARegistryUiChecks: HttpNetworkReport[];\n\n autoUpdateCdnChecks: HttpNetworkReport[];\n\n uploadTemplateCheck: TemplateReport;\n uploadFileCheck: TemplateReport;\n downloadFileCheck: TemplateReport;\n softwareCheck: TemplateReport;\n pythonSoftwareCheck: TemplateReport;\n storageToDownloadReport: Record<string, TemplateReport>;\n}\n\nexport interface CheckNetworkOpts {\n /** Signal to abort all network checks. */\n signal?: AbortSignal;\n\n /** Platforma Backend pings options. */\n pingCheckDurationMs: number;\n pingTimeoutMs: number;\n maxPingsPerSecond: number;\n\n /** An options for CDN and block registry. */\n httpTimeoutMs: number;\n\n /** Block registry pings options. */\n blockRegistryDurationMs: number;\n maxRegistryChecksPerSecond: number;\n blockRegistryUrl: string;\n blockGARegistryUrl: string;\n blockOverviewPath: string;\n blockUiPath: string;\n\n /** CDN for auto-update pings options. */\n autoUpdateCdnDurationMs: number;\n maxAutoUpdateCdnChecksPerSecond: number;\n autoUpdateCdnUrl: string;\n\n /** Body limit for requests. */\n bodyLimit: number;\n\n /** Limit for the size of files to download from every storage. */\n everyStorageBytesLimit: number;\n /** Minimal size of files to create a directory from for every storage. */\n everyStorageMinFileSize: number;\n /** Maximal size of files to create a directory from for every storage. */\n everyStorageMaxFileSize: number;\n /** How many files to check from every storage. */\n everyStorageNFilesToCheck: number;\n /** Minimal number of ls requests for every storage. */\n everyStorageMinLsRequests: number;\n}\n\n/** Checks connectivity to Platforma Backend, to block registry\n * and to auto-update CDN,\n * and generates a string report. */\nexport async function checkNetwork(\n plCredentials: string,\n plUser: string | undefined,\n plPassword: string | undefined,\n optsOverrides: Partial<CheckNetworkOpts> = {},\n): Promise<string> {\n const undiciLogs: any[] = [];\n // Subscribe to all Undici diagnostic events\n undiciEvents.forEach((event) => {\n const diagnosticChannel = channel(event);\n diagnosticChannel.subscribe((message: any) => {\n const timestamp = new Date().toISOString();\n const data = { ...message };\n if (data?.response?.headers) {\n data.response = { ...data.response };\n data.response.headers = data.response.headers.slice();\n data.response.headers = data.response.headers.map((h: any) => h.toString());\n }\n\n // we try to upload big files, don't include the buffer in the report.\n if (data?.request?.body) {\n data.request = { ...data.request };\n data.request.body = `too big`;\n }\n\n undiciLogs.push(\n JSON.stringify({\n timestamp,\n event,\n data,\n }),\n );\n });\n });\n\n try {\n const {\n logger,\n plConfig,\n client,\n signer,\n downloadClient,\n uploadBlobClient,\n lsDriver,\n httpClient,\n ops,\n } = await initNetworkCheck(plCredentials, plUser, plPassword, optsOverrides);\n\n const { filePath: filePathToDownload, fileContent: fileContentToDownload } =\n await createTempFile();\n const { filePath: filePathToUpload } = await createBigTempFile();\n\n const report: NetworkReports = {\n plPings: await backendPings(ops, plConfig),\n blockRegistryOverviewChecks: await blockRegistryOverviewPings(ops, httpClient),\n blockGARegistryOverviewChecks: await blockGARegistryOverviewPings(ops, httpClient),\n blockRegistryUiChecks: await blockRegistryUiPings(ops, httpClient),\n blockGARegistryUiChecks: await blockGARegistryUiPings(ops, httpClient),\n\n autoUpdateCdnChecks: await autoUpdateCdnPings(ops, httpClient),\n\n uploadTemplateCheck: await uploadTemplate(logger, client, \"Jack\"),\n uploadFileCheck: await uploadFile(\n logger,\n signer,\n lsDriver,\n uploadBlobClient,\n client,\n filePathToUpload,\n ),\n downloadFileCheck: await downloadFile(\n logger,\n client,\n lsDriver,\n uploadBlobClient,\n downloadClient,\n filePathToDownload,\n fileContentToDownload,\n ),\n softwareCheck: await softwareCheck(client),\n pythonSoftwareCheck: await pythonSoftware(client, \"Jack\"),\n storageToDownloadReport: await downloadFromEveryStorage(logger, client, lsDriver, {\n minLsRequests: ops.everyStorageMinLsRequests,\n bytesLimit: ops.everyStorageBytesLimit,\n minFileSize: ops.everyStorageMinFileSize,\n maxFileSize: ops.everyStorageMaxFileSize,\n nFilesToCheck: ops.everyStorageNFilesToCheck,\n }),\n };\n\n return reportsToString(report, plCredentials, ops, undiciLogs);\n } catch (e) {\n return `Unhandled error while checking the network: ${e}`;\n }\n}\n\nexport async function initNetworkCheck(\n plCredentials: string,\n plUser: string | undefined,\n plPassword: string | undefined,\n optsOverrides: Partial<CheckNetworkOpts> = {},\n): Promise<{\n logger: MiLogger;\n plConfig: PlClientConfig;\n signer: Signer;\n client: PlClient;\n downloadClient: ClientDownload;\n uploadBlobClient: ClientUpload;\n lsDriver: LsDriver;\n httpClient: Dispatcher;\n ops: CheckNetworkOpts;\n terminate: () => Promise<void>;\n}> {\n const ops: CheckNetworkOpts = {\n pingCheckDurationMs: 10000,\n pingTimeoutMs: 3000,\n maxPingsPerSecond: 50,\n\n httpTimeoutMs: 3000,\n\n blockRegistryDurationMs: 3000,\n maxRegistryChecksPerSecond: 1,\n\n blockRegistryUrl: \"https://blocks.pl-open.science\",\n blockGARegistryUrl: \"https://blocks-ga.pl-open.science\",\n blockOverviewPath: \"v2/overview.json\",\n blockUiPath: \"v2/milaboratories/samples-and-data/1.7.0/ui.tgz\",\n\n autoUpdateCdnDurationMs: 5000,\n maxAutoUpdateCdnChecksPerSecond: 1,\n autoUpdateCdnUrl:\n \"https://cdn.platforma.bio/software/platforma-desktop-v2/windows/amd64/latest.yml\",\n\n bodyLimit: 300,\n\n everyStorageBytesLimit: 1024,\n everyStorageMinFileSize: 1024,\n everyStorageMaxFileSize: 200 * 1024 * 1024, // 200 MB\n everyStorageNFilesToCheck: 300,\n everyStorageMinLsRequests: 50,\n ...optsOverrides,\n };\n\n const plConfig = plAddressToConfig(plCredentials, {\n defaultRequestTimeout: ops.pingTimeoutMs,\n });\n\n // exposing alternative root for fields not to interfere with\n // projects of the user.\n plConfig.alternativeRoot = `check_network_${randomUUID()}`;\n\n const uaClient = await UnauthenticatedPlClient.build(plConfig);\n\n let auth: AuthInformation = {};\n if (plUser && plPassword) {\n auth = await uaClient.login(plUser, plPassword);\n }\n\n const client = await PlClient.init(plCredentials, { authInformation: auth });\n\n const httpClient = uaClient.ll.httpDispatcher;\n const logger = new ConsoleLoggerAdapter();\n\n // FIXME: do we need to get an actual secret?\n const signer = new HmacSha256Signer(\"localSecret\");\n\n const downloadClient = createDownloadClient(logger, client);\n const uploadBlobClient = createUploadBlobClient(client, logger);\n\n const lsDriver = await LsDriver.init(logger, client, signer, () => Promise.resolve([]), []);\n\n const terminate = async () => {\n downloadClient.close();\n uploadBlobClient.close();\n await httpClient.close();\n await client.close();\n };\n\n return {\n logger,\n plConfig,\n client,\n signer,\n downloadClient,\n uploadBlobClient,\n lsDriver,\n httpClient,\n ops,\n terminate,\n };\n}\n\nfunction reportsToString(\n report: NetworkReports,\n plEndpoint: string,\n opts: CheckNetworkOpts,\n undiciLogs: any[],\n): string {\n const successPings = report.plPings.filter((p) => p.response.ok);\n const failedPings = report.plPings.filter((p) => !p.response.ok);\n const successPingsBodies = [\n ...new Set(successPings.map((p) => JSON.stringify((p.response as any).value))),\n ];\n\n const summary = (ok: boolean) => (ok ? \"OK\" : \"FAILED\");\n const templateSummary = (report: TemplateReport) =>\n report.status === \"ok\" ? \"OK\" : report.status === \"warn\" ? \"WARN\" : \"FAILED\";\n\n const pings = reportToString(report.plPings);\n const blockRegistryOverview = reportToString(report.blockRegistryOverviewChecks);\n const blockGARegistryOverview = reportToString(report.blockGARegistryOverviewChecks);\n const blockRegistryUi = reportToString(report.blockRegistryUiChecks);\n const blockGARegistryUi = reportToString(report.blockGARegistryUiChecks);\n const autoUpdateCdn = reportToString(report.autoUpdateCdnChecks);\n\n const storagesSummary = Object.entries(report.storageToDownloadReport)\n .map(([storage, report]) => `${templateSummary(report)} ${storage} storage check`)\n .join(\"\\n\");\n\n return `\n${summary(pings.ok)} pings to Platforma Backend\n${summary(blockRegistryOverview.ok)} block registry overview\n${summary(blockGARegistryOverview.ok)} block ga registry overview\n${summary(blockRegistryUi.ok)} block registry ui\n${summary(blockGARegistryUi.ok)} block ga registry ui\n${summary(autoUpdateCdn.ok)} auto-update CDN\n${templateSummary(report.uploadTemplateCheck)} upload template\n${templateSummary(report.uploadFileCheck)} upload file\n${templateSummary(report.downloadFileCheck)} download file\n${templateSummary(report.softwareCheck)} software check\n${templateSummary(report.pythonSoftwareCheck)} python software check\n${storagesSummary}\n\ndetails:\npl endpoint: ${plEndpoint};\noptions: ${JSON.stringify(opts, null, 2)}.\n\nUpload template response: ${report.uploadTemplateCheck.message}\n\nUpload file response: ${report.uploadFileCheck.message}\n\nDownload file response: ${report.downloadFileCheck.message}\n\nSoftware check response: ${report.softwareCheck.message}\nPython software check response: ${report.pythonSoftwareCheck.message}\nStorage to download responses: ${JSON.stringify(report.storageToDownloadReport, null, 2)}\n\nPlatforma pings: ${pings.details}\n\nBlock registry overview responses: ${blockRegistryOverview.details}\n\nBlock ga registry overview responses: ${blockGARegistryOverview.details}\n\nBlock registry ui responses: ${blockRegistryUi.details}\n\nBlock ga registry ui responses: ${blockGARegistryUi.details}\n\nAuto-update CDN responses: ${autoUpdateCdn.details}\n\ndumps:\nBlock registry overview dumps:\n${JSON.stringify(report.blockRegistryOverviewChecks, null, 2)}\n\nBlock ga registry overview dumps:\n${JSON.stringify(report.blockGARegistryOverviewChecks, null, 2)}\n\nBlock registry ui dumps:\n${JSON.stringify(report.blockRegistryUiChecks, null, 2)}\n\nBlock ga registry ui dumps:\n${JSON.stringify(report.blockGARegistryUiChecks, null, 2)}\n\nAuto-update CDN dumps:\n${JSON.stringify(report.autoUpdateCdnChecks, null, 2)}\n\nPlatforma pings error dumps:\n${JSON.stringify(failedPings, null, 2)}\n\nPlatforma pings success dump examples:\n${JSON.stringify(successPingsBodies, null, 2)}\n\nUndici logs:\n${undiciLogs.join(\"\\n\")}\n`;\n}\n\n// List of Undici diagnostic channels\nconst undiciEvents: string[] = [\n \"undici:request:create\", // When a new request is created\n \"undici:request:bodySent\", // When the request body is sent\n \"undici:request:headers\", // When request headers are sent\n \"undici:request:error\", // When a request encounters an error\n \"undici:request:trailers\", // When a response completes.\n\n \"undici:client:sendHeaders\",\n \"undici:client:beforeConnect\",\n \"undici:client:connected\",\n \"undici:client:connectError\",\n\n \"undici:socket:close\", // When a socket is closed\n \"undici:socket:connect\", // When a socket connects\n \"undici:socket:error\", // When a socket encounters an error\n\n \"undici:pool:request\", // When a request is added to the pool\n \"undici:pool:connect\", // When a pool creates a new connection\n \"undici:pool:disconnect\", // When a pool connection is closed\n \"undici:pool:destroy\", // When a pool is destroyed\n \"undici:dispatcher:request\", // When a dispatcher processes a request\n \"undici:dispatcher:connect\", // When a dispatcher connects\n \"undici:dispatcher:disconnect\", // When a dispatcher disconnects\n \"undici:dispatcher:retry\", // When a dispatcher retries a request\n];\n"],"mappings":";;;;;;;;;;;AAgHA,eAAsB,aACpB,eACA,QACA,YACA,gBAA2C,CAAC,GAC3B;CACjB,MAAM,aAAoB,CAAC;CAE3B,aAAa,SAAS,UAAU;EAE9B,CAAA,GAD0BA,yBAAAA,QAAAA,CAAQ,KAClB,CAAC,CAAC,WAAW,YAAiB;GAC5C,MAAM,6BAAY,IAAI,KAAK,EAAA,CAAE,YAAY;GACzC,MAAM,OAAO,EAAE,GAAG,QAAQ;GAC1B,IAAI,MAAM,UAAU,SAAS;IAC3B,KAAK,WAAW,EA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plCredentials, plUser, plPassword, optsOverrides
|
|
|
91
91
|
const httpClient = uaClient.ll.httpDispatcher;
|
|
92
92
|
const logger = new ConsoleLoggerAdapter();
|
|
93
93
|
const signer = new HmacSha256Signer("localSecret");
|
|
94
|
-
const downloadClient = createDownloadClient(logger, client
|
|
94
|
+
const downloadClient = createDownloadClient(logger, client);
|
|
95
95
|
const uploadBlobClient = createUploadBlobClient(client, logger);
|
|
96
|
-
const lsDriver = await LsDriver.init(logger, client, signer,
|
|
96
|
+
const lsDriver = await LsDriver.init(logger, client, signer, () => Promise.resolve([]), []);
|
|
97
97
|
const terminate = async () => {
|
|
98
98
|
downloadClient.close();
|
|
99
99
|
uploadBlobClient.close();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"network_check.js","names":[],"sources":["../../src/network_check/network_check.ts"],"sourcesContent":["/** A utility to check network problems and gather statistics.\n * It's useful when we cannot connect to the server of a company\n * because of security reasons,\n * but they can send us and their DevOps team this report.\n *\n * What we check:\n * - pings to backend\n * - block registry for block overview and ui.\n * - autoupdate CDN.\n * - upload workflow to backend (workflow part via our API).\n * - the desktop could do multipart upload.\n * - the desktop could download files from S3.\n * - backend could download software and run it.\n * - backend could run python software.\n * - try to get something from every storage to work storage.\n *\n * We don't check backend access to S3 storage, it is checked on the start of backend.\n */\n\nimport type { AuthInformation, PlClientConfig } from \"@milaboratories/pl-client\";\nimport { PlClient, UnauthenticatedPlClient, plAddressToConfig } from \"@milaboratories/pl-client\";\nimport type { MiLogger, Signer } from \"@milaboratories/ts-helpers\";\nimport { ConsoleLoggerAdapter, HmacSha256Signer } from \"@milaboratories/ts-helpers\";\nimport { channel } from \"node:diagnostics_channel\";\nimport type { ClientDownload, ClientUpload } from \"@milaboratories/pl-drivers\";\nimport { LsDriver, createDownloadClient, createUploadBlobClient } from \"@milaboratories/pl-drivers\";\nimport type { HttpNetworkReport, NetworkReport } from \"./pings\";\nimport {\n autoUpdateCdnPings,\n backendPings,\n blockGARegistryOverviewPings,\n blockGARegistryUiPings,\n blockRegistryOverviewPings,\n blockRegistryUiPings,\n reportToString,\n} from \"./pings\";\nimport type { Dispatcher } from \"undici\";\nimport type { TemplateReport } from \"./template\";\nimport {\n uploadTemplate,\n uploadFile,\n downloadFile,\n createTempFile,\n pythonSoftware,\n softwareCheck,\n createBigTempFile,\n downloadFromEveryStorage,\n} from \"./template\";\nimport { randomUUID } from \"node:crypto\";\n\n/** All reports we need to collect. */\ninterface NetworkReports {\n plPings: NetworkReport<string>[];\n\n blockRegistryOverviewChecks: HttpNetworkReport[];\n blockGARegistryOverviewChecks: HttpNetworkReport[];\n blockRegistryUiChecks: HttpNetworkReport[];\n blockGARegistryUiChecks: HttpNetworkReport[];\n\n autoUpdateCdnChecks: HttpNetworkReport[];\n\n uploadTemplateCheck: TemplateReport;\n uploadFileCheck: TemplateReport;\n downloadFileCheck: TemplateReport;\n softwareCheck: TemplateReport;\n pythonSoftwareCheck: TemplateReport;\n storageToDownloadReport: Record<string, TemplateReport>;\n}\n\nexport interface CheckNetworkOpts {\n /** Signal to abort all network checks. */\n signal?: AbortSignal;\n\n /** Platforma Backend pings options. */\n pingCheckDurationMs: number;\n pingTimeoutMs: number;\n maxPingsPerSecond: number;\n\n /** An options for CDN and block registry. */\n httpTimeoutMs: number;\n\n /** Block registry pings options. */\n blockRegistryDurationMs: number;\n maxRegistryChecksPerSecond: number;\n blockRegistryUrl: string;\n blockGARegistryUrl: string;\n blockOverviewPath: string;\n blockUiPath: string;\n\n /** CDN for auto-update pings options. */\n autoUpdateCdnDurationMs: number;\n maxAutoUpdateCdnChecksPerSecond: number;\n autoUpdateCdnUrl: string;\n\n /** Body limit for requests. */\n bodyLimit: number;\n\n /** Limit for the size of files to download from every storage. */\n everyStorageBytesLimit: number;\n /** Minimal size of files to create a directory from for every storage. */\n everyStorageMinFileSize: number;\n /** Maximal size of files to create a directory from for every storage. */\n everyStorageMaxFileSize: number;\n /** How many files to check from every storage. */\n everyStorageNFilesToCheck: number;\n /** Minimal number of ls requests for every storage. */\n everyStorageMinLsRequests: number;\n}\n\n/** Checks connectivity to Platforma Backend, to block registry\n * and to auto-update CDN,\n * and generates a string report. */\nexport async function checkNetwork(\n plCredentials: string,\n plUser: string | undefined,\n plPassword: string | undefined,\n optsOverrides: Partial<CheckNetworkOpts> = {},\n): Promise<string> {\n const undiciLogs: any[] = [];\n // Subscribe to all Undici diagnostic events\n undiciEvents.forEach((event) => {\n const diagnosticChannel = channel(event);\n diagnosticChannel.subscribe((message: any) => {\n const timestamp = new Date().toISOString();\n const data = { ...message };\n if (data?.response?.headers) {\n data.response = { ...data.response };\n data.response.headers = data.response.headers.slice();\n data.response.headers = data.response.headers.map((h: any) => h.toString());\n }\n\n // we try to upload big files, don't include the buffer in the report.\n if (data?.request?.body) {\n data.request = { ...data.request };\n data.request.body = `too big`;\n }\n\n undiciLogs.push(\n JSON.stringify({\n timestamp,\n event,\n data,\n }),\n );\n });\n });\n\n try {\n const {\n logger,\n plConfig,\n client,\n signer,\n downloadClient,\n uploadBlobClient,\n lsDriver,\n httpClient,\n ops,\n } = await initNetworkCheck(plCredentials, plUser, plPassword, optsOverrides);\n\n const { filePath: filePathToDownload, fileContent: fileContentToDownload } =\n await createTempFile();\n const { filePath: filePathToUpload } = await createBigTempFile();\n\n const report: NetworkReports = {\n plPings: await backendPings(ops, plConfig),\n blockRegistryOverviewChecks: await blockRegistryOverviewPings(ops, httpClient),\n blockGARegistryOverviewChecks: await blockGARegistryOverviewPings(ops, httpClient),\n blockRegistryUiChecks: await blockRegistryUiPings(ops, httpClient),\n blockGARegistryUiChecks: await blockGARegistryUiPings(ops, httpClient),\n\n autoUpdateCdnChecks: await autoUpdateCdnPings(ops, httpClient),\n\n uploadTemplateCheck: await uploadTemplate(logger, client, \"Jack\"),\n uploadFileCheck: await uploadFile(\n logger,\n signer,\n lsDriver,\n uploadBlobClient,\n client,\n filePathToUpload,\n ),\n downloadFileCheck: await downloadFile(\n logger,\n client,\n lsDriver,\n uploadBlobClient,\n downloadClient,\n filePathToDownload,\n fileContentToDownload,\n ),\n softwareCheck: await softwareCheck(client),\n pythonSoftwareCheck: await pythonSoftware(client, \"Jack\"),\n storageToDownloadReport: await downloadFromEveryStorage(logger, client, lsDriver, {\n minLsRequests: ops.everyStorageMinLsRequests,\n bytesLimit: ops.everyStorageBytesLimit,\n minFileSize: ops.everyStorageMinFileSize,\n maxFileSize: ops.everyStorageMaxFileSize,\n nFilesToCheck: ops.everyStorageNFilesToCheck,\n }),\n };\n\n return reportsToString(report, plCredentials, ops, undiciLogs);\n } catch (e) {\n return `Unhandled error while checking the network: ${e}`;\n }\n}\n\nexport async function initNetworkCheck(\n plCredentials: string,\n plUser: string | undefined,\n plPassword: string | undefined,\n optsOverrides: Partial<CheckNetworkOpts> = {},\n): Promise<{\n logger: MiLogger;\n plConfig: PlClientConfig;\n signer: Signer;\n client: PlClient;\n downloadClient: ClientDownload;\n uploadBlobClient: ClientUpload;\n lsDriver: LsDriver;\n httpClient: Dispatcher;\n ops: CheckNetworkOpts;\n terminate: () => Promise<void>;\n}> {\n const ops: CheckNetworkOpts = {\n pingCheckDurationMs: 10000,\n pingTimeoutMs: 3000,\n maxPingsPerSecond: 50,\n\n httpTimeoutMs: 3000,\n\n blockRegistryDurationMs: 3000,\n maxRegistryChecksPerSecond: 1,\n\n blockRegistryUrl: \"https://blocks.pl-open.science\",\n blockGARegistryUrl: \"https://blocks-ga.pl-open.science\",\n blockOverviewPath: \"v2/overview.json\",\n blockUiPath: \"v2/milaboratories/samples-and-data/1.7.0/ui.tgz\",\n\n autoUpdateCdnDurationMs: 5000,\n maxAutoUpdateCdnChecksPerSecond: 1,\n autoUpdateCdnUrl:\n \"https://cdn.platforma.bio/software/platforma-desktop-v2/windows/amd64/latest.yml\",\n\n bodyLimit: 300,\n\n everyStorageBytesLimit: 1024,\n everyStorageMinFileSize: 1024,\n everyStorageMaxFileSize: 200 * 1024 * 1024, // 200 MB\n everyStorageNFilesToCheck: 300,\n everyStorageMinLsRequests: 50,\n ...optsOverrides,\n };\n\n const plConfig = plAddressToConfig(plCredentials, {\n defaultRequestTimeout: ops.pingTimeoutMs,\n });\n\n // exposing alternative root for fields not to interfere with\n // projects of the user.\n plConfig.alternativeRoot = `check_network_${randomUUID()}`;\n\n const uaClient = await UnauthenticatedPlClient.build(plConfig);\n\n let auth: AuthInformation = {};\n if (plUser && plPassword) {\n auth = await uaClient.login(plUser, plPassword);\n }\n\n const client = await PlClient.init(plCredentials, { authInformation: auth });\n\n const httpClient = uaClient.ll.httpDispatcher;\n const logger = new ConsoleLoggerAdapter();\n\n // FIXME: do we need to get an actual secret?\n const signer = new HmacSha256Signer(\"localSecret\");\n\n // We could initialize middle-layer here, but for now it seems like an overkill.\n // Here's the code to do it:\n //\n // const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'platforma-network-check-'));\n // const ml = await MiddleLayer.init(client, tmpDir, {\n // logger,\n // localSecret: '',\n // localProjections: [],\n // openFileDialogCallback: () => Promise.resolve([]),\n // preferredUpdateChannel: 'stable',\n // });\n\n const downloadClient = createDownloadClient(logger, client, []);\n const uploadBlobClient = createUploadBlobClient(client, logger);\n\n const lsDriver = await LsDriver.init(logger, client, signer, [], () => Promise.resolve([]), []);\n\n const terminate = async () => {\n downloadClient.close();\n uploadBlobClient.close();\n await httpClient.close();\n await client.close();\n };\n\n return {\n logger,\n plConfig,\n client,\n signer,\n downloadClient,\n uploadBlobClient,\n lsDriver,\n httpClient,\n ops,\n terminate,\n };\n}\n\nfunction reportsToString(\n report: NetworkReports,\n plEndpoint: string,\n opts: CheckNetworkOpts,\n undiciLogs: any[],\n): string {\n const successPings = report.plPings.filter((p) => p.response.ok);\n const failedPings = report.plPings.filter((p) => !p.response.ok);\n const successPingsBodies = [\n ...new Set(successPings.map((p) => JSON.stringify((p.response as any).value))),\n ];\n\n const summary = (ok: boolean) => (ok ? \"OK\" : \"FAILED\");\n const templateSummary = (report: TemplateReport) =>\n report.status === \"ok\" ? \"OK\" : report.status === \"warn\" ? \"WARN\" : \"FAILED\";\n\n const pings = reportToString(report.plPings);\n const blockRegistryOverview = reportToString(report.blockRegistryOverviewChecks);\n const blockGARegistryOverview = reportToString(report.blockGARegistryOverviewChecks);\n const blockRegistryUi = reportToString(report.blockRegistryUiChecks);\n const blockGARegistryUi = reportToString(report.blockGARegistryUiChecks);\n const autoUpdateCdn = reportToString(report.autoUpdateCdnChecks);\n\n const storagesSummary = Object.entries(report.storageToDownloadReport)\n .map(([storage, report]) => `${templateSummary(report)} ${storage} storage check`)\n .join(\"\\n\");\n\n return `\n${summary(pings.ok)} pings to Platforma Backend\n${summary(blockRegistryOverview.ok)} block registry overview\n${summary(blockGARegistryOverview.ok)} block ga registry overview\n${summary(blockRegistryUi.ok)} block registry ui\n${summary(blockGARegistryUi.ok)} block ga registry ui\n${summary(autoUpdateCdn.ok)} auto-update CDN\n${templateSummary(report.uploadTemplateCheck)} upload template\n${templateSummary(report.uploadFileCheck)} upload file\n${templateSummary(report.downloadFileCheck)} download file\n${templateSummary(report.softwareCheck)} software check\n${templateSummary(report.pythonSoftwareCheck)} python software check\n${storagesSummary}\n\ndetails:\npl endpoint: ${plEndpoint};\noptions: ${JSON.stringify(opts, null, 2)}.\n\nUpload template response: ${report.uploadTemplateCheck.message}\n\nUpload file response: ${report.uploadFileCheck.message}\n\nDownload file response: ${report.downloadFileCheck.message}\n\nSoftware check response: ${report.softwareCheck.message}\nPython software check response: ${report.pythonSoftwareCheck.message}\nStorage to download responses: ${JSON.stringify(report.storageToDownloadReport, null, 2)}\n\nPlatforma pings: ${pings.details}\n\nBlock registry overview responses: ${blockRegistryOverview.details}\n\nBlock ga registry overview responses: ${blockGARegistryOverview.details}\n\nBlock registry ui responses: ${blockRegistryUi.details}\n\nBlock ga registry ui responses: ${blockGARegistryUi.details}\n\nAuto-update CDN responses: ${autoUpdateCdn.details}\n\ndumps:\nBlock registry overview dumps:\n${JSON.stringify(report.blockRegistryOverviewChecks, null, 2)}\n\nBlock ga registry overview dumps:\n${JSON.stringify(report.blockGARegistryOverviewChecks, null, 2)}\n\nBlock registry ui dumps:\n${JSON.stringify(report.blockRegistryUiChecks, null, 2)}\n\nBlock ga registry ui dumps:\n${JSON.stringify(report.blockGARegistryUiChecks, null, 2)}\n\nAuto-update CDN dumps:\n${JSON.stringify(report.autoUpdateCdnChecks, null, 2)}\n\nPlatforma pings error dumps:\n${JSON.stringify(failedPings, null, 2)}\n\nPlatforma pings success dump examples:\n${JSON.stringify(successPingsBodies, null, 2)}\n\nUndici logs:\n${undiciLogs.join(\"\\n\")}\n`;\n}\n\n// List of Undici diagnostic channels\nconst undiciEvents: string[] = [\n \"undici:request:create\", // When a new request is created\n \"undici:request:bodySent\", // When the request body is sent\n \"undici:request:headers\", // When request headers are sent\n \"undici:request:error\", // When a request encounters an error\n \"undici:request:trailers\", // When a response completes.\n\n \"undici:client:sendHeaders\",\n \"undici:client:beforeConnect\",\n \"undici:client:connected\",\n \"undici:client:connectError\",\n\n \"undici:socket:close\", // When a socket is closed\n \"undici:socket:connect\", // When a socket connects\n \"undici:socket:error\", // When a socket encounters an error\n\n \"undici:pool:request\", // When a request is added to the pool\n \"undici:pool:connect\", // When a pool creates a new connection\n \"undici:pool:disconnect\", // When a pool connection is closed\n \"undici:pool:destroy\", // When a pool is destroyed\n \"undici:dispatcher:request\", // When a dispatcher processes a request\n \"undici:dispatcher:connect\", // When a dispatcher connects\n \"undici:dispatcher:disconnect\", // When a dispatcher disconnects\n \"undici:dispatcher:retry\", // When a dispatcher retries a request\n];\n"],"mappings":";;;;;;;;;;;AAgHA,eAAsB,aACpB,eACA,QACA,YACA,gBAA2C,CAAC,GAC3B;CACjB,MAAM,aAAoB,CAAC;CAE3B,aAAa,SAAS,UAAU;EAE9B,QADkC,KAClB,CAAC,CAAC,WAAW,YAAiB;GAC5C,MAAM,6BAAY,IAAI,KAAK,EAAA,CAAE,YAAY;GACzC,MAAM,OAAO,EAAE,GAAG,QAAQ;GAC1B,IAAI,MAAM,UAAU,S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GH,WAAW;WACf,KAAK,UAAU,MAAM,MAAM,CAAC,EAAE;;4BAEb,OAAO,oBAAoB,QAAQ;;wBAEvC,OAAO,gBAAgB,QAAQ;;0BAE7B,OAAO,kBAAkB,QAAQ;;2BAEhC,OAAO,cAAc,QAAQ;kCACtB,OAAO,oBAAoB,QAAQ;iCACpC,KAAK,UAAU,OAAO,yBAAyB,MAAM,CAAC,EAAE;;mBAEtE,MAAM,QAAQ;;qCAEI,sBAAsB,QAAQ;;wCAE3B,wBAAwB,QAAQ;;+BAEzC,gBAAgB,QAAQ;;kCAErB,kBAAkB,QAAQ;;6BAE/B,cAAc,QAAQ;;;;EAIjD,KAAK,UAAU,OAAO,6BAA6B,MAAM,CAAC,EAAE;;;EAG5D,KAAK,UAAU,OAAO,+BAA+B,MAAM,CAAC,EAAE;;;EAG9D,KAAK,UAAU,OAAO,uBAAuB,MAAM,CAAC,EAAE;;;EAGtD,KAAK,UAAU,OAAO,yBAAyB,MAAM,CAAC,EAAE;;;EAGxD,KAAK,UAAU,OAAO,qBAAqB,MAAM,CAAC,EAAE;;;EAGpD,KAAK,UAAU,aAAa,MAAM,CAAC,EAAE;;;EAGrC,KAAK,UAAU,oBAAoB,MAAM,CAAC,EAAE;;;EAG5C,WAAW,KAAK,IAAI,EAAE;;AAExB;AAGA,MAAM,eAAyB;CAC7B;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CAEA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF"}
|
|
1
|
+
{"version":3,"file":"network_check.js","names":[],"sources":["../../src/network_check/network_check.ts"],"sourcesContent":["/** A utility to check network problems and gather statistics.\n * It's useful when we cannot connect to the server of a company\n * because of security reasons,\n * but they can send us and their DevOps team this report.\n *\n * What we check:\n * - pings to backend\n * - block registry for block overview and ui.\n * - autoupdate CDN.\n * - upload workflow to backend (workflow part via our API).\n * - the desktop could do multipart upload.\n * - the desktop could download files from S3.\n * - backend could download software and run it.\n * - backend could run python software.\n * - try to get something from every storage to work storage.\n *\n * We don't check backend access to S3 storage, it is checked on the start of backend.\n */\n\nimport type { AuthInformation, PlClientConfig } from \"@milaboratories/pl-client\";\nimport { PlClient, UnauthenticatedPlClient, plAddressToConfig } from \"@milaboratories/pl-client\";\nimport type { MiLogger, Signer } from \"@milaboratories/ts-helpers\";\nimport { ConsoleLoggerAdapter, HmacSha256Signer } from \"@milaboratories/ts-helpers\";\nimport { channel } from \"node:diagnostics_channel\";\nimport type { ClientDownload, ClientUpload } from \"@milaboratories/pl-drivers\";\nimport { LsDriver, createDownloadClient, createUploadBlobClient } from \"@milaboratories/pl-drivers\";\nimport type { HttpNetworkReport, NetworkReport } from \"./pings\";\nimport {\n autoUpdateCdnPings,\n backendPings,\n blockGARegistryOverviewPings,\n blockGARegistryUiPings,\n blockRegistryOverviewPings,\n blockRegistryUiPings,\n reportToString,\n} from \"./pings\";\nimport type { Dispatcher } from \"undici\";\nimport type { TemplateReport } from \"./template\";\nimport {\n uploadTemplate,\n uploadFile,\n downloadFile,\n createTempFile,\n pythonSoftware,\n softwareCheck,\n createBigTempFile,\n downloadFromEveryStorage,\n} from \"./template\";\nimport { randomUUID } from \"node:crypto\";\n\n/** All reports we need to collect. */\ninterface NetworkReports {\n plPings: NetworkReport<string>[];\n\n blockRegistryOverviewChecks: HttpNetworkReport[];\n blockGARegistryOverviewChecks: HttpNetworkReport[];\n blockRegistryUiChecks: HttpNetworkReport[];\n blockGARegistryUiChecks: HttpNetworkReport[];\n\n autoUpdateCdnChecks: HttpNetworkReport[];\n\n uploadTemplateCheck: TemplateReport;\n uploadFileCheck: TemplateReport;\n downloadFileCheck: TemplateReport;\n softwareCheck: TemplateReport;\n pythonSoftwareCheck: TemplateReport;\n storageToDownloadReport: Record<string, TemplateReport>;\n}\n\nexport interface CheckNetworkOpts {\n /** Signal to abort all network checks. */\n signal?: AbortSignal;\n\n /** Platforma Backend pings options. */\n pingCheckDurationMs: number;\n pingTimeoutMs: number;\n maxPingsPerSecond: number;\n\n /** An options for CDN and block registry. */\n httpTimeoutMs: number;\n\n /** Block registry pings options. */\n blockRegistryDurationMs: number;\n maxRegistryChecksPerSecond: number;\n blockRegistryUrl: string;\n blockGARegistryUrl: string;\n blockOverviewPath: string;\n blockUiPath: string;\n\n /** CDN for auto-update pings options. */\n autoUpdateCdnDurationMs: number;\n maxAutoUpdateCdnChecksPerSecond: number;\n autoUpdateCdnUrl: string;\n\n /** Body limit for requests. */\n bodyLimit: number;\n\n /** Limit for the size of files to download from every storage. */\n everyStorageBytesLimit: number;\n /** Minimal size of files to create a directory from for every storage. */\n everyStorageMinFileSize: number;\n /** Maximal size of files to create a directory from for every storage. */\n everyStorageMaxFileSize: number;\n /** How many files to check from every storage. */\n everyStorageNFilesToCheck: number;\n /** Minimal number of ls requests for every storage. */\n everyStorageMinLsRequests: number;\n}\n\n/** Checks connectivity to Platforma Backend, to block registry\n * and to auto-update CDN,\n * and generates a string report. */\nexport async function checkNetwork(\n plCredentials: string,\n plUser: string | undefined,\n plPassword: string | undefined,\n optsOverrides: Partial<CheckNetworkOpts> = {},\n): Promise<string> {\n const undiciLogs: any[] = [];\n // Subscribe to all Undici diagnostic events\n undiciEvents.forEach((event) => {\n const diagnosticChannel = channel(event);\n diagnosticChannel.subscribe((message: any) => {\n const timestamp = new Date().toISOString();\n const data = { ...message };\n if (data?.response?.headers) {\n data.response = { ...data.response };\n data.response.headers = data.response.headers.slice();\n data.response.headers = data.response.headers.map((h: any) => h.toString());\n }\n\n // we try to upload big files, don't include the buffer in the report.\n if (data?.request?.body) {\n data.request = { ...data.request };\n data.request.body = `too big`;\n }\n\n undiciLogs.push(\n JSON.stringify({\n timestamp,\n event,\n data,\n }),\n );\n });\n });\n\n try {\n const {\n logger,\n plConfig,\n client,\n signer,\n downloadClient,\n uploadBlobClient,\n lsDriver,\n httpClient,\n ops,\n } = await initNetworkCheck(plCredentials, plUser, plPassword, optsOverrides);\n\n const { filePath: filePathToDownload, fileContent: fileContentToDownload } =\n await createTempFile();\n const { filePath: filePathToUpload } = await createBigTempFile();\n\n const report: NetworkReports = {\n plPings: await backendPings(ops, plConfig),\n blockRegistryOverviewChecks: await blockRegistryOverviewPings(ops, httpClient),\n blockGARegistryOverviewChecks: await blockGARegistryOverviewPings(ops, httpClient),\n blockRegistryUiChecks: await blockRegistryUiPings(ops, httpClient),\n blockGARegistryUiChecks: await blockGARegistryUiPings(ops, httpClient),\n\n autoUpdateCdnChecks: await autoUpdateCdnPings(ops, httpClient),\n\n uploadTemplateCheck: await uploadTemplate(logger, client, \"Jack\"),\n uploadFileCheck: await uploadFile(\n logger,\n signer,\n lsDriver,\n uploadBlobClient,\n client,\n filePathToUpload,\n ),\n downloadFileCheck: await downloadFile(\n logger,\n client,\n lsDriver,\n uploadBlobClient,\n downloadClient,\n filePathToDownload,\n fileContentToDownload,\n ),\n softwareCheck: await softwareCheck(client),\n pythonSoftwareCheck: await pythonSoftware(client, \"Jack\"),\n storageToDownloadReport: await downloadFromEveryStorage(logger, client, lsDriver, {\n minLsRequests: ops.everyStorageMinLsRequests,\n bytesLimit: ops.everyStorageBytesLimit,\n minFileSize: ops.everyStorageMinFileSize,\n maxFileSize: ops.everyStorageMaxFileSize,\n nFilesToCheck: ops.everyStorageNFilesToCheck,\n }),\n };\n\n return reportsToString(report, plCredentials, ops, undiciLogs);\n } catch (e) {\n return `Unhandled error while checking the network: ${e}`;\n }\n}\n\nexport async function initNetworkCheck(\n plCredentials: string,\n plUser: string | undefined,\n plPassword: string | undefined,\n optsOverrides: Partial<CheckNetworkOpts> = {},\n): Promise<{\n logger: MiLogger;\n plConfig: PlClientConfig;\n signer: Signer;\n client: PlClient;\n downloadClient: ClientDownload;\n uploadBlobClient: ClientUpload;\n lsDriver: LsDriver;\n httpClient: Dispatcher;\n ops: CheckNetworkOpts;\n terminate: () => Promise<void>;\n}> {\n const ops: CheckNetworkOpts = {\n pingCheckDurationMs: 10000,\n pingTimeoutMs: 3000,\n maxPingsPerSecond: 50,\n\n httpTimeoutMs: 3000,\n\n blockRegistryDurationMs: 3000,\n maxRegistryChecksPerSecond: 1,\n\n blockRegistryUrl: \"https://blocks.pl-open.science\",\n blockGARegistryUrl: \"https://blocks-ga.pl-open.science\",\n blockOverviewPath: \"v2/overview.json\",\n blockUiPath: \"v2/milaboratories/samples-and-data/1.7.0/ui.tgz\",\n\n autoUpdateCdnDurationMs: 5000,\n maxAutoUpdateCdnChecksPerSecond: 1,\n autoUpdateCdnUrl:\n \"https://cdn.platforma.bio/software/platforma-desktop-v2/windows/amd64/latest.yml\",\n\n bodyLimit: 300,\n\n everyStorageBytesLimit: 1024,\n everyStorageMinFileSize: 1024,\n everyStorageMaxFileSize: 200 * 1024 * 1024, // 200 MB\n everyStorageNFilesToCheck: 300,\n everyStorageMinLsRequests: 50,\n ...optsOverrides,\n };\n\n const plConfig = plAddressToConfig(plCredentials, {\n defaultRequestTimeout: ops.pingTimeoutMs,\n });\n\n // exposing alternative root for fields not to interfere with\n // projects of the user.\n plConfig.alternativeRoot = `check_network_${randomUUID()}`;\n\n const uaClient = await UnauthenticatedPlClient.build(plConfig);\n\n let auth: AuthInformation = {};\n if (plUser && plPassword) {\n auth = await uaClient.login(plUser, plPassword);\n }\n\n const client = await PlClient.init(plCredentials, { authInformation: auth });\n\n const httpClient = uaClient.ll.httpDispatcher;\n const logger = new ConsoleLoggerAdapter();\n\n // FIXME: do we need to get an actual secret?\n const signer = new HmacSha256Signer(\"localSecret\");\n\n const downloadClient = createDownloadClient(logger, client);\n const uploadBlobClient = createUploadBlobClient(client, logger);\n\n const lsDriver = await LsDriver.init(logger, client, signer, () => Promise.resolve([]), []);\n\n const terminate = async () => {\n downloadClient.close();\n uploadBlobClient.close();\n await httpClient.close();\n await client.close();\n };\n\n return {\n logger,\n plConfig,\n client,\n signer,\n downloadClient,\n uploadBlobClient,\n lsDriver,\n httpClient,\n ops,\n terminate,\n };\n}\n\nfunction reportsToString(\n report: NetworkReports,\n plEndpoint: string,\n opts: CheckNetworkOpts,\n undiciLogs: any[],\n): string {\n const successPings = report.plPings.filter((p) => p.response.ok);\n const failedPings = report.plPings.filter((p) => !p.response.ok);\n const successPingsBodies = [\n ...new Set(successPings.map((p) => JSON.stringify((p.response as any).value))),\n ];\n\n const summary = (ok: boolean) => (ok ? \"OK\" : \"FAILED\");\n const templateSummary = (report: TemplateReport) =>\n report.status === \"ok\" ? \"OK\" : report.status === \"warn\" ? \"WARN\" : \"FAILED\";\n\n const pings = reportToString(report.plPings);\n const blockRegistryOverview = reportToString(report.blockRegistryOverviewChecks);\n const blockGARegistryOverview = reportToString(report.blockGARegistryOverviewChecks);\n const blockRegistryUi = reportToString(report.blockRegistryUiChecks);\n const blockGARegistryUi = reportToString(report.blockGARegistryUiChecks);\n const autoUpdateCdn = reportToString(report.autoUpdateCdnChecks);\n\n const storagesSummary = Object.entries(report.storageToDownloadReport)\n .map(([storage, report]) => `${templateSummary(report)} ${storage} storage check`)\n .join(\"\\n\");\n\n return `\n${summary(pings.ok)} pings to Platforma Backend\n${summary(blockRegistryOverview.ok)} block registry overview\n${summary(blockGARegistryOverview.ok)} block ga registry overview\n${summary(blockRegistryUi.ok)} block registry ui\n${summary(blockGARegistryUi.ok)} block ga registry ui\n${summary(autoUpdateCdn.ok)} auto-update CDN\n${templateSummary(report.uploadTemplateCheck)} upload template\n${templateSummary(report.uploadFileCheck)} upload file\n${templateSummary(report.downloadFileCheck)} download file\n${templateSummary(report.softwareCheck)} software check\n${templateSummary(report.pythonSoftwareCheck)} python software check\n${storagesSummary}\n\ndetails:\npl endpoint: ${plEndpoint};\noptions: ${JSON.stringify(opts, null, 2)}.\n\nUpload template response: ${report.uploadTemplateCheck.message}\n\nUpload file response: ${report.uploadFileCheck.message}\n\nDownload file response: ${report.downloadFileCheck.message}\n\nSoftware check response: ${report.softwareCheck.message}\nPython software check response: ${report.pythonSoftwareCheck.message}\nStorage to download responses: ${JSON.stringify(report.storageToDownloadReport, null, 2)}\n\nPlatforma pings: ${pings.details}\n\nBlock registry overview responses: ${blockRegistryOverview.details}\n\nBlock ga registry overview responses: ${blockGARegistryOverview.details}\n\nBlock registry ui responses: ${blockRegistryUi.details}\n\nBlock ga registry ui responses: ${blockGARegistryUi.details}\n\nAuto-update CDN responses: ${autoUpdateCdn.details}\n\ndumps:\nBlock registry overview dumps:\n${JSON.stringify(report.blockRegistryOverviewChecks, null, 2)}\n\nBlock ga registry overview dumps:\n${JSON.stringify(report.blockGARegistryOverviewChecks, null, 2)}\n\nBlock registry ui dumps:\n${JSON.stringify(report.blockRegistryUiChecks, null, 2)}\n\nBlock ga registry ui dumps:\n${JSON.stringify(report.blockGARegistryUiChecks, null, 2)}\n\nAuto-update CDN dumps:\n${JSON.stringify(report.autoUpdateCdnChecks, null, 2)}\n\nPlatforma pings error dumps:\n${JSON.stringify(failedPings, null, 2)}\n\nPlatforma pings success dump examples:\n${JSON.stringify(successPingsBodies, null, 2)}\n\nUndici logs:\n${undiciLogs.join(\"\\n\")}\n`;\n}\n\n// List of Undici diagnostic channels\nconst undiciEvents: string[] = [\n \"undici:request:create\", // When a new request is created\n \"undici:request:bodySent\", // When the request body is sent\n \"undici:request:headers\", // When request headers are sent\n \"undici:request:error\", // When a request encounters an error\n \"undici:request:trailers\", // When a response completes.\n\n \"undici:client:sendHeaders\",\n \"undici:client:beforeConnect\",\n \"undici:client:connected\",\n \"undici:client:connectError\",\n\n \"undici:socket:close\", // When a socket is closed\n \"undici:socket:connect\", // When a socket connects\n \"undici:socket:error\", // When a socket encounters an error\n\n \"undici:pool:request\", // When a request is added to the pool\n \"undici:pool:connect\", // When a pool creates a new connection\n \"undici:pool:disconnect\", // When a pool connection is closed\n \"undici:pool:destroy\", // When a pool is destroyed\n \"undici:dispatcher:request\", // When a dispatcher processes a request\n \"undici:dispatcher:connect\", // When a dispatcher connects\n \"undici:dispatcher:disconnect\", // When a dispatcher disconnects\n \"undici:dispatcher:retry\", // When a dispatcher retries a request\n];\n"],"mappings":";;;;;;;;;;;AAgHA,eAAsB,aACpB,eAC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aboratories/pl-client");
|
|
3
2
|
let node_timers_promises = require("node:timers/promises");
|
|
3
|
+
let _milaboratories_pl_client = require("@milaboratories/pl-client");
|
|
4
4
|
// src/network_check/pings.ts
|
|
5
5
|
async function backendPings(ops, plConfig) {
|
|
6
6
|
return await recordPings(ops.pingCheckDurationMs, ops.maxPingsPerSecond, async () => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { request } from "undici";
|
|
2
|
-
import { UnauthenticatedPlClient } from "@milaboratories/pl-client";
|
|
3
2
|
import { setTimeout } from "node:timers/promises";
|
|
3
|
+
import { UnauthenticatedPlClient } from "@milaboratories/pl-client";
|
|
4
4
|
// src/network_check/pings.ts
|
|
5
5
|
async function backendPings(ops, plConfig) {
|
|
6
6
|
return await recordPings(ops.pingCheckDurationMs, ops.maxPingsPerSecond, async () => {
|