Make the cut off point for combining build reports customizable.

Signed-off-by: magic_rb <richard@brezak.sk>
This commit is contained in:
magic_rb 2024-07-12 16:44:02 +02:00
parent dd2df67009
commit 28b6da6e73
Failed to generate hash of commit
3 changed files with 45 additions and 16 deletions

View file

@ -165,7 +165,11 @@ class NixEvalCommand(buildstep.ShellMixin, steps.BuildStep):
project: GitProject project: GitProject
def __init__( def __init__(
self, project: GitProject, supported_systems: list[str], **kwargs: Any self,
project: GitProject,
supported_systems: list[str],
job_report_limit: int | None,
**kwargs: Any,
) -> None: ) -> None:
kwargs = self.setupShellMixin(kwargs) kwargs = self.setupShellMixin(kwargs)
super().__init__(**kwargs) super().__init__(**kwargs)
@ -173,6 +177,7 @@ class NixEvalCommand(buildstep.ShellMixin, steps.BuildStep):
self.observer = logobserver.BufferLogObserver() self.observer = logobserver.BufferLogObserver()
self.addLogObserver("stdio", self.observer) self.addLogObserver("stdio", self.observer)
self.supported_systems = supported_systems self.supported_systems = supported_systems
self.job_report_limit = job_report_limit
@defer.inlineCallbacks @defer.inlineCallbacks
def run(self) -> Generator[Any, object, Any]: def run(self) -> Generator[Any, object, Any]:
@ -205,17 +210,21 @@ class NixEvalCommand(buildstep.ShellMixin, steps.BuildStep):
self.number_of_jobs = len(filtered_jobs) self.number_of_jobs = len(filtered_jobs)
self.build.addStepsAfterCurrentStep( self.build.addStepsAfterCurrentStep(
[ # noqa: RUF005 [
BuildTrigger( BuildTrigger(
self.project, self.project,
builds_scheduler=f"{project_id}-nix-build", builds_scheduler=f"{project_id}-nix-build",
skipped_builds_scheduler=f"{project_id}-nix-skipped-build", skipped_builds_scheduler=f"{project_id}-nix-skipped-build",
name="build flake", name="build flake",
jobs=filtered_jobs, jobs=filtered_jobs,
report_status=(self.number_of_jobs <= 2), report_status=(
self.job_report_limit is None
or self.number_of_jobs <= self.job_report_limit
),
), ),
] ]
+ [ + (
[
Trigger( Trigger(
waitForFinish=True, waitForFinish=True,
schedulerNames=[f"{project_id}-nix-build-combined"], schedulerNames=[f"{project_id}-nix-build-combined"],
@ -226,8 +235,10 @@ class NixEvalCommand(buildstep.ShellMixin, steps.BuildStep):
updateSourceStamp=False, updateSourceStamp=False,
), ),
] ]
if self.number_of_jobs > 2 if self.job_report_limit is not None
else [], and self.number_of_jobs > self.job_report_limit
else []
),
) )
return result return result
@ -388,6 +399,7 @@ def nix_eval_config(
eval_lock: MasterLock, eval_lock: MasterLock,
worker_count: int, worker_count: int,
max_memory_size: int, max_memory_size: int,
job_report_limit: int | None,
) -> BuilderConfig: ) -> BuilderConfig:
"""Uses nix-eval-jobs to evaluate hydraJobs from flake.nix in parallel. """Uses nix-eval-jobs to evaluate hydraJobs from flake.nix in parallel.
For each evaluated attribute a new build pipeline is started. For each evaluated attribute a new build pipeline is started.
@ -413,6 +425,7 @@ def nix_eval_config(
env={}, env={},
name="evaluate flake", name="evaluate flake",
supported_systems=supported_systems, supported_systems=supported_systems,
job_report_limit=job_report_limit,
command=[ command=[
"nix-eval-jobs", "nix-eval-jobs",
"--workers", "--workers",
@ -655,6 +668,7 @@ def config_for_project(
nix_eval_max_memory_size: int, nix_eval_max_memory_size: int,
eval_lock: MasterLock, eval_lock: MasterLock,
post_build_steps: list[steps.BuildStep], post_build_steps: list[steps.BuildStep],
job_report_limit: int | None,
outputs_path: Path | None = None, outputs_path: Path | None = None,
build_retries: int = 1, build_retries: int = 1,
) -> None: ) -> None:
@ -730,6 +744,7 @@ def config_for_project(
worker_names, worker_names,
git_url=project.get_project_url(), git_url=project.get_project_url(),
supported_systems=nix_supported_systems, supported_systems=nix_supported_systems,
job_report_limit=job_report_limit,
worker_count=nix_eval_worker_count, worker_count=nix_eval_worker_count,
max_memory_size=nix_eval_max_memory_size, max_memory_size=nix_eval_max_memory_size,
eval_lock=eval_lock, eval_lock=eval_lock,
@ -946,6 +961,7 @@ class NixConfigurator(ConfiguratorBase):
self.config.eval_max_memory_size, self.config.eval_max_memory_size,
eval_lock, eval_lock,
[x.to_buildstep() for x in self.config.post_build_steps], [x.to_buildstep() for x in self.config.post_build_steps],
self.config.job_report_limit,
self.config.outputs_path, self.config.outputs_path,
self.config.build_retries, self.config.build_retries,
) )

View file

@ -179,6 +179,7 @@ class BuildbotNixConfig(BaseModel):
outputs_path: Path | None outputs_path: Path | None
url: str url: str
post_build_steps: list[PostBuildStep] post_build_steps: list[PostBuildStep]
job_report_limit: int | None
@property @property
def nix_workers_secret(self) -> str: def nix_workers_secret(self) -> str:

View file

@ -338,6 +338,17 @@ in
default = null; default = null;
example = "/var/www/buildbot/nix-outputs"; example = "/var/www/buildbot/nix-outputs";
}; };
jobReportLimit = lib.mkOption {
type = lib.types.nullOr lib.types.ints.positive;
description = ''
The max number of build jobs per `nix-eval` `buildbot-nix` will report to backends (GitHub, Gitea, etc.).
If set to `null`, report everything, if set to `n` (some positive intereger), report builds individually
as long as the number of builds is less than or equal to `n`, then report builds using a combined
`nix-build-combined` build.
'';
default = 50;
};
}; };
}; };
config = lib.mkMerge [ config = lib.mkMerge [
@ -469,6 +480,7 @@ in
outputs_path = cfg.outputsPath; outputs_path = cfg.outputsPath;
url = config.services.buildbot-nix.master.webhookBaseUrl; url = config.services.buildbot-nix.master.webhookBaseUrl;
post_build_steps = cfg.postBuildSteps; post_build_steps = cfg.postBuildSteps;
job_report_limit=if cfg.jobReportLimit == null then "None" else builtins.toJSON cfg.jobReportLimit;
}}").read_text())) }}").read_text()))
) )
'' ''