observe failed digest-score api call lantency in prometheus too
This commit is contained in:
@ -248,7 +248,7 @@ const rankCandidates = async (
|
||||
const scores = await scoreClient.getScores(data)
|
||||
// update scores for candidates
|
||||
candidates.forEach((item) => {
|
||||
item.score = scores[item.id]['score'] || 0
|
||||
item.score = scores[item.id].score || 0
|
||||
})
|
||||
|
||||
// rank candidates by score in descending order
|
||||
|
||||
@ -75,9 +75,9 @@ class ScoreClientImpl implements ScoreClient {
|
||||
}
|
||||
|
||||
async getScores(data: ScoreApiRequestBody): Promise<ScoreApiResponse> {
|
||||
try {
|
||||
const start = Date.now()
|
||||
const start = Date.now()
|
||||
|
||||
try {
|
||||
const response = await axios.post<ScoreApiResponse>(this.apiUrl, data, {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
@ -85,9 +85,6 @@ class ScoreClientImpl implements ScoreClient {
|
||||
timeout: 5000,
|
||||
})
|
||||
|
||||
const duration = (Date.now() - start) / 1000 // in seconds
|
||||
latency.observe(duration)
|
||||
|
||||
return response.data
|
||||
} catch (error) {
|
||||
logError(error)
|
||||
@ -96,6 +93,9 @@ class ScoreClientImpl implements ScoreClient {
|
||||
return {
|
||||
[Object.keys(data.items)[0]]: { score: 0 },
|
||||
}
|
||||
} finally {
|
||||
const duration = (Date.now() - start) / 1000 // in seconds
|
||||
latency.observe(duration)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user