Skip to content

Commit

Permalink
fix influxdb timestamp reporting. add prettier fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
iturricf committed Apr 1, 2024
1 parent 72b9d71 commit 7427194
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions frontend/scripts/influxdb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,13 @@ async function main() {
const readApi = influxDB.getQueryApi(INFLUX_ORG)

let latestTxBlockTime = 0
let latestSignature = await getLatestTxSignature(INFLUX_BUCKET, CLUSTER, readApi)
let latestSignature = await getLatestTxSignature(
INFLUX_BUCKET,
CLUSTER,
readApi
)

console.log("LATEST SIGNATURE AT START:", latestSignature);
console.log("LATEST SIGNATURE AT START:", latestSignature)
const tokenDispenserEventSubscriber = new TokenDispenserEventSubscriber(
ENDPOINT,
new anchor.web3.PublicKey(PROGRAM_ID),
Expand Down Expand Up @@ -143,7 +147,7 @@ async function main() {
writeApi.writePoint(failedTxnEventPoint)
})

console.log('Latest Signature at the end:', latestSignature);
console.log('Latest Signature at the end:', latestSignature)
const latestTxPoint = new Point('latest_txn_seen')
.tag('network', CLUSTER)
.stringField('signature', latestSignature)
Expand All @@ -161,21 +165,25 @@ async function main() {
})
}

async function getLatestTxSignature(bucket: string, network: string, readApi: QueryApi): Promise<string | undefined> {
async function getLatestTxSignature(
bucket: string,
network: string,
readApi: QueryApi
): Promise<string | undefined> {
const query = `from(bucket: "${bucket}")
|> range(start: -1d)
|> filter(fn: (r) => r._measurement == "latest_txn_seen")
|> filter(fn: (r) => r.network == "${network}")
|> last()
|> limit(n:1)`

let signature = undefined;
for await (const {values, tableMeta} of readApi.iterateRows(query)) {
let signature = undefined
for await (const { values, tableMeta } of readApi.iterateRows(query)) {
const o = tableMeta.toObject(values)
signature = o._value.length > 0 ? o._value : undefined
}

return signature;
return signature
}

function createTxnEventPoints(formattedTxnEvents: FormattedTxnEventInfo[]) {
Expand All @@ -198,7 +206,7 @@ function createTxnEventPoints(formattedTxnEvents: FormattedTxnEventInfo[]) {
.stringField('signature', signature)
.intField('amount', amountValue)
.stringField('eventDetails', JSON.stringify(formattedEvent))
.timestamp(new Date(formattedEvent.blockTime * 1000).toISOString())
.timestamp(new Date(formattedEvent.blockTime * 1000))

return point
})
Expand Down Expand Up @@ -241,7 +249,7 @@ function createDoubleClaimPoint(formattedTxnEvents: FormattedTxnEventInfo[]) {
.tag('network', CLUSTER)
.tag('service', 'token-dispenser-event-subscriber')
.stringField('details', JSON.stringify(txnEventInfos))
.timestamp(new Date(blockTime * 1000).toISOString())
.timestamp(new Date(blockTime * 1000))
doubleClaimPoints.push(point)
}
entry = entryGen.next()
Expand All @@ -257,7 +265,7 @@ function createFailedTxnEventPoints(failedTxns: TxnInfo[]) {
.tag('network', CLUSTER)
.tag('service', 'token-dispenser-event-subscriber')
.stringField('errorDetails', JSON.stringify(errorLog))
.timestamp(new Date(errorLog.blockTime * 1000).toISOString())
.timestamp(new Date(errorLog.blockTime * 1000))
return point
})
}
Expand Down

0 comments on commit 7427194

Please sign in to comment.