Class MetricsStore
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic final classA commit to write alongside its build.static classstatic classstatic final classA stage to write alongside its build.static class -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptiondoubleavgLeadTimeMs(long fromMs, long toMs, String jobPattern) doubleavgLeadTimeMs(long fromMs, long toMs, String jobPattern, Set<String> excludedJobs) doubleavgLeadTimeMs(long fromMs, long toMs, String jobPattern, Set<String> excludedJobs, String branchPattern) Average lead time of the successful builds in the window, as the time from the earliest commit that build deployed until it finished.voidcleanup(long retainAfterTimestamp) longcountDeployments(long fromMs, long toMs, String jobPattern, Set<String> excludedJobs, String branchPattern) Builds that ran as a deployment, successfully or not: SUCCESS, UNSTABLE or FAILURE.longcountFailedBuilds(long fromMs, long toMs, String jobPattern) longcountFailedBuilds(long fromMs, long toMs, String jobPattern, Set<String> excludedJobs) longcountFailedBuilds(long fromMs, long toMs, String jobPattern, Set<String> excludedJobs, String branchPattern) As above, counting only builds on a branch matchingbranchPattern, or all when it is null.longcountSuccessfulBuilds(long fromMs, long toMs, String jobPattern) longcountSuccessfulBuilds(long fromMs, long toMs, String jobPattern, Set<String> excludedJobs) longcountSuccessfulBuilds(long fromMs, long toMs, String jobPattern, Set<String> excludedJobs, String branchPattern) As above, counting only builds on a branch matchingbranchPattern, or all when it is null.longcountTotalBuilds(long fromMs, long toMs, String jobPattern) longcountTotalBuilds(long fromMs, long toMs, String jobPattern, Set<String> excludedJobs) longcountTotalBuilds(long fromMs, long toMs, String jobPattern, Set<String> excludedJobs, String branchPattern) As above, counting only builds on a branch matchingbranchPattern, or all when it is null.voiddetachDeletedJob(String fullName, long deletedAtMs) Detaches the records of a deleted job, and of everything below it when it was a folder, from the job name.failureStreaksOpenAt(long beforeMs, Set<String> excludedJobs, String branchPattern) For every job whose failures had not been fixed yet atbeforeMs, when its run of failures began: the earliest FAILURE after that job's last SUCCESS before that moment.getAllBuilds(long fromTimestamp, long toTimestamp) getAllBuilds(long fromTimestamp, long toTimestamp, Set<String> excludedJobs) All builds in the window, leaving out the given job names.getBuildsFinishedBetween(long afterMs, long untilMs, Set<String> excludedJobs) Builds that finished afterafterMsand no later thanuntilMs, leaving out the given job names.longgetEarliestCommitTimestamp(long buildId) static MetricsStoregetJobStats(long fromMs, long toMs, int limit, String orderBy) getJobStats(long fromMs, long toMs, int limit, String orderBy, Set<String> excludedJobs) getStages(long buildId) getStagesByBuild(Collection<Long> buildIds) The stages of many builds at once, keyed by build id, each list in recorded order.getStageStats(long fromMs, long toMs, int limit, String orderBy) getStageStats(long fromMs, long toMs, int limit, String orderBy, Set<String> excludedJobs) longinsertBuild(String jobName, int buildNumber, long timestamp, long durationMs, String result, String triggerType, String branch) Upserts the build row and clears the stages and commits recorded against it, returning its id so they can be written back.voidinsertCommit(long buildId, String sha, String author, long timestamp) voidinsertStage(long buildId, String stageName, long durationMs, String result) static booleanisOnBranch(MetricsStore.BuildRecord build, String branchPattern) Whether a build's branch passes the same test asbranchCondition(java.lang.String, java.lang.String), for the metrics that are worked out row by row.List<long[]> leadTimes(long fromMs, long toMs, String jobPattern, Set<String> excludedJobs, String branchPattern) The lead time of each successful build in the window, as[build start, lead time], worked out asavgLeadTimeMs(long, long, String, Set, String)describes.longrecordBuild(String jobName, int buildNumber, long timestamp, long durationMs, String result, String triggerType, String branch, List<MetricsStore.StageRow> stages, List<MetricsStore.CommitRow> commits) Writes one build and the stages and commits belonging to it, in a single transaction.voidMoves a job's records to its new name.static voidsetInstance(MetricsStore store) Reset singleton.
-
Field Details
-
DELETED_MARKER
Marks records of a deleted job. '@' is not allowed in a Jenkins item name.- See Also:
-
-
Method Details
-
getInstance
-
setInstance
Reset singleton. Used by tests to reinitialize with fresh Jenkins home. -
recordBuild
public long recordBuild(String jobName, int buildNumber, long timestamp, long durationMs, String result, String triggerType, String branch, List<MetricsStore.StageRow> stages, List<MetricsStore.CommitRow> commits) Writes one build and the stages and commits belonging to it, in a single transaction.The build row is upserted rather than replaced. INSERT OR REPLACE deletes the conflicting row and inserts a new one, which hands out a new id, and since the foreign keys on stages and commits are not enforced their old rows are left pointing at an id that no longer exists. Nothing deletes those afterwards, including retention, which looks its children up through their parent. Keeping the id and replacing the children explicitly is what stops them accumulating.
The id comes from RETURNING because getGeneratedKeys reports 0 after an upsert that updates rather than inserts.
- Returns:
- the build's id, or -1 if nothing was written
-
insertBuild
public long insertBuild(String jobName, int buildNumber, long timestamp, long durationMs, String result, String triggerType, String branch) Upserts the build row and clears the stages and commits recorded against it, returning its id so they can be written back.Prefer
recordBuild(java.lang.String, int, long, long, java.lang.String, java.lang.String, java.lang.String, java.util.List<io.jenkins.plugins.dorametrics.store.MetricsStore.StageRow>, java.util.List<io.jenkins.plugins.dorametrics.store.MetricsStore.CommitRow>)where the stages and commits are already known: it writes all three in one transaction, so the build is never briefly left without them.- Returns:
- the build's id, or -1 if nothing was written
-
insertStage
-
insertCommit
-
getBuilds
public List<MetricsStore.BuildRecord> getBuilds(String jobName, long fromTimestamp, long toTimestamp) -
getAllBuilds
-
getAllBuilds
public List<MetricsStore.BuildRecord> getAllBuilds(long fromTimestamp, long toTimestamp, Set<String> excludedJobs) All builds in the window, leaving out the given job names. -
failureStreaksOpenAt
public Map<String,Long> failureStreaksOpenAt(long beforeMs, Set<String> excludedJobs, String branchPattern) For every job whose failures had not been fixed yet atbeforeMs, when its run of failures began: the earliest FAILURE after that job's last SUCCESS before that moment. Lets a recovery inside a window be measured from a failure that started before it. -
getBuildsFinishedBetween
public List<MetricsStore.BuildRecord> getBuildsFinishedBetween(long afterMs, long untilMs, Set<String> excludedJobs) Builds that finished afterafterMsand no later thanuntilMs, leaving out the given job names. A build is stored when it finishes, so this is what an export that ran atafterMscould not have seen yet, however long before that the build started. -
getAllJobNames
-
getEarliestCommitTimestamp
public long getEarliestCommitTimestamp(long buildId) -
getStages
-
getStagesByBuild
The stages of many builds at once, keyed by build id, each list in recorded order. One query per few hundred builds instead of one per build, which is what made exporting a month of history slow. -
countSuccessfulBuilds
-
countSuccessfulBuilds
-
countSuccessfulBuilds
public long countSuccessfulBuilds(long fromMs, long toMs, String jobPattern, Set<String> excludedJobs, String branchPattern) As above, counting only builds on a branch matchingbranchPattern, or all when it is null. -
countTotalBuilds
-
countTotalBuilds
-
countTotalBuilds
public long countTotalBuilds(long fromMs, long toMs, String jobPattern, Set<String> excludedJobs, String branchPattern) As above, counting only builds on a branch matchingbranchPattern, or all when it is null. -
countDeployments
public long countDeployments(long fromMs, long toMs, String jobPattern, Set<String> excludedJobs, String branchPattern) Builds that ran as a deployment, successfully or not: SUCCESS, UNSTABLE or FAILURE. An aborted build, one that was never built, or one with no result deployed nothing. -
countFailedBuilds
-
countFailedBuilds
-
countFailedBuilds
public long countFailedBuilds(long fromMs, long toMs, String jobPattern, Set<String> excludedJobs, String branchPattern) As above, counting only builds on a branch matchingbranchPattern, or all when it is null. -
avgLeadTimeMs
-
avgLeadTimeMs
-
avgLeadTimeMs
public double avgLeadTimeMs(long fromMs, long toMs, String jobPattern, Set<String> excludedJobs, String branchPattern) Average lead time of the successful builds in the window, as the time from the earliest commit that build deployed until it finished. A changelog only lists what changed since the build before, so a commit first built by a build that failed or was aborted is in that build's changelog, not in the deploying one's. Every build since the job's previous success therefore counts toward the next success. Only builds on a production branch take part whenbranchPatternis set. -
leadTimes
public List<long[]> leadTimes(long fromMs, long toMs, String jobPattern, Set<String> excludedJobs, String branchPattern) The lead time of each successful build in the window, as[build start, lead time], worked out asavgLeadTimeMs(long, long, String, Set, String)describes. -
getJobStats
-
getJobStats
public List<MetricsStore.JobStats> getJobStats(long fromMs, long toMs, int limit, String orderBy, Set<String> excludedJobs) -
getStageStats
public List<MetricsStore.StageStats> getStageStats(long fromMs, long toMs, int limit, String orderBy) -
getStageStats
public List<MetricsStore.StageStats> getStageStats(long fromMs, long toMs, int limit, String orderBy, Set<String> excludedJobs) -
isOnBranch
Whether a build's branch passes the same test asbranchCondition(java.lang.String, java.lang.String), for the metrics that are worked out row by row. -
renameJob
Moves a job's records to its new name. Rows already stored under the new name belong to a job that is gone, since the name was free until now, so they are detached first, in the same transaction, instead of being merged into this job's history or making the rename fail on the unique key. -
detachDeletedJob
Detaches the records of a deleted job, and of everything below it when it was a folder, from the job name. The history stays in the totals that administrators and the scheduled export see, but a new job created under the same name starts empty instead of inheriting it. -
cleanup
public void cleanup(long retainAfterTimestamp)
-