blob: 7cf7171e76103a005395c7b0cd7f880e47bc5de0 [file] [log] [blame]
Will Bradley88b1ffc2019-08-19 15:09:39 -06001# Copyright 2019 The Chromium OS 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"""The build API Metrics Emit entry point."""
6
Will Bradley88b1ffc2019-08-19 15:09:39 -06007from chromite.lib import commandline
8from chromite.utils import metrics
9
10
11def main(argv):
12 """Emit a metric event."""
13 parser = commandline.ArgumentParser(description=__doc__)
Alex Klein8718c032022-04-19 14:06:03 -060014 parser.add_argument(
15 'op',
16 choices=sorted(metrics.VALID_OPS),
17 help='Which metric event operator to emit.')
18 parser.add_argument(
19 'name',
20 help='The name of the metric event as you would like it '
21 'to appear downstream in data stores.')
22 parser.add_argument(
23 'arg', nargs='?', 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|.
Alex Klein8718c032022-04-19 14:06:03 -060028 parser.error('Unexpected arg "%s" given for op "%s"' % (opts.arg, opts.op))
Will Bradley333d22c2019-09-11 15:04:59 -060029
Will Bradley88b1ffc2019-08-19 15:09:39 -060030 timestamp = metrics.current_milli_time()
Will Bradley333d22c2019-09-11 15:04:59 -060031 metrics.append_metrics_log(timestamp, opts.name, opts.op, arg=opts.arg)