Skip to content

Commit

Permalink
Fixes sync-store metrics for postgres (#663)
Browse files Browse the repository at this point in the history
* fix metrics in sync-store

* Fixes sync-store metrics for postgres
  • Loading branch information
kyscott18 authored Feb 26, 2024
1 parent 762a8b2 commit 51aa6f7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .changeset/rare-dogs-speak.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ponder/core": patch
---

Fixed sync-store metrics for Postgres apps.
28 changes: 14 additions & 14 deletions packages/core/src/sync-store/postgres/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class PostgresSyncStore implements SyncStore {
const { error } = await this.migrator.migrateToLatest();
if (error) throw error;

this.record("migrateUp", start);
this.record("migrateUp", performance.now() - start);
};

insertLogFilterInterval = async ({
Expand Down Expand Up @@ -136,7 +136,7 @@ export class PostgresSyncStore implements SyncStore {
});
});

this.record("insertLogFilterInterval", start);
this.record("insertLogFilterInterval", performance.now() - start);
};

getLogFilterIntervals = async ({
Expand Down Expand Up @@ -253,7 +253,7 @@ export class PostgresSyncStore implements SyncStore {

const intersectIntervals = intervalIntersectionMany(fragmentIntervals);

this.record("getLogFilterIntervals", start);
this.record("getLogFilterIntervals", performance.now() - start);

return intersectIntervals;
};
Expand Down Expand Up @@ -282,7 +282,7 @@ export class PostgresSyncStore implements SyncStore {
}
});

this.record("insertFactoryChildAddressLogs", start);
this.record("insertFactoryChildAddressLogs", performance.now() - start);
};

async *getFactoryChildAddresses({
Expand Down Expand Up @@ -335,7 +335,7 @@ export class PostgresSyncStore implements SyncStore {
if (batch.length < pageSize) break;
}

this.record("getFactoryChildAddresses", start);
this.record("getFactoryChildAddresses", performance.now() - start);
}

insertFactoryLogFilterInterval = async ({
Expand Down Expand Up @@ -386,7 +386,7 @@ export class PostgresSyncStore implements SyncStore {
});
});

this.record("insertFactoryLogFilterInterval", start);
this.record("insertFactoryLogFilterInterval", performance.now() - start);
};

getFactoryLogFilterIntervals = async ({
Expand Down Expand Up @@ -515,7 +515,7 @@ export class PostgresSyncStore implements SyncStore {

const intersectIntervals = intervalIntersectionMany(fragmentIntervals);

this.record("getFactoryLogFilterIntervals", start);
this.record("getFactoryLogFilterIntervals", performance.now() - start);

return intersectIntervals;
};
Expand Down Expand Up @@ -557,7 +557,7 @@ export class PostgresSyncStore implements SyncStore {
}
});

this.record("insertRealtimeBlock", start);
this.record("insertRealtimeBlock", performance.now() - start);
};

insertRealtimeInterval = async ({
Expand Down Expand Up @@ -595,7 +595,7 @@ export class PostgresSyncStore implements SyncStore {
});
});

this.record("insertRealtimeInterval", start);
this.record("insertRealtimeInterval", performance.now() - start);
};

deleteRealtimeData = async ({
Expand Down Expand Up @@ -701,7 +701,7 @@ export class PostgresSyncStore implements SyncStore {
.execute();
});

this.record("deleteRealtimeData", start);
this.record("deleteRealtimeData", performance.now() - start);
};

/** SYNC HELPER METHODS */
Expand Down Expand Up @@ -791,7 +791,7 @@ export class PostgresSyncStore implements SyncStore {
)
.execute();

this.record("insertRpcRequestResult", start);
this.record("insertRpcRequestResult", performance.now() - start);
};

getRpcRequestResult = async ({
Expand All @@ -815,7 +815,7 @@ export class PostgresSyncStore implements SyncStore {

const result = contractReadResult ?? null;

this.record("getRpcRequestResult", start);
this.record("getRpcRequestResult", performance.now() - start);

return result;
};
Expand Down Expand Up @@ -1292,10 +1292,10 @@ export class PostgresSyncStore implements SyncStore {
callback: (tx: KyselyTransaction<SyncStoreTables>) => Promise<U>,
) => this.db.transaction().execute(callback);

private record(methodName: string, start: number) {
private record(methodName: string, duration: number) {
this.common.metrics.ponder_sync_store_method_duration.observe(
{ method: methodName },
performance.now() - start,
duration,
);
}
}
Expand Down

0 comments on commit 51aa6f7

Please sign in to comment.