Merge "Fix zoned executor metric when unzoned is allowed"

This commit is contained in:
Zuul 2022-08-15 22:59:09 +00:00 committed by Gerrit Code Review
commit afebbb6a6c
3 changed files with 18 additions and 2 deletions

View File

@ -226,6 +226,18 @@ class TestSchedulerZoneFallback(ZuulTestCase):
def test_jobs_executed(self):
"Test that jobs are executed and a change is merged per zone"
self.hold_jobs_in_queue = True
# Validate that the reported executor stats are correct. Since
# the executor accepts zoned and unzoned job it should be counted
# in both metrics.
self.assertReportedStat(
'zuul.executors.online', value='1', kind='g')
self.assertReportedStat(
'zuul.executors.unzoned.online', value='1', kind='g')
self.assertReportedStat(
'zuul.executors.zone.test-provider_vpn.online',
value='1', kind='g')
A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
A.addApproval('Code-Review', 2)
self.fake_gerrit.addEvent(A.addApproval('Approved', 1))

View File

@ -3157,6 +3157,10 @@ class ExecutorServer(BaseMergeServer):
self.allow_unzoned = get_default(self.config, 'executor',
'allow_unzoned', False)
# If this executor has no zone configured it is implicitly unzoned
if self.zone is None:
self.allow_unzoned = True
# Those attributes won't change, so it's enough to set them once on the
# component info.
self.component_info.zone = self.zone

View File

@ -438,12 +438,12 @@ class Scheduler(threading.Thread):
mergers_online = 0
for executor_component in self.component_registry.all("executor"):
if executor_component.allow_unzoned or not executor_component.zone:
if executor_component.allow_unzoned:
if executor_component.state == BaseComponent.RUNNING:
executors_unzoned_online += 1
if executor_component.accepting_work:
executors_unzoned_accepting += 1
else:
if executor_component.zone:
zone_stats = zoned_executor_stats.setdefault(
executor_component.zone,
executor_stats_default.copy())