Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2561)

Unified Diff: appengine/swarming/handlers_backend.py

Issue 2212073002: Add endpoint and cron job to aggregate all dimensions and values (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-py@master
Patch Set: trying things Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « appengine/swarming/cron.yaml ('k') | appengine/swarming/handlers_endpoints.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: appengine/swarming/handlers_backend.py
diff --git a/appengine/swarming/handlers_backend.py b/appengine/swarming/handlers_backend.py
index bbcdc6bc90678b32459613a04a3983d496827665..6e80a602e3803e0079469a22c0bc39235ed00ff7 100644
--- a/appengine/swarming/handlers_backend.py
+++ b/appengine/swarming/handlers_backend.py
@@ -12,9 +12,12 @@ from google.appengine.api import app_identity
from google.appengine.api import datastore_errors
from google.appengine.api import taskqueue
+from components import utils
+
import mapreduce_jobs
from components import decorators
from components import machine_provider
+from server import bot_management
from server import config
from server import lease_management
from server import stats
@@ -97,6 +100,30 @@ class CronMachineProviderCleanUpHandler(webapp2.RequestHandler):
lease_management.clean_up_bots()
+class CronBotsDimensionAggregationHandler(webapp2.RequestHandler):
+ """Aggregates all bots dimensions (except id) in the fleet."""
+
+ @decorators.require_cronjob
+ def get(self):
+ seen = {}
+ now = utils.utcnow()
+ for b in bot_management.BotInfo.query():
+ for i in b.dimensions_flat:
+ k, v = i.split(':', 1)
+ if k != 'id':
+ seen.setdefault(k, set()).add(v)
+ dims = []
+ for k, values in sorted(seen.iteritems()):
M-A Ruel 2016/08/05 17:09:20 you can use a list comprehension here too.
kjlubick 2016/08/05 17:38:58 Done.
+ dims.append(bot_management.DimensionValues(
+ dimension=k,
+ values=sorted(list(values))))
M-A Ruel 2016/08/05 17:09:20 don't call list(), no need to rasterise the genera
kjlubick 2016/08/05 17:38:58 Done.
+ logging.info('Saw dimensions %s', dims)
+ aggregate = bot_management.DimensionAggregation.KEY.get()
M-A Ruel 2016/08/05 17:09:20 no need to get it, just write a new one
kjlubick 2016/08/05 17:38:58 Done.
+ aggregate.dimensions = dims
+ aggregate.ts = now
+ aggregate.put()
+
+
class CronMachineProviderPubSubHandler(webapp2.RequestHandler):
"""Listens for Pub/Sub communication from Machine Provider."""
@@ -170,6 +197,8 @@ def get_routes():
('/internal/cron/stats/update', stats.InternalStatsUpdateHandler),
('/internal/cron/trigger_cleanup_data', CronTriggerCleanupDataHandler),
+ ('/internal/cron/aggregate_bots_dimensions',
+ CronBotsDimensionAggregationHandler),
('/internal/cron/machine_provider', CronMachineProviderBotHandler),
('/internal/cron/machine_provider_cleanup',
CronMachineProviderCleanUpHandler),
« no previous file with comments | « appengine/swarming/cron.yaml ('k') | appengine/swarming/handlers_endpoints.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698