Skip to content

Commit

Permalink
Merge pull request #1352 from input-output-hk/feat/web-socket-network…
Browse files Browse the repository at this point in the history
…-info-provider

LW-10739 Add web socket based network info provider
  • Loading branch information
iccicci authored Jul 22, 2024
2 parents 12a0874 + 7036837 commit 95ac6d5
Show file tree
Hide file tree
Showing 35 changed files with 1,522 additions and 28 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/continuous-integration-e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ env:
HANDLE_PROVIDER_PARAMS: '{"baseUrl":"http://localhost:4011/"}'
STAKE_POOL_CONNECTION_STRING: 'postgresql://postgres:doNoUseThisSecret!@localhost:5435/stake_pool'
STAKE_POOL_TEST_CONNECTION_STRING: 'postgresql://postgres:doNoUseThisSecret!@localhost:5435/stake_pool_test'
NETWORK_INFO_PROVIDER: 'http'
NETWORK_INFO_PROVIDER: 'ws'
NETWORK_INFO_PROVIDER_PARAMS: '{"baseUrl":"http://localhost:4000/"}'
OGMIOS_URL: 'ws://localhost:1340/'
REWARDS_PROVIDER: 'http'
Expand All @@ -26,6 +26,7 @@ env:
UTXO_PROVIDER_PARAMS: '{"baseUrl":"http://localhost:4000/"}'
STAKE_POOL_PROVIDER: 'http'
STAKE_POOL_PROVIDER_PARAMS: '{"baseUrl":"http://localhost:4000/"}'
WS_PROVIDER_URL: 'http://localhost:4100/ws'

on:
pull_request:
Expand Down Expand Up @@ -78,6 +79,7 @@ jobs:
run: |
yarn workspace @cardano-sdk/e2e test:wallet:epoch0
yarn workspace @cardano-sdk/e2e test:projection
yarn workspace @cardano-sdk/e2e test:ws
- name: Wait for epoch 3
run: |
Expand Down
44 changes: 44 additions & 0 deletions .github/workflows/k6-web-socket.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,54 @@ name: K6 WebSocket server load tests

on:
workflow_dispatch:
branches: ['master', 'feat/web-socket-network-info-provider']
inputs:
environment:
description: 'Target environment'
type: choice
required: true
options:
- 'dev'
- 'ops'
- 'staging'
- 'prod'
network:
description: 'Target network'
type: choice
required: true
options:
- 'preview'
- 'preprod'
- 'sanchonet'
- 'mainnet'
wallets:
description: 'Number of wallets to simulate'
type: number
required: true
default: 1000

jobs:
web-socket:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Run k6 cloud test
uses: grafana/[email protected]
env:
K6_CLOUD_PROJECT_ID: ${{ secrets.K6_CLOUD_PROJECT_ID }}
with:
filename: ./packages/e2e/test/k6/scenarios/web-socket.test.js
cloud: false
token: ${{ secrets.K6_CLOUD_API_TOKEN }}
flags: >
-e TARGET_ENV=${{ inputs.environment }}
-e TARGET_NET=${{ inputs.network }}
-e WALLETS=${{ inputs.wallets }}
--out json=web-socket-results.json
--quiet
- name: Upload performance test results
uses: actions/upload-artifact@v3
with:
name: k6-report
path: web-socket-results.json
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,8 @@ COPY compose/projector/init.* ./
RUN chmod 755 init.sh
HEALTHCHECK CMD test `curl --fail --silent http://localhost:3000/v1.0.0/health | jq -r ".services[0].projectedTip.blockNo"` -gt 1
CMD ["./init.sh"]

FROM cardano-services as ws-server
WORKDIR /app/packages/cardano-services
HEALTHCHECK CMD curl --fail --silent http://localhost:3000/health
CMD ["bash", "-c", "../../node_modules/.bin/tsx watch --clear-screen=false --conditions=development src/cli start-ws-server"]
23 changes: 23 additions & 0 deletions compose/common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ x-sdk-environment: &sdk-environment
POSTGRES_USER_FILE_HANDLE: /run/secrets/postgres_user
POSTGRES_USER_FILE_STAKE_POOL: /run/secrets/postgres_user
TOKEN_METADATA_SERVER_URL: https://metadata.world.dev.cardano.org
USE_WEB_SOCKET_API: true
WEB_SOCKET_API_URL: ws://ws-server:3000/ws

services:
cardano-db-sync:
Expand Down Expand Up @@ -358,6 +360,27 @@ services:
ports:
- ${HANDLE_API_PORT:-4011}:3000

ws-server:
<<:
- *from-sdk
- *logging
- *provider-server
- *with-postgres
build:
args:
- NETWORK=${NETWORK:-mainnet}
context: ../../
target: ws-server
environment:
<<:
- *sdk-environment
- *provider-server-environment
ports:
- ${WS_SERVER_PORT:-4100}:3000
restart: always
volumes:
- ../..:/app

secrets:
# Replicates the db-sync secret for historical reasons.
# When the SDK was using only one database (the db-sync one) the only secret for database name used was this one
Expand Down
10 changes: 10 additions & 0 deletions nix/cardano-services/deployments/backend-ingress.nix
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,16 @@
};
}
]
++ lib.optionals values.ws-server.enabled [
{
pathType = "Exact";
path = "/ws";
backend.service = {
name = "${chart.name}-ws-server";
port.name = "http";
};
}
]
++ values.cardano-services.additionalRoutes;
})
values.backend.hostnames;
Expand Down
14 changes: 14 additions & 0 deletions nix/cardano-services/deployments/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ in
resources.requests = mkPodResources "150Mi" "200m";
};

ws-server = {
enabled = false;
resources.limits = mkPodResources "300Mi" "300m";
resources.requests = mkPodResources "150Mi" "200m";
};

backend = {
allowedOrigins = lib.concatStringsSep "," allowedOrigins;
passHandleDBArgs = true;
Expand Down Expand Up @@ -169,6 +175,7 @@ in
};
imports = [
./options.nix
./ws-server.deployment.nix
./provider.resource.nix
./projector.resource.nix
./backend.provider.nix
Expand Down Expand Up @@ -209,6 +216,7 @@ in
};

values = {
ws-server.enabled = true;
stakepool.databaseName = "stakepoolv2";
cardano-services = {
ingresOrder = 99;
Expand Down Expand Up @@ -255,6 +263,7 @@ in
};

values = {
ws-server.enabled = true;
blockfrost-worker.enabled = false;
pg-boss-worker.enabled = true;

Expand Down Expand Up @@ -322,6 +331,7 @@ in
};

values = {
ws-server.enabled = true;
ingress.enabled = false;
pg-boss-worker.enabled = true;
stakepool.databaseName = "stakepoolv2";
Expand Down Expand Up @@ -358,6 +368,7 @@ in
};

values = {
ws-server.enabled = true;
cardano-services = {
ingresOrder = 99;
additionalRoutes = [
Expand Down Expand Up @@ -406,6 +417,7 @@ in
};

values = {
ws-server.enabled = true;
stakepool.databaseName = "stakepoolv2";
backend.allowedOrigins = lib.concatStringsSep "," allowedOriginsDev;

Expand Down Expand Up @@ -445,6 +457,7 @@ in
};

values = {
ws-server.enabled = true;
stakepool.databaseName = "stakepoolv2";
blockfrost-worker.enabled = true;
pg-boss-worker.enabled = true;
Expand Down Expand Up @@ -870,6 +883,7 @@ in
};

values = {
ws-server.enabled = true;
cardano-services = {
ingresOrder = 99;
};
Expand Down
110 changes: 110 additions & 0 deletions nix/cardano-services/deployments/ws-server.deployment.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
{
lib,
utils,
values,
chart,
config,
...
}: {
templates.ws-server-service = lib.mkIf values.ws-server.enabled {
apiVersion = "v1";
kind = "Service";
metadata = {
name = "${chart.name}-ws-server";
labels = utils.appLabels "ws-server";
};
spec = {
ports = [
{
name = "http";
protocol = "TCP";
port = 3000;
targetPort = 3000;
}
];
selector = utils.appLabels "ws-server";
};
};

templates.ws-server-deployment = lib.mkIf values.ws-server.enabled {
apiVersion = "apps/v1";
kind = "Deployment";
metadata = {
name = "${chart.name}-ws-server";
labels = utils.appLabels "ws-server";
};
spec = {
selector.matchLabels = utils.appLabels "ws-server";
template = {
metadata.labels = utils.appLabels "ws-server";
spec = {
imagePullSecrets = [
{
name = "dockerconfigjson";
}
];
containers = [
{
inherit (values.cardano-services) image;
inherit (values.ws-server) resources;
name = "ws-server";
ports = [
{
containerPort = 3000;
name = "http";
}
];
livenessProbe = {
httpGet = {
path = "/health";
port = 3000;
};
};
securityContext = {
runAsUser = 0;
runAsGroup = 0;
};
args = ["start-ws-server"];
env = utils.mkPodEnv ({
NETWORK = config.network;
DB_CACHE_TTL = "7200";
OGMIOS_URL = "ws://${config.namespace}-cardano-core.${config.namespace}.svc.cluster.local:1337";

POSTGRES_POOL_MAX_DB_SYNC = "2";
POSTGRES_HOST_DB_SYNC = values.postgresName;
POSTGRES_PORT_DB_SYNC = "5432";
POSTGRES_DB_DB_SYNC = "cardano";
POSTGRES_PASSWORD_DB_SYNC = {
valueFrom.secretKeyRef = {
name = "cardano-owner-user.${values.postgresName}.credentials.postgresql.acid.zalan.do";
key = "password";
};
};
POSTGRES_USER_DB_SYNC = {
valueFrom.secretKeyRef = {
name = "cardano-owner-user.${values.postgresName}.credentials.postgresql.acid.zalan.do";
key = "username";
};
};
POSTGRES_SSL_DB_SYNC = "true";
POSTGRES_SSL_CA_FILE_DB_SYNC = "/tls/ca.crt";
});
volumeMounts = [
{
mountPath = "/tls";
name = "tls";
}
];
}
];
volumes = [
{
name = "tls";
secret.secretName = "postgresql-server-cert";
}
];
};
};
};
};
}
4 changes: 3 additions & 1 deletion packages/cardano-services-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@
"@cardano-sdk/util": "workspace:~",
"axios": "^0.28.0",
"class-validator": "^0.14.0",
"isomorphic-ws": "^5.0.0",
"json-bigint": "~1.0.0",
"ts-log": "^2.2.4"
"ts-log": "^2.2.4",
"ws": "^8.17.1"
},
"files": [
"dist/*",
Expand Down
Loading

0 comments on commit 95ac6d5

Please sign in to comment.