Created
October 21, 2022 10:12
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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