Skip to content

Commit

Permalink
refactor(metrics): use dims instead of creating new metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
yossi-eynav committed Feb 4, 2024
1 parent 3b8e474 commit c1ee700
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion server/bin/dummy_job
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ async function run() {
}

async function main(){
await runAndReport({func: run, metricName: "dummy_job"})
await runAndReport({func: run, name: "dummy_job"})
}

main()
18 changes: 13 additions & 5 deletions server/metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,35 @@ const report = async ({ metricName, unit = "None", value = 1.0, dims = [] }) =>
};


async function runAndReport({metricName, func}) {
async function runAndReport({name, func}) {
try {
const res = await func()
report({
metricName,
metricName: "job",
dims: [
{
Name: "result",
Value: "success",
}
},
{
Name: "component",
Value: name,
},
]
})
return res
} catch (e) {
report({
metricName,
metricName: "job",
dims: [
{
Name: "result",
Value: "failed",
}
},
{
Name: "component",
Value: name,
},
]
})
throw e
Expand Down

0 comments on commit c1ee700

Please sign in to comment.