Skip to content

Commit

Permalink
refactor clickhouse sink
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisCarriere committed Feb 18, 2024
1 parent f8cd21c commit a3da148
Show file tree
Hide file tree
Showing 49 changed files with 569 additions and 830 deletions.
17 changes: 2 additions & 15 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,7 @@ PASSWORD=
# Webhook Authentication (Optional)
PUBLIC_KEY=... # ed25519 public key provided by https://github.com/pinax-network/substreams-sink-webhook

# HTTP Server (Optional)
# Clickhouse Sink (Optional)
PORT=3000
HOSTNAME=0.0.0.0

# Clickhouse Sink Authentication (Optional)
# PUT endpoints are protected (uses HTTP Basic authentication)
AUTH_KEY=...

# Clickhouse Sink (Optional)
MAX_BUFFER_SIZE=1000
INSERTION_DELAY=2000
WAIT_FOR_INSERT=0
ASYNC_INSERT=1
BUFFER=buffer.db
ALLOW_UNPARSED=false
VERBOSE=true
RESUME=true
VERBOSE=true
13 changes: 1 addition & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,24 +91,13 @@ Options:
-p, --port <number> HTTP port on which to attach the sink (default: "3000", env: PORT)
-v, --verbose <boolean> Enable verbose logging (choices: "true", "false", default: "true", env: VERBOSE)
--hostname <string> Server listen on HTTP hostname (default: "0.0.0.0", env: HOSTNAME)
--public-key <string> Comma separated list of public keys to validate messages (env: PUBLIC_KEY)
--auth-key <string> Auth key to validate requests (env: AUTH_KEY)
--public-keys <string> Comma separated list of public keys to validate messages (env: PUBLIC_KEYS)
--host <string> Database HTTP hostname (default: "http://localhost:8123", env: HOST)
--username <string> Database user (default: "default", env: USERNAME)
--password <string> Password associated with the specified username (default: "", env: PASSWORD)
--database <string> The database to use inside ClickHouse (default: "default", env: DATABASE)
--async-insert <number> https://clickhouse.com/docs/en/operations/settings/settings#async-insert (choices:
"0", "1", default: 1, env: ASYNC_INSERT)
--wait-for-async-insert <boolean> https://clickhouse.com/docs/en/operations/settings/settings#wait-for-async-insert
(choices: "0", "1", default: 0, env: WAIT_FOR_INSERT)
--max-buffer-size <number> Maximum insertion batch size (default: 10000, env: MAX_BUFFER_SIZE)
--insertion-delay <number> Delay between batch insertions (in ms) (default: 2000, env: INSERTION_DELAY)
--allow-unparsed <boolean> Enable storage in 'unparsed_json' table (choices: "true", "false", default: false,
env: ALLOW_UNPARSED)
--resume <boolean> Save the cached data from the previous process into ClickHouse (choices: "true",
"false", default: true, env: RESUME)
--buffer <string> SQLite database to use as an insertion buffer. Use ':memory:' to make it volatile.
(default: "buffer.db", env: BUFFER)
-h, --help display help for command
```

Expand Down
12 changes: 7 additions & 5 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import PUT from "./src/fetch/PUT.js";
import { NotFound } from "./src/fetch/cors.js";
import { logger } from "./src/logger.js";
import init from "./src/fetch/init.js";
import { show_tables } from "./src/clickhouse/stores.js";

if (config.verbose) logger.enable();

Expand All @@ -26,8 +27,9 @@ const app = Bun.serve({
},
});

logger.info('[app]', `${name} v${version}`);
logger.info('[app]', `Server listening on http://${app.hostname}:${app.port}`);
logger.info('[app]', `Clickhouse Server ${config.host} (${config.database})`);
if (config.publicKey) logger.info('[app]', `Webhook Ed25519 Public Key: ${config.publicKey}`);
init();
logger.info('[app]\t', `${name} v${version}`);
logger.info('[app]\t', `Server listening on http://${app.hostname}:${app.port}`);
logger.info('[app]\t', `Clickhouse Server ${config.host} (${config.database})`);
if (config.publicKey) logger.info('[app]\t', `Webhook Ed25519 Public Key: ${config.publicKey}`);
await init();
await show_tables();
Loading

0 comments on commit a3da148

Please sign in to comment.