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

Unified Diff: appengine/swarming/handlers_endpoints.py

Issue 2198063002: Add bots.count endpoint (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-py@master
Patch Set: Address nits Created 4 years, 5 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 | « no previous file | appengine/swarming/handlers_endpoints_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: appengine/swarming/handlers_endpoints.py
diff --git a/appengine/swarming/handlers_endpoints.py b/appengine/swarming/handlers_endpoints.py
index ef39512802e46fa7c7c6bc8ed55934f9f246d0d0..0b353a30c5ba9424b2e5d0cd2883816d5b25c396 100644
--- a/appengine/swarming/handlers_endpoints.py
+++ b/appengine/swarming/handlers_endpoints.py
@@ -635,6 +635,36 @@ class SwarmingBotsService(remote.Service):
items=[message_conversion.bot_info_to_rpc(bot, now) for bot in bots],
now=now)
+ @gae_ts_mon.instrument_endpoint()
+ @auth.endpoints_method(
+ swarming_rpcs.BotsRequest, swarming_rpcs.BotsCount,
+ http_method='GET')
+ @auth.require(acl.is_privileged_user)
+ def count(self, request):
+ """Counts number of bots with given dimensions."""
+ logging.info('%s', request)
+ now = utils.utcnow()
+ q = bot_management.BotInfo.query().order()
+ for d in request.dimensions:
+ parts = d.split(':', 1)
+ if len(parts) != 2 or any(i.strip() != i or not i for i in parts):
+ raise endpoints.BadRequestException('Invalid dimensions: %s' % d)
+ q = q.filter(bot_management.BotInfo.dimensions_flat == d)
+ f_count = q.count_async()
+ dt = datetime.timedelta(seconds=config.settings().bot_death_timeout_secs)
+ timeout = now - dt
+ f_dead = q.filter(
+ bot_management.BotInfo.last_seen_ts < timeout).count_async()
+ f_quarantined = q.filter(
+ bot_management.BotInfo.quarantined == True).count_async()
+ f_busy = q.filter(bot_management.BotInfo.is_busy == True).count_async()
+ return swarming_rpcs.BotsCount(
+ count=f_count.get_result(),
+ quarantined=f_quarantined.get_result(),
+ dead=f_dead.get_result(),
+ busy=f_busy.get_result(),
+ now=now)
+
def get_routes():
return (
« no previous file with comments | « no previous file | appengine/swarming/handlers_endpoints_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698