Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] HyperDB integration for metrics #399

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 14 additions & 19 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,22 @@ jobs:
runs-on: ${{ matrix.os }}
timeout-minutes: 15
steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 https://github.com/actions/checkout/releases/tag/v4.1.1
with:
persist-credentials: false
ref: ${{ github.event.pull_request.head.ref }}
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2 https://github.com/actions/setup-node/releases/tag/v4.0.2
with:
node-version: lts/*
- name: Setup repo
uses: holepunchto/actions/.github/steps/setup-repo@v1

- name: Install w/ dev deps
run: npm install
- name: Install w/ dev deps
run: npm install
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Bootstrap
run: npm run bootstrap
- name: Bootstrap
run: npm run bootstrap

- name: Install Bare
run: npm i -g bare-runtime
- name: Install Bare
run: npm i -g bare-runtime

- name: Test
run: npm test
- name: Test
run: npm test

- name: Lint
run: npm run lint
- name: Lint
run: npm run lint
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"lint:fix": "standard --fix",
"archdump": "node scripts/bootstrap.js --archdump",
"prestage": "node scripts/bootstrap.js --archdump --external-corestore && node scripts/prune-dual-prebuilds.mjs",
"bootstrap": "node scripts/bootstrap.js"
"bootstrap": "node scripts/bootstrap.js",
"schema": "bare scripts/schema-builder.js"
},
"author": "Holepunch",
"pear": {
Expand Down Expand Up @@ -51,7 +52,9 @@
],
"standard": {
"globals": [
"Bare", "Pear", "LOG"
"Bare",
"Pear",
"LOG"
],
"ignore": [
"__snapshots__",
Expand All @@ -63,6 +66,7 @@
},
"dependencies": {
"@fontsource/open-sans": "^5.0.22",
"@holepunchto/hyperdb": "^1.5.1",
"@hyperswarm/seeders": "^1.1.6",
"b4a": "^1.6.6",
"bare-bundle": "^1.7.0",
Expand All @@ -89,6 +93,7 @@
"hypercore-crypto": "^3.4.1",
"hypercore-id-encoding": "^1.3.0",
"hyperdrive": "^11.8.1",
"hyperschema": "^1.0.3",
"hyperswarm": "^4.7.14",
"iambus": "^1.0.3",
"listen-async": "^1.0.0",
Expand Down
159 changes: 159 additions & 0 deletions scripts/schema-builder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
const Hyperschema = require('hyperschema')
const Builder = require('@holepunchto/hyperdb/builder')

const SCHEMA_DIR = './spec/schema'
const DB_DIR = './spec/db'

const schema = Hyperschema.from(SCHEMA_DIR)
const pearSchema = schema.namespace('pear')

pearSchema.register({
name: 'node',
fields: [
{
name: 'host',
type: 'string',
required: true
},
{
name: 'port',
type: 'uint',
required: true
}
]
})

pearSchema.register({
name: 'dht-nodes',
fields: [
{
name: 'nodes',
type: '@pear/node',
array: true
}
]
})

pearSchema.register({
name: 'encryption-keys',
fields: [
{ name: 'publicKey', type: 'string', required: true },
{ name: 'privateKey', type: 'string', required: true }
]
})

pearSchema.register({
name: 'permits',
fields: [{ name: 'z32', type: 'string', required: true }]
})

pearSchema.register({
name: 'identity',
fields: [
{ name: 'publicKey', type: 'string', required: true },
{ name: 'privateKey', type: 'string', required: false }
]
})

pearSchema.register({
name: 'apps',
fields: [{ name: 'key', type: 'string', required: true }]
})

pearSchema.register({
name: 'apps-owned',
fields: [{ name: 'key', type: 'string', required: true }]
})

pearSchema.register({
name: 'app-storage',
fields: [{ name: 'app', type: 'string', required: true }]
})

pearSchema.register({
name: 'channels',
fields: [{ name: 'key', type: 'string', required: true }]
})

pearSchema.register({
name: 'error-logs',
fields: [
{ name: 'type', type: 'string', required: true },
{ name: 'trace', type: 'string', required: true }
]
})

pearSchema.register({
name: 'perf-stats',
fields: [
{ name: 'uptimeSeconds', type: 'int', required: true },
{ name: 'ramUsage', type: 'float64', required: true },
{ name: 'cpuUsage', type: 'float64', required: true },
{ name: 'os', type: 'string', required: true }
]
})

Hyperschema.toDisk(schema)

const db = Builder.from(SCHEMA_DIR, DB_DIR)
const pearDB = db.namespace('pear')

pearDB.collections.register({
name: 'dht-nodes',
schema: '@pear/dht-nodes'
})

pearDB.collections.register({
name: 'encryption-keys',
schema: '@pear/encryption-keys',
key: ['publicKey']
})

pearDB.collections.register({
name: 'permits',
schema: '@pear/permits',
key: ['z32']
})

pearDB.collections.register({
name: 'identity',
schema: '@pear/identity',
key: ['publicKey']
})

pearDB.collections.register({
name: 'apps',
schema: '@pear/apps',
key: ['key']
})

pearDB.collections.register({
name: 'apps-owned',
schema: '@pear/apps-owned',
key: ['key']
})

pearDB.collections.register({
name: 'app-storage',
schema: '@pear/app-storage',
key: ['app']
})

pearDB.collections.register({
name: 'channels',
schema: '@pear/channels',
key: ['key']
})

pearDB.collections.register({
name: 'error-logs',
schema: '@pear/error-logs',
key: ['type']
})

pearDB.collections.register({
name: 'perf-stats',
schema: '@pear/perf-stats'
})

Builder.toDisk(db)
132 changes: 132 additions & 0 deletions spec/db/db.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
{
"version": 0,
"offset": 0,
"schema": [
{
"name": "dht-nodes",
"namespace": "pear",
"id": 0,
"type": 1,
"indexes": [],
"schema": "@pear/dht-nodes",
"derived": false,
"key": [],
"trigger": null
},
{
"name": "encryption-keys",
"namespace": "pear",
"id": 1,
"type": 1,
"indexes": [],
"schema": "@pear/encryption-keys",
"derived": false,
"key": [
"publicKey"
],
"trigger": null
},
{
"name": "permits",
"namespace": "pear",
"id": 2,
"type": 1,
"indexes": [],
"schema": "@pear/permits",
"derived": false,
"key": [
"z32"
],
"trigger": null
},
{
"name": "identity",
"namespace": "pear",
"id": 3,
"type": 1,
"indexes": [],
"schema": "@pear/identity",
"derived": false,
"key": [
"publicKey"
],
"trigger": null
},
{
"name": "apps",
"namespace": "pear",
"id": 4,
"type": 1,
"indexes": [],
"schema": "@pear/apps",
"derived": false,
"key": [
"key"
],
"trigger": null
},
{
"name": "apps-owned",
"namespace": "pear",
"id": 5,
"type": 1,
"indexes": [],
"schema": "@pear/apps-owned",
"derived": false,
"key": [
"key"
],
"trigger": null
},
{
"name": "app-storage",
"namespace": "pear",
"id": 6,
"type": 1,
"indexes": [],
"schema": "@pear/app-storage",
"derived": false,
"key": [
"app"
],
"trigger": null
},
{
"name": "channels",
"namespace": "pear",
"id": 7,
"type": 1,
"indexes": [],
"schema": "@pear/channels",
"derived": false,
"key": [
"key"
],
"trigger": null
},
{
"name": "error-logs",
"namespace": "pear",
"id": 8,
"type": 1,
"indexes": [],
"schema": "@pear/error-logs",
"derived": false,
"key": [
"type"
],
"trigger": null
},
{
"name": "perf-stats",
"namespace": "pear",
"id": 9,
"type": 1,
"indexes": [],
"schema": "@pear/perf-stats",
"derived": false,
"key": [],
"trigger": null
}
]
}
Loading
Loading