-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #251 from cardanoapi/enhancement/event-based-form-…
…integration Enhancement/event based form integration
- Loading branch information
Showing
259 changed files
with
6,149 additions
and
5,148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,26 @@ | ||
import { ParameterizedMessageObject, Span, Transaction } from "elastic-apm-node"; | ||
import { ParameterizedMessageObject, Span, Transaction } from 'elastic-apm-node' | ||
|
||
export const apm = require('elastic-apm-node') | ||
import apmAgent from 'elastic-apm-node' | ||
|
||
export const apm = apmAgent | ||
|
||
function readConfig(){ | ||
if(process.env.ELASTIC_APM_SERVER_URL && process.env.ELASTIC_APM_API_KEY && process.env.ELASTIC_APM_ENVIRONMENT){ | ||
return { | ||
ELASTIC_APM_SERVER_URL: process.env.ELASTIC_APM_SERVER_URL, | ||
ELASTIC_APM_API_KEY: process.env.ELASTIC_APM_API_KEY, | ||
ELASTIC_APM_ENVIRONMENT: process.env.ELASTIC_APM_ENVIRONMENT | ||
} | ||
} | ||
function readConfig() { | ||
if (process.env.ELASTIC_APM_SERVER_URL && process.env.ELASTIC_APM_API_KEY && process.env.ELASTIC_APM_ENVIRONMENT) { | ||
return { | ||
ELASTIC_APM_SERVER_URL: process.env.ELASTIC_APM_SERVER_URL, | ||
ELASTIC_APM_API_KEY: process.env.ELASTIC_APM_API_KEY, | ||
ELASTIC_APM_ENVIRONMENT: process.env.ELASTIC_APM_ENVIRONMENT, | ||
} | ||
} | ||
} | ||
export const apmConfig=readConfig() | ||
export const apmConfig = readConfig() | ||
|
||
export const startTransaction= (...args: any[]): Transaction=>{ | ||
return apm.startTransaction(...args); | ||
export const startTransaction = (...args: any[]): Transaction => { | ||
return apm.startTransaction(...args) | ||
} | ||
export const captureError= (err: Error | string | ParameterizedMessageObject)=>{ | ||
return apm.captureError(err) | ||
export const captureError = (err: Error | string | ParameterizedMessageObject) => { | ||
return apm.captureError(err) | ||
} | ||
export const startSpan = (...args: any[]): Span | any => { | ||
return apm.startSpan(...args) | ||
} | ||
export const startSpan = (...args: any[]) : Span | any =>{ | ||
return apm.startSpan(...args); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Router, Request, Response } from 'express' | ||
import { handlerWrapper } from '../utils/asyncWrapper' | ||
import environments from '../config/environments' | ||
|
||
const router = Router() | ||
|
||
async function blockfrostHealthCheck(req: Request, res: Response) { | ||
const url = `https://cardano-${environments.networkName}.blockfrost.io/api/v0/health` | ||
const response = await fetch(url, { | ||
method: 'GET', | ||
headers: { | ||
project_id: environments.blockFrostApiKey, | ||
}, | ||
}) | ||
return res.status(response.status).send(await response.json()) | ||
} | ||
|
||
router.get('/', handlerWrapper(blockfrostHealthCheck)) | ||
|
||
export default router |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Router, Request, Response } from 'express' | ||
import { handlerWrapper } from '../utils/asyncWrapper' | ||
import { checkKafkaStatus } from '../service/healthCheck/kafka' | ||
import { cardanoNodeStatus } from '../service/healthCheck/cardanoNode' | ||
|
||
const router = Router() | ||
|
||
async function healthCheck(req: Request, res: Response) { | ||
try { | ||
const isKafkaHealthy = await checkKafkaStatus() | ||
const nodeStatus = cardanoNodeStatus.checkStatus() | ||
return res.status(isKafkaHealthy && nodeStatus.isHealthy ? 200 : 503).send({ | ||
isHealthy: isKafkaHealthy && nodeStatus.isHealthy, | ||
details: { | ||
kafka: { | ||
isHealthy: isKafkaHealthy, | ||
}, | ||
cardanoNode: { | ||
isHealthy: nodeStatus.isHealthy, | ||
secsSinceLastBlock: cardanoNodeStatus.lastTimeStamp, | ||
lastBlock: nodeStatus.block, | ||
}, | ||
}, | ||
}) | ||
} catch (err: any) { | ||
return res.status(500).send(err.message ? err.message : err) | ||
} | ||
} | ||
|
||
router.get('/', handlerWrapper(healthCheck)) | ||
|
||
export default router |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,24 @@ | ||
import { PrismaClient } from "@prisma/client"; | ||
import { apm } from "../config/tracer"; | ||
import { PrismaClient } from '@prisma/client' | ||
import { apm } from '../config/tracer' | ||
|
||
export const prisma = new PrismaClient() | ||
|
||
if(process.env.ELASTIC_APM_SERVER_URL && process.env.ELASTIC_APM_API_KEY){ | ||
prisma.$use(async (params: any, next:any) => { | ||
const spanName=params.model?`prisma.${params.model}.${params.action}`:`prisma.${params.action}` | ||
const span = apm.startSpan(spanName); | ||
if (span) { | ||
span.type = "DB"; | ||
span.subtype = "prisma"; | ||
span.action = "query"; | ||
} | ||
try { | ||
const result = await next(params); | ||
span?.end(); | ||
return result; | ||
} catch (e) { | ||
span?.end(); | ||
throw e; | ||
} | ||
}); | ||
} | ||
if (process.env.ELASTIC_APM_SERVER_URL && process.env.ELASTIC_APM_API_KEY) { | ||
prisma.$use(async (params: any, next: any) => { | ||
const spanName = params.model ? `prisma.${params.model}.${params.action}` : `prisma.${params.action}` | ||
const span = apm.startSpan(spanName) | ||
if (span) { | ||
span.type = 'DB' | ||
span.subtype = 'prisma' | ||
span.action = 'query' | ||
} | ||
try { | ||
const result = await next(params) | ||
span?.end() | ||
return result | ||
} catch (e) { | ||
span?.end() | ||
throw e | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.