Skip to content

Commit

Permalink
Bugfix/metrics provider undefined error (#3489)
Browse files Browse the repository at this point in the history
fix metrics provider undefined error
  • Loading branch information
HenryHengZJ authored Nov 8, 2024
1 parent ccc0088 commit d64cb70
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/server/src/services/assistants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +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 })
appServer.metricsProvider?.incrementCounter(FLOWISE_METRIC_COUNTERS.ASSISTANT_CREATED, { status: FLOWISE_COUNTER_STATUS.SUCCESS })
return dbResponse
} catch (error) {
throw new InternalFlowiseError(
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/services/chatflows/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ 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(
appServer.metricsProvider?.incrementCounter(
dbResponse?.type === 'MULTIAGENT' ? FLOWISE_METRIC_COUNTERS.AGENTFLOW_CREATED : FLOWISE_METRIC_COUNTERS.CHATFLOW_CREATED,
{ status: FLOWISE_COUNTER_STATUS.SUCCESS }
)
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/services/documentstore/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,7 @@ const _insertIntoVectorStoreWorkerThread = async (data: ICommonObject) => {
type: ChatType.INTERNAL,
flowGraph: omit(indexResult['result'], ['totalKeys', 'addedDocs'])
})
appServer.metricsProvider.incrementCounter(FLOWISE_METRIC_COUNTERS.VECTORSTORE_UPSERT, { status: FLOWISE_COUNTER_STATUS.SUCCESS })
appServer.metricsProvider?.incrementCounter(FLOWISE_METRIC_COUNTERS.VECTORSTORE_UPSERT, { status: FLOWISE_COUNTER_STATUS.SUCCESS })

entity.status = DocumentStoreStatus.UPSERTED
await appServer.AppDataSource.getRepository(DocumentStore).save(entity)
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/services/tools/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +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 })
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)}`)
Expand Down
8 changes: 4 additions & 4 deletions packages/server/src/utils/buildChatflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ export const utilBuildChatflow = async (req: Request, isInternal: boolean = fals
flowGraph: getTelemetryFlowObj(nodes, edges)
})

appServer.metricsProvider.incrementCounter(
appServer.metricsProvider?.incrementCounter(
isInternal ? FLOWISE_METRIC_COUNTERS.CHATFLOW_PREDICTION_INTERNAL : FLOWISE_METRIC_COUNTERS.CHATFLOW_PREDICTION_EXTERNAL,
{ status: FLOWISE_COUNTER_STATUS.SUCCESS }
)
Expand All @@ -512,7 +512,7 @@ export const utilBuildChatflow = async (req: Request, isInternal: boolean = fals

return result
} catch (e) {
appServer.metricsProvider.incrementCounter(
appServer.metricsProvider?.incrementCounter(
isInternal ? FLOWISE_METRIC_COUNTERS.CHATFLOW_PREDICTION_INTERNAL : FLOWISE_METRIC_COUNTERS.CHATFLOW_PREDICTION_EXTERNAL,
{ status: FLOWISE_COUNTER_STATUS.FAILURE }
)
Expand Down Expand Up @@ -608,7 +608,7 @@ const utilBuildAgentResponse = async (
type: isInternal ? ChatType.INTERNAL : ChatType.EXTERNAL,
flowGraph: getTelemetryFlowObj(nodes, edges)
})
appServer.metricsProvider.incrementCounter(
appServer.metricsProvider?.incrementCounter(
isInternal ? FLOWISE_METRIC_COUNTERS.AGENTFLOW_PREDICTION_INTERNAL : FLOWISE_METRIC_COUNTERS.AGENTFLOW_PREDICTION_EXTERNAL,
{ status: FLOWISE_COUNTER_STATUS.SUCCESS }
)
Expand Down Expand Up @@ -658,7 +658,7 @@ const utilBuildAgentResponse = async (
return undefined
} catch (e) {
logger.error('[server]: Error:', e)
appServer.metricsProvider.incrementCounter(
appServer.metricsProvider?.incrementCounter(
isInternal ? FLOWISE_METRIC_COUNTERS.AGENTFLOW_PREDICTION_INTERNAL : FLOWISE_METRIC_COUNTERS.AGENTFLOW_PREDICTION_EXTERNAL,
{ status: FLOWISE_COUNTER_STATUS.FAILURE }
)
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/utils/upsertVector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export const upsertVector = async (req: Request, isInternal: boolean = false) =>
flowGraph: getTelemetryFlowObj(nodes, edges),
stopNodeId
})
appServer.metricsProvider.incrementCounter(FLOWISE_METRIC_COUNTERS.VECTORSTORE_UPSERT, { status: FLOWISE_COUNTER_STATUS.SUCCESS })
appServer.metricsProvider?.incrementCounter(FLOWISE_METRIC_COUNTERS.VECTORSTORE_UPSERT, { status: FLOWISE_COUNTER_STATUS.SUCCESS })

return upsertedResult['result'] ?? { result: 'Successfully Upserted' }
} catch (e) {
Expand Down

0 comments on commit d64cb70

Please sign in to comment.