Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:verida/storage-node into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
nick-verida committed Jul 31, 2023
2 parents 47cd6d5 + f9c0a60 commit 74fe42e
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 14 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,18 @@ docker buildx build --platform linux/amd64,linux/arm64 --push -t verida/storage-

Run tests with `yarn run tests`

You will need to update `/test/config.js` with at least the `VDA_PRIVATE_KEY`, `DID_CLIENT_CONFIG.web3Config.privateKey`
and possibily `ENDPOINTS` and `SERVER_URL`.

Common issues when running tests:

1. `Bad key`: The key in CouchDB configuration for `jwt_keys/hmac:_default` is not a valid Base64 encoded key
2. `HMAC error`: The key in CouchDB configuration for `jwt_keys/hmac:_default` does not match `ACCESS_JWT_SIGN_PK` in `.env`


## Testing a deplyed node
## Testing a deployed node

To test a deployed node, do the following

* Modify `tests/config.js` with the correct endpoint URLs
* Modify `test/config.js` with the correct endpoint URLs
* Run `yarn test test/server.js`
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@verida/storage-node",
"version": "2.1.0",
"version": "2.1.1",
"description": "Verida Storage Node middleware that bridges decentralised identities so they can control access to databases within a CouchDB storage engine",
"main": "dist/server.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/build.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const BUILD_DETAILS = {buildTimestamp: "2023-05-04T01:33:06+00:00"};
export const BUILD_DETAILS = {buildTimestamp: "2023-07-21T04:18:40+00:00"};
22 changes: 18 additions & 4 deletions src/components/db.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import dotenv from 'dotenv';
import CouchDb from 'nano';
import Axios from 'axios';

dotenv.config();
import CouchDb from 'nano';

class Db {

Expand Down Expand Up @@ -50,6 +47,23 @@ class Db {
return info.doc_count
}

// Get some useful couch statistics and metrics to include in the status
async getCouchStats() {
const dsn = this.buildDsn(process.env.DB_USER, process.env.DB_PASS, 'internal');

try {
const metrics = await Axios.get(`${dsn}/_node/_local/_stats/couchdb/`);
return {
requestMeanTimeMS: metrics.data['request_time']['value']['arithmetic_mean'],
requestTimeStdDevMS: metrics.data['request_time']['value']['standard_deviation'],
continuousChangesClientCount: metrics.data['httpd']['clients_requesting_changes']['value']
}
} catch (err) {
console.log(err);
return undefined
}
}

}

const db = new Db()
Expand Down
8 changes: 5 additions & 3 deletions src/controllers/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ import { BUILD_DETAILS } from '../build';
class SystemController {

async status(req, res) {
const currentUsers = await db.totalUsers()
const storageSlotsUsed = await db.totalUsers();
const metrics = await db.getCouchStats();
const wallet = new ethers.Wallet(process.env.VDA_PRIVATE_KEY)

const results = {
maxUsers: parseInt(process.env.MAX_USERS),
currentUsers,
maxStorageSlots: parseInt(process.env.MAX_USERS),
storageSlotsUsed,
metrics: metrics,
version: packageJson.version,
publicKey: wallet.publicKey,
couchUri: db.buildHost(),
Expand Down
10 changes: 7 additions & 3 deletions test/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,13 @@ describe("Server tests", function() {
it("Status", async () => {
const response = await Axios.get(`${SERVER_URL}/status`);

assert.equal(response.data.results.maxUsers, process.env.MAX_USERS, 'Correct maximum number of users')
assert.ok(response.data.results.currentUsers > 2, 'At least two users')
assert.ok(response.data.results.version && response.data.results.version.length, 'Version specified')
assert.equal(response.data.results.maxUsers, process.env.MAX_USERS, 'Correct maximum number of users');
assert.ok(response.data.results.currentUsers > 2, 'At least two users');
assert.ok(response.data.results.version && response.data.results.version.length, 'Version specified');
assert.ok(response.data.results.metrics && response.data.results.metrics.length === 3, 'Metrics exist');
assert.ok(response.data.results.metrics.continuousChangesClientCount >= 0, 'Metric continuousChangesClientCount is in expected range');
assert.ok(response.data.results.metrics.requestMeanTimeMS >= 0, 'Metric requestMeanTimeMS is in expected range');
assert.ok(response.data.results.metrics.requestTimeStdDevMS >= 0, 'Metric requestTimeStdDevMS is in expected range');
})
})
})

0 comments on commit 74fe42e

Please sign in to comment.