FEATURE:: Support for metrics collection - Prometheus and Open Telemetry (#3420)

* adding support for prometheus and grafana

* open telemetry

* lint fixes

* missing counter and telemetry standardization

---------

Co-authored-by: Henry <hzj94@hotmail.com>
This commit is contained in:
Vinod Kiran
2024-11-08 05:30:43 +05:30
committed by GitHub
parent 8466e1a0b0
commit fe03683f0c
22 changed files with 3493 additions and 54 deletions
@@ -8,6 +8,7 @@ import { decryptCredentialData, getAppVersion } from '../../utils'
import { InternalFlowiseError } from '../../errors/internalFlowiseError'
import { getErrorMessage } from '../../errors/utils'
import { DeleteResult } from 'typeorm'
import { FLOWISE_METRIC_COUNTERS, FLOWISE_COUNTER_STATUS } from '../../Interface.Metrics'
const createAssistant = async (requestBody: any): Promise<Assistant> => {
try {
@@ -111,6 +112,7 @@ const createAssistant = async (requestBody: any): Promise<Assistant> => {
version: await getAppVersion(),
assistantId: dbResponse.id
})
appServer.metricsProvider.incrementCounter(FLOWISE_METRIC_COUNTERS.ASSISTANT_CREATED, { status: FLOWISE_COUNTER_STATUS.SUCCESS })
return dbResponse
} catch (error) {
throw new InternalFlowiseError(
@@ -13,6 +13,7 @@ import { containsBase64File, updateFlowDataWithFilePaths } from '../../utils/fil
import { getRunningExpressApp } from '../../utils/getRunningExpressApp'
import { utilGetUploadsConfig } from '../../utils/getUploadsConfig'
import logger from '../../utils/logger'
import { FLOWISE_METRIC_COUNTERS, FLOWISE_COUNTER_STATUS } from '../../Interface.Metrics'
// Check if chatflow valid for streaming
const checkIfChatflowIsValidForStreaming = async (chatflowId: string): Promise<any> => {
@@ -191,6 +192,11 @@ const saveChatflow = async (newChatFlow: ChatFlow): Promise<any> => {
chatflowId: dbResponse.id,
flowGraph: getTelemetryFlowObj(JSON.parse(dbResponse.flowData)?.nodes, JSON.parse(dbResponse.flowData)?.edges)
})
appServer.metricsProvider.incrementCounter(
dbResponse?.type === 'MULTIAGENT' ? FLOWISE_METRIC_COUNTERS.AGENTFLOW_CREATED : FLOWISE_METRIC_COUNTERS.CHATFLOW_CREATED,
{ status: FLOWISE_COUNTER_STATUS.SUCCESS }
)
return dbResponse
} catch (error) {
throw new InternalFlowiseError(
@@ -31,7 +31,7 @@ import { Document } from '@langchain/core/documents'
import { App } from '../../index'
import { UpsertHistory } from '../../database/entities/UpsertHistory'
import { cloneDeep, omit } from 'lodash'
import telemetryService from '../telemetry'
import { FLOWISE_COUNTER_STATUS, FLOWISE_METRIC_COUNTERS } from '../../Interface.Metrics'
const DOCUMENT_STORE_BASE_FOLDER = 'docustore'
@@ -990,15 +990,13 @@ const _insertIntoVectorStoreWorkerThread = async (data: ICommonObject) => {
await appServer.AppDataSource.getRepository(UpsertHistory).save(upsertHistoryItem)
}
await telemetryService.createEvent({
name: `vector_upserted`,
data: {
version: await getAppVersion(),
chatlowId: chatflowid,
type: ChatType.INTERNAL,
flowGraph: omit(indexResult['result'], ['totalKeys', 'addedDocs'])
}
await appServer.telemetry.sendTelemetry('vector_upserted', {
version: await getAppVersion(),
chatlowId: chatflowid,
type: ChatType.INTERNAL,
flowGraph: omit(indexResult['result'], ['totalKeys', 'addedDocs'])
})
appServer.metricsProvider.incrementCounter(FLOWISE_METRIC_COUNTERS.VECTORSTORE_UPSERT, { status: FLOWISE_COUNTER_STATUS.SUCCESS })
entity.status = DocumentStoreStatus.UPSERTED
await appServer.AppDataSource.getRepository(DocumentStore).save(entity)
@@ -1,10 +0,0 @@
import { getRunningExpressApp } from '../../utils/getRunningExpressApp'
const createEvent = async (eventInfo: any) => {
const appServer = getRunningExpressApp()
await appServer.telemetry.sendTelemetry(eventInfo.name, eventInfo.data)
}
export default {
createEvent
}
@@ -4,6 +4,7 @@ import { InternalFlowiseError } from '../../errors/internalFlowiseError'
import { getErrorMessage } from '../../errors/utils'
import { getAppVersion } from '../../utils'
import { getRunningExpressApp } from '../../utils/getRunningExpressApp'
import { FLOWISE_METRIC_COUNTERS, FLOWISE_COUNTER_STATUS } from '../../Interface.Metrics'
const createTool = async (requestBody: any): Promise<any> => {
try {
@@ -17,6 +18,7 @@ const createTool = async (requestBody: any): Promise<any> => {
toolId: dbResponse.id,
toolName: dbResponse.name
})
appServer.metricsProvider.incrementCounter(FLOWISE_METRIC_COUNTERS.TOOL_CREATED, { status: FLOWISE_COUNTER_STATUS.SUCCESS })
return dbResponse
} catch (error) {
throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: toolsService.createTool - ${getErrorMessage(error)}`)