Skip to content

Commit

Permalink
feat: added dataversion to logging (#637)
Browse files Browse the repository at this point in the history
we added it to pino config as prefix and an endpoint /version
  • Loading branch information
hussedev authored Aug 8, 2024
1 parent eb1706f commit 3ca4462
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1826,6 +1826,7 @@ export type Config = {
sentryDsn: string | null;
databaseUrl: string;
readOnlyDatabaseUrl: string;
dataVersion: string;
databaseSchemaName: string;
hostname: string;
pinoPretty: boolean;
Expand Down Expand Up @@ -1979,7 +1980,8 @@ export function getConfig(): Config {
.default(databaseUrl)
.parse(process.env.READ_ONLY_DATABASE_URL);

const databaseSchemaName = `chain_data_${CHAIN_DATA_VERSION}`;
const dataVersion = CHAIN_DATA_VERSION;
const databaseSchemaName = `chain_data_${dataVersion}`;

const dropDb = z.boolean().default(false).parse(args["drop-db"]);

Expand Down Expand Up @@ -2028,6 +2030,7 @@ export function getConfig(): Config {
databaseUrl,
readOnlyDatabaseUrl,
dropDb,
dataVersion,
databaseSchemaName,
httpServerWaitForSync,
httpServerEnabled,
Expand Down
5 changes: 5 additions & 0 deletions src/http/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface HttpApiConfig {
priceProvider: PriceProvider;
db: Database;
dataProvider: DataProvider;
dataVersion?: string;
passportProvider: PassportProvider;
graphqlHandler?: AsyncRequestHandler;
hostname: string;
Expand Down Expand Up @@ -95,6 +96,10 @@ export const createHttpApi = (config: HttpApiConfig): HttpApi => {

app.get("/data/*", staticJsonDataHandler(config.dataProvider));

app.get("/version", (_req, res) => {
res.send(config.dataVersion);
});

app.use("/api/v1", api);

if (config.graphqlHandler !== undefined) {
Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ function createPgPool(args: { url: string; logger: Logger }): pg.Pool {

return pool;
}

async function main(): Promise<void> {
const config = getConfig();

Expand Down Expand Up @@ -99,6 +98,7 @@ async function main(): Promise<void> {
: {};

const baseLogger = pino({
msgPrefix: `[${config.dataVersion}] `,
level: config.logLevel,
formatters: {
level(level) {
Expand Down Expand Up @@ -366,6 +366,7 @@ async function main(): Promise<void> {
db,
priceProvider,
passportProvider: passportProvider,
dataVersion: config.dataVersion,
dataProvider: new CachedDataProvider({
dataProvider: new DatabaseDataProvider(db),
cache: new TTLCache({
Expand Down

0 comments on commit 3ca4462

Please sign in to comment.