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

Side by Side Diff: appengine/gce-backend/instances.py

Issue 2520873003: Count instances managed by each instance template (Closed)
Patch Set: Replace old metric with new Created 4 years 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 unified diff | Download patch
« no previous file with comments | « appengine/gce-backend/instance_group_managers.py ('k') | appengine/gce-backend/metrics.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2016 The LUCI Authors. All rights reserved. 1 # Copyright 2016 The LUCI Authors. All rights reserved.
2 # Use of this source code is governed under the Apache License, Version 2.0 2 # Use of this source code is governed under the Apache License, Version 2.0
3 # that can be found in the LICENSE file. 3 # that can be found in the LICENSE file.
4 4
5 """Utilities for operating on instances.""" 5 """Utilities for operating on instances."""
6 6
7 import json 7 import json
8 import logging 8 import logging
9 9
10 from google.appengine.ext import ndb 10 from google.appengine.ext import ndb
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 if instance and not instance.cataloged: 369 if instance and not instance.cataloged:
370 if not utils.enqueue_task( 370 if not utils.enqueue_task(
371 '/internal/queues/delete-drained-instance', 371 '/internal/queues/delete-drained-instance',
372 'delete-drained-instance', 372 'delete-drained-instance',
373 params={ 373 params={
374 'key': instance.key.urlsafe(), 374 'key': instance.key.urlsafe(),
375 }, 375 },
376 ): 376 ):
377 logging.warning( 377 logging.warning(
378 'Failed to enqueue task for Instance: %s', instance.key) 378 'Failed to enqueue task for Instance: %s', instance.key)
379
380
381 def count_instances():
382 """Counts the number of Instance entities in the datastore.
383
384 Returns:
385 A 2-tuple of (orphaned, total).
386 Orphaned instances are instances no longer referred to by their parent.
387 """
388 total = 0
389 orphaned = 0
390 for instance in models.Instance.query():
391 total += 1
392 instance_group_manager = instance.instance_group_manager.get()
393 if (not instance_group_manager
394 or instance.key not in instance_group_manager.instances):
395 logging.warning('Found orphaned Instance: %s', instance.key)
396 orphaned += 1
397 logging.info('Orphaned Instances: %s/%s', orphaned, total)
398 return orphaned, total
OLDNEW
« no previous file with comments | « appengine/gce-backend/instance_group_managers.py ('k') | appengine/gce-backend/metrics.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698