Skip to content

Commit

Permalink
feat: fly indexer process http service (#670)
Browse files Browse the repository at this point in the history
* Add port 8081 for indexer

* fix

* chore: added indexer web service

---------

Co-authored-by: 0xKurt <[email protected]>
  • Loading branch information
hussedev and 0xKurt authored Sep 11, 2024
1 parent 64fd8e5 commit 35be50d
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 79 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ npm run dev -- --from-block=12345 # start indexing from the 12345th block
npm run dev -- --run-once # index and exit without watching for events
npm run dev -- --no-cache # disable cache
npm run dev -- --log-level=trace # set log level
npm run dev -- --port=8081 # start web service on a given port
```

## Running in production
Expand Down
125 changes: 82 additions & 43 deletions fly.toml
Original file line number Diff line number Diff line change
@@ -1,66 +1,105 @@
app = 'indexer-v2'
primary_region = 'den'
kill_signal = 'SIGINT'
kill_timeout = '5s'

app = "indexer-v2"
primary_region = "den"
kill_signal = "SIGINT"
kill_timeout = "5s"

[experimental]
auto_rollback = true

[build]

[deploy]
wait_timeout = '6h0m0s'
wait_timeout = "6h0m0s"

[env]
PINO_PRETTY = 'true'
DEPLOYMENT_ENVIRONMENT = 'production'
ENABLE_RESOURCE_MONITOR = 'false'
ESTIMATES_LINEARQF_WORKER_POOL_SIZE = '10'
INDEXED_CHAINS = 'mainnet,optimism,fantom,pgn-testnet,pgn-mainnet,arbitrum,polygon,sepolia,avalanche,avalanche-fuji,scroll,scroll-sepolia,base,zksync-era-mainnet,lukso-mainnet,lukso-testnet,celo-mainnet,celo-testnet,sei-mainnet,metisAndromeda'
LOG_LEVEL = 'debug'
NODE_OPTIONS = '--max-old-space-size=4096'
PORT = '8080'
STORAGE_DIR = '/mnt/indexer'
PASSPORT_SCORER_ID=335
PINO_PRETTY = "true"
DEPLOYMENT_ENVIRONMENT = "production"
ENABLE_RESOURCE_MONITOR = "false"
ESTIMATES_LINEARQF_WORKER_POOL_SIZE = "10"
INDEXED_CHAINS = "mainnet,optimism,fantom,pgn-testnet,pgn-mainnet,arbitrum,polygon,sepolia,avalanche,avalanche-fuji,scroll,scroll-sepolia,base,zksync-era-mainnet,lukso-mainnet,lukso-testnet,celo-mainnet,celo-testnet,sei-mainnet,metisAndromeda"
LOG_LEVEL = "debug"
NODE_OPTIONS = "--max-old-space-size=4096"
PORT = "8080"
STORAGE_DIR = "/mnt/indexer"
PASSPORT_SCORER_ID = 335

[processes]
indexer = 'npm start -- --indexer --http'
web = 'npm start -- --http --http-wait-for-sync=false'
indexer = "npm start -- --indexer --http"
web = "npm start -- --http --http-wait-for-sync=false"

[[mounts]]
source = 'indexer_staging'
destination = '/mnt/indexer'
initial_size = '50GB'
source = "indexer_staging"
destination = "/mnt/indexer"
initial_size = "50GB"
auto_extend_size_threshold = 80
auto_extend_size_increment = "5GB"
auto_extend_size_limit = "100GB"
processes = ['indexer', 'web']
processes = ["indexer", "web"]

[http_service]
[[services]]
internal_port = 8080
force_https = true
auto_stop_machines = true
auto_start_machines = true
min_machines_running = 2
processes = ['web']

[http_service.concurrency]
type = 'requests'
processes = ["indexer"]
protocol = "tcp"
script_checks = []

[services.concurrency]
hard_limit = 250
soft_limit = 200
type = "requests"

[[services.ports]]
force_https = true
handlers = ["http"]
port = 80

[[services.ports]]
handlers = ["tls", "http"]
port = 443

[[services.tcp_checks]]
grace_period = "30s"
interval = "15s"
restart_limit = 0
timeout = "10s"

[[services]]
internal_port = 8080
processes = ["web"]
protocol = "tcp"
script_checks = []

[services.concurrency]
hard_limit = 250
soft_limit = 200
type = "requests"

[[services.ports]]
force_https = true
handlers = ["http"]
port = 80

[[services.ports]]
handlers = ["tls", "http"]
port = 443

[[services.tcp_checks]]
grace_period = "30s"
interval = "15s"
restart_limit = 0
timeout = "10s"

[checks]
[checks.http]
port = 8080
type = 'http'
interval = '15s'
timeout = '10s'
grace_period = '30s'
method = 'get'
path = '/api/v1/status'
processes = ['web', 'indexer']
[checks.http]
port = 8080
type = "http"
interval = "15s"
timeout = "10s"
grace_period = "30s"
method = "get"
path = "/api/v1/status"
processes = ["web", "indexer"]

[[vm]]
memory = '4gb'
cpu_kind = 'performance'
cpus = 2
memory = "4gb"
cpu_kind = "performance"
cpus = 2
85 changes: 49 additions & 36 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1839,6 +1839,44 @@ export type Config = {
};

export function getConfig(): Config {
const { values: args } = parseArgs({
options: {
"to-block": {
type: "string",
},
"from-block": {
type: "string",
},
"drop-db": {
type: "boolean",
},
"rm-cache": {
type: "boolean",
},
"log-level": {
type: "string",
},
"run-once": {
type: "boolean",
},
"no-cache": {
type: "boolean",
},
"http-wait-for-sync": {
type: "string",
},
http: {
type: "boolean",
},
indexer: {
type: "boolean",
},
port: {
type: "string",
},
},
});

const buildTag = z
.union([z.string(), z.null()])
.default(null)
Expand All @@ -1849,7 +1887,17 @@ export function getConfig(): Config {
.transform((value) => value === "true")
.parse(process.env.ENABLE_RESOURCE_MONITOR);

const apiHttpPort = z.coerce.number().parse(process.env.PORT);
const portSchema = z.coerce.number().int().nonnegative().max(65535);

const portOverride = z
.union([portSchema, z.undefined()])
.optional()
.parse(args["port"]);

const apiHttpPort =
portOverride !== undefined
? portOverride
: portSchema.parse(z.coerce.number().parse(process.env.PORT));

const pinoPretty = z
.enum(["true", "false"])
Expand Down Expand Up @@ -1890,41 +1938,6 @@ export function getConfig(): Config {
.default(path.join(storageDir, "cache"))
.parse(process.env.CACHE_DIR);

const { values: args } = parseArgs({
options: {
"to-block": {
type: "string",
},
"from-block": {
type: "string",
},
"drop-db": {
type: "boolean",
},
"rm-cache": {
type: "boolean",
},
"log-level": {
type: "string",
},
"run-once": {
type: "boolean",
},
"no-cache": {
type: "boolean",
},
"http-wait-for-sync": {
type: "string",
},
http: {
type: "boolean",
},
indexer: {
type: "boolean",
},
},
});

const chains = z
.string()
.or(z.literal("all"))
Expand Down

0 comments on commit 35be50d

Please sign in to comment.