Skip to content

Instantly share code, notes, and snippets.

@tom1299
Created October 21, 2022 10:12
Show Gist options
  • Save tom1299/b86e2f825f4f6b340438a927e264a905 to your computer and use it in GitHub Desktop.
Save tom1299/b86e2f825f4f6b340438a927e264a905 to your computer and use it in GitHub Desktop.
A query for calculating the average running time of a job in a GitLab pipeline.
db.pipelines.aggregate([
{
$unwind: "$jobs"
},
{
$group: {
_id: {
"project": "$project_id",
"jobName": "$jobs.name"
},
averageRun: {
$avt: {
$dateDiff: {
startDate: {
"$dateFromString": {
"dateString": "$jobs.started_at",
"format": "%Y-%m-%dT%H:%M:%S.%LZ"
}
},
endDate: {
"$dateFromString": {
"dateString": "$jobs.finished_at",
"format": "%Y-%m-%dT%H:%M:%S.%LZ"
}
},
unit: "second"
}
}
}
}
}
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment