Telemetry: add bot opt-in support

This adds a new option to bypass the googler check for bots which
might have unexpected hostnames

Bug: 326277821
Change-Id: I56aa2e60d9a7a91ba0b8c8202e659d5b35076c52
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6622310
Reviewed-by: Ben Pastene <bpastene@chromium.org>
Commit-Queue: Struan Shrimpton <sshrimp@google.com>
changes/10/6622310/17
Struan Shrimpton 2 weeks ago committed by LUCI CQ
parent dcbf502f02
commit 2ac2988f7b

@ -72,13 +72,15 @@ def initialize(service_name,
if not sys.platform.startswith('linux'):
return
if not is_google_host():
return
cfg = config.Config(cfg_file)
if cfg.trace_config.disabled():
return
bot_enabled = (cfg.trace_config.has_enabled()
and cfg.trace_config.enabled_reason == 'BOT_USER')
if not is_google_host() and not bot_enabled:
return
if not cfg.trace_config.has_enabled():
if cfg.root_config.notice_countdown > -1:
print(notice.format(run_count=cfg.root_config.notice_countdown,

@ -26,14 +26,26 @@ def main():
default=None,
help='Enable telemetry collection.')
parser.add_argument('--bot-enable',
'-b',
dest='bot_enable',
action='store_true',
default=False,
help='Enable for bots. Ignores googler check. '
'Not for human users.')
args = parser.parse_args()
if args.enable is not None:
cfg = config.Config(config.DEFAULT_CONFIG_FILE)
cfg.trace_config.update(args.enable, 'USER')
cfg.flush()
elif args.bot_enable:
cfg = config.Config(config.DEFAULT_CONFIG_FILE)
cfg.trace_config.update(args.bot_enable, 'BOT_USER')
cfg.flush()
else:
print('Error: --enable or --disable flag is required.')
print('Error: --enable --disable or --bot-enable flag is required.')
if __name__ == '__main__':

@ -45,7 +45,8 @@ class TraceConfig:
if not self.has_enabled() or self.enabled:
self.gen_id()
def update(self, enabled: bool, reason: Literal["AUTO", "USER"]) -> None:
def update(self, enabled: bool, reason: Literal["AUTO", "USER",
"BOT_USER"]) -> None:
"""Update the config."""
self._config[TRACE_SECTION_KEY][ENABLED_KEY] = str(enabled)
self._config[TRACE_SECTION_KEY][ENABLED_REASON_KEY] = reason
@ -100,7 +101,7 @@ class TraceConfig:
return self._config[TRACE_SECTION_KEY].getboolean(ENABLED_KEY, False)
@property
def enabled_reason(self) -> Literal["AUTO", "USER"]:
def enabled_reason(self) -> Literal["AUTO", "USER", "BOT_USER"]:
"""Value of trace.enabled_reason property in telemetry.cfg."""
return self._config[TRACE_SECTION_KEY].get(ENABLED_REASON_KEY, "AUTO")

Loading…
Cancel
Save