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

Side by Side Diff: infra_libs/experiments.py

Issue 1365583002: Have service_manager start a cloudtail attached to each service it starts. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Just use the default project ID Created 5 years, 3 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 unified diff | Download patch
OLDNEW
(Empty)
1 # Copyright 2015 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 """Tools for gradually enabling a feature on a deterministic set of machines.
6
7 Add a flag to your program to control the percentage of machines that a new
8 feature should be enabled on::
9
10 def add_argparse_options(self, parser):
11 parser.add_argument('--myfeature-percent', type=int, default=0)
12
13 def main(self, opts):
14 if experiments.is_active_for_host('myfeature', opts.myfeature_percent):
15 # do myfeature
16 """
17
18 import hashlib
19 import logging
20 import socket
21
22
23 def _is_active(labels, percent):
24 h = hashlib.md5()
25 for label, value in labels.iteritems():
Vadim Sh. 2015/09/23 17:40:22 sorted(labels.iteritems())
dsansome 2015/09/24 04:34:13 Done.
26 h.update(label)
27 h.update(value)
28
29 digest = h.digest()
30
31 print hash(digest) % 100
Vadim Sh. 2015/09/23 17:40:22 remove :)
dsansome 2015/09/24 04:34:13 Oops!
32 return (hash(digest) % 100) < percent
33
34
35 def is_active_for_host(experiment_name, percent):
36 ret = _is_active({
37 'name': experiment_name,
38 'host': socket.getfqdn(),
Vadim Sh. 2015/09/23 17:40:21 This thing can return nonsense (e.g. 1.1.1.1.1.1.a
dsansome 2015/09/24 04:34:13 Nonsense is fine - it's just being hashed anyway.
39 }, percent)
40
41 if ret:
42 logging.info('Experiment "%s" is active', experiment_name)
43
44 return ret
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698