blob: 928365c32e027707599ca7ef9989201bac7dbbc7 [file] [log] [blame]
Will Bradley88b1ffc2019-08-19 15:09:39 -06001# -*- coding: utf-8 -*-
2# Copyright 2019 The Chromium OS Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6"""The build API Metrics Emit entry point."""
7
8from __future__ import print_function
9
10from chromite.lib import commandline
11from chromite.utils import metrics
12
13
14def main(argv):
15 """Emit a metric event."""
16 parser = commandline.ArgumentParser(description=__doc__)
Will Bradley333d22c2019-09-11 15:04:59 -060017 parser.add_argument('op', choices=sorted(metrics.VALID_OPS),
Will Bradley88b1ffc2019-08-19 15:09:39 -060018 help='Which metric event operator to emit.')
19 parser.add_argument('name',
20 help='The name of the metric event as you would like it '
21 'to appear downstream in data stores.')
Will Bradley333d22c2019-09-11 15:04:59 -060022 parser.add_argument('arg', nargs='?',
23 help='An accessory argument dependent upon the "op".')
Will Bradley88b1ffc2019-08-19 15:09:39 -060024 opts = parser.parse_args(argv)
25
Will Bradley333d22c2019-09-11 15:04:59 -060026 if opts.arg and not metrics.OP_EXPECTS_ARG[opts.op]:
27 # We do not expect to get an |arg| for this |op|.
28 parser.error('Unexpected arg "%s" given for op "%s"' % (opts.arg,
29 opts.op))
30
Will Bradley88b1ffc2019-08-19 15:09:39 -060031 timestamp = metrics.current_milli_time()
Will Bradley333d22c2019-09-11 15:04:59 -060032 metrics.append_metrics_log(timestamp, opts.name, opts.op, arg=opts.arg)