mirror of
https://github.com/renovatebot/renovate.git
synced 2026-11-08 04:53:36 +00:00
e34af57483
As part of future changes to add an OpenTelemetry attribute for the splits, we should make sure that we have a common type for the splits, which can be used with `addSplit`. This refactors - with some help from GPT-4.1 - to use Vitest's timer mocking. This also requires a slight refactor of the implementation to test more appropriately, without duplicate calls to `Date.now`. Co-authored-by: gpt-4.1 <jamie.tanna+github-copilot@mend.io>
34 lines
618 B
TypeScript
34 lines
618 B
TypeScript
import type { RenovateSplit } from '../config/types';
|
|
|
|
let startTime = 0;
|
|
let lastTime = 0;
|
|
let splits: Record<RenovateSplit, number> = {
|
|
init: 0,
|
|
onboarding: 0,
|
|
extract: 0,
|
|
lookup: 0,
|
|
update: 0,
|
|
};
|
|
|
|
export function splitInit(): void {
|
|
splits = {
|
|
init: 0,
|
|
onboarding: 0,
|
|
extract: 0,
|
|
lookup: 0,
|
|
update: 0,
|
|
};
|
|
startTime = Date.now();
|
|
lastTime = startTime;
|
|
}
|
|
|
|
export function addSplit(name: RenovateSplit): void {
|
|
const now = Date.now();
|
|
splits[name] = now - lastTime;
|
|
lastTime = now;
|
|
}
|
|
|
|
export function getSplits(): any {
|
|
return { splits, total: Date.now() - startTime };
|
|
}
|