Skip to content

fix: reuse helia logger instead of creating a new one #156

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

Merged
merged 3 commits into from
Jul 9, 2024
Merged
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
10 changes: 4 additions & 6 deletions src/healthcheck.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
#!/usr/bin/env node
import { HOST, RPC_PORT } from './constants.js'
import { logger } from './logger.js'

const log = logger.forComponent('healthcheck')

/**
* This healthcheck script is used to check if the server is running and healthy.
* This healthcheck script is used to check if the server is running and healthy
*/
const rootReq = await fetch(`http://${HOST}:${RPC_PORT}/api/v0/http-gateway-healthcheck`, { method: 'GET' })
const rootReq = await fetch(`http://${HOST}:${RPC_PORT}/api/v0/http-gateway-healthcheck`, {
method: 'GET'
})
const status = rootReq.status
Comment on lines +5 to 10
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: are we getting any logging information now that we're removing the log here?

the prior log was probably too verbose (log every 12 seconds..) but I just want to make sure we can see some type of healthcheck item if we need to


log(`Healthcheck status: ${status}`)
process.exit(status === 200 ? 0 : 1)
4 changes: 1 addition & 3 deletions src/helia-http-gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { dnsLinkLabelEncoder, isInlinedDnsLink } from './dns-link-labels.js'
import { getFullUrlFromFastifyRequest, getRequestAwareSignal } from './helia-server.js'
import { getIpnsAddressDetails } from './ipns-address-utils.js'
import type { VerifiedFetch } from '@helia/verified-fetch'
import type { ComponentLogger } from '@libp2p/interface'
import type { AbortOptions } from '@multiformats/multiaddr'
import type { FastifyReply, FastifyRequest, RouteOptions } from 'fastify'
import type { Helia } from 'helia'
Expand All @@ -16,13 +15,12 @@ interface EntryParams {
}

export interface HeliaHTTPGatewayOptions {
logger: ComponentLogger
helia: Helia
fetch: VerifiedFetch
}

export function httpGateway (opts: HeliaHTTPGatewayOptions): RouteOptions[] {
const log = opts.logger.forComponent('http-gateway')
const log = opts.helia.logger.forComponent('http-gateway')

/**
* Redirects to the subdomain gateway.
Expand Down
4 changes: 1 addition & 3 deletions src/helia-rpc-api.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
import { GC_TIMEOUT_MS, HEALTHCHECK_TIMEOUT_MS } from './constants.js'
import { getRequestAwareSignal } from './helia-server.js'
import type { VerifiedFetch } from '@helia/verified-fetch'
import type { ComponentLogger } from '@libp2p/interface'
import type { FastifyReply, FastifyRequest, RouteOptions } from 'fastify'
import type { Helia } from 'helia'

const HELIA_RELEASE_INFO_API = (version: string): string => `https://api.github.com/repos/ipfs/helia/git/ref/tags/helia-v${version}`

export interface HeliaRPCAPIOptions {
logger: ComponentLogger
helia: Helia
fetch: VerifiedFetch
}

export function rpcApi (opts: HeliaRPCAPIOptions): RouteOptions[] {
const log = opts.logger.forComponent('rpc-api')
const log = opts.helia.logger.forComponent('rpc-api')
let heliaVersionInfo: { Version: string, Commit: string } | undefined

/**
Expand Down
6 changes: 1 addition & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,23 +165,19 @@ import { contentTypeParser } from './content-type-parser.js'
import { getCustomHelia } from './get-custom-helia.js'
import { httpGateway } from './helia-http-gateway.js'
import { rpcApi } from './helia-rpc-api.js'
import { logger } from './logger.js'

const log = logger.forComponent('index')

const helia = await getCustomHelia()
const fetch = await createVerifiedFetch(helia, { contentTypeParser })
const log = helia.logger.forComponent('index')

const [rpcApiServer, httpGatewayServer] = await Promise.all([
createServer('rpc-api', rpcApi({
logger,
helia,
fetch
}), {
metrics: false
}),
createServer('http-gateway', httpGateway({
logger,
helia,
fetch
}), {
Expand Down
3 changes: 0 additions & 3 deletions src/logger.ts

This file was deleted.

Loading