telemetry: Collect until opt-out

The pdd says we will collect by default:
https://eldar.corp.google.com/assessments/570486509/revisions/1/sections/550004#questions/550404/revisions/2

Also reduce the notice count to 9 since it notices on "0 remaining"

Bug: 326277821
Change-Id: I4de584c36868b45cefaa5cea42f88d245485dce7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6616983
Reviewed-by: Ben Pastene <bpastene@chromium.org>
Commit-Queue: Struan Shrimpton <sshrimp@google.com>
changes/83/6616983/5
Struan Shrimpton 2 months ago committed by LUCI CQ
parent bb7719c346
commit 9c11bcef1f

@ -76,6 +76,8 @@ def initialize(service_name,
return return
cfg = config.Config(cfg_file) cfg = config.Config(cfg_file)
if cfg.disabled():
return
if not cfg.trace_config.has_enabled(): if not cfg.trace_config.has_enabled():
if cfg.root_config.notice_countdown > -1: if cfg.root_config.notice_countdown > -1:
@ -89,9 +91,6 @@ def initialize(service_name,
cfg.flush() cfg.flush()
if not cfg.trace_config.enabled:
return
default_resource = otel_resources.Resource.create({ default_resource = otel_resources.Resource.create({
otel_resources.SERVICE_NAME: otel_resources.SERVICE_NAME:
service_name, service_name,

@ -23,7 +23,7 @@ ENABLED_REASON_KEY = "enabled_reason"
TRACE_SECTION_KEY = "trace" TRACE_SECTION_KEY = "trace"
DEFAULT_CONFIG = { DEFAULT_CONFIG = {
ROOT_SECTION_KEY: { ROOT_SECTION_KEY: {
NOTICE_COUNTDOWN_KEY: 10 NOTICE_COUNTDOWN_KEY: 9
}, },
TRACE_SECTION_KEY: {}, TRACE_SECTION_KEY: {},
} }
@ -42,12 +42,13 @@ class TraceConfig:
def __init__(self, config: configparser.ConfigParser) -> None: def __init__(self, config: configparser.ConfigParser) -> None:
self._config = config self._config = config
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"]) -> None:
"""Update the config.""" """Update the config."""
self._config[TRACE_SECTION_KEY][ENABLED_KEY] = str(enabled) self._config[TRACE_SECTION_KEY][ENABLED_KEY] = str(enabled)
self._config[TRACE_SECTION_KEY][ENABLED_REASON_KEY] = reason self._config[TRACE_SECTION_KEY][ENABLED_REASON_KEY] = reason
if enabled:
self.gen_id()
def gen_id(self, regen=False) -> None: def gen_id(self, regen=False) -> None:
"""[Re]generate UUIDs.""" """[Re]generate UUIDs."""
@ -89,6 +90,10 @@ class TraceConfig:
"""Checks if the enabled property exists in config.""" """Checks if the enabled property exists in config."""
return ENABLED_KEY in self._config[TRACE_SECTION_KEY] return ENABLED_KEY in self._config[TRACE_SECTION_KEY]
def disabled(self) -> bool:
"""Checks if the enabled probperty exists and is false"""
return self.trace_config.has_enabled() and not self.trace_config.enabled
@property @property
def enabled(self) -> bool: def enabled(self) -> bool:
"""Value of trace.enabled property in telemetry.cfg.""" """Value of trace.enabled property in telemetry.cfg."""
@ -131,8 +136,7 @@ class RootConfig:
@property @property
def notice_countdown(self) -> int: def notice_countdown(self) -> int:
"""Value for root.notice_countdown property in telemetry.cfg.""" """Value for root.notice_countdown property in telemetry.cfg."""
return self._config[ROOT_SECTION_KEY].getint(NOTICE_COUNTDOWN_KEY, 9)
return self._config[ROOT_SECTION_KEY].getint(NOTICE_COUNTDOWN_KEY, 10)
class Config: class Config:

@ -21,12 +21,12 @@ class ConfigTest(unittest.TestCase):
cfg = config.Config(path) cfg = config.Config(path)
with open(path, 'r') as f: with open(path, 'r') as f:
self.assertEqual( self.assertEqual(f.read(),
f.read(), "[root]\nnotice_countdown = 10\n\n[trace]\n\n") "[root]\nnotice_countdown = 9\n\n[trace]\n\n")
self.assertFalse(cfg.trace_config.enabled) self.assertFalse(cfg.trace_config.enabled)
self.assertFalse(cfg.trace_config.has_enabled()) self.assertFalse(cfg.trace_config.has_enabled())
self.assertEqual("AUTO", cfg.trace_config.enabled_reason) self.assertEqual("AUTO", cfg.trace_config.enabled_reason)
self.assertEqual(10, cfg.root_config.notice_countdown) self.assertEqual(9, cfg.root_config.notice_countdown)
def test_load_config_file(self) -> None: def test_load_config_file(self) -> None:
"""Test Config to load config file.""" """Test Config to load config file."""
@ -60,19 +60,17 @@ class ConfigTest(unittest.TestCase):
cfg.flush() cfg.flush()
with open(path, 'r') as f: with open(path, 'r') as f:
self.assertEqual( file = f.read()
f.read(), self.assertIn(
"\n".join([ "\n".join([
"[root]", "[root]",
"notice_countdown = 9", "notice_countdown = 9",
"",
"[trace]",
"enabled = False",
"enabled_reason = AUTO",
"",
"",
]), ]),
file,
) )
self.assertIn("[trace]", file)
self.assertIn("enabled = False", file)
self.assertIn("enabled_reason = AUTO", file)
def test_default_trace_config() -> None: def test_default_trace_config() -> None:
@ -111,7 +109,7 @@ def test_default_root_config() -> None:
cfg[config.ROOT_SECTION_KEY] = {} cfg[config.ROOT_SECTION_KEY] = {}
root_config = config.RootConfig(cfg) root_config = config.RootConfig(cfg)
assert root_config.notice_countdown == 10 assert root_config.notice_countdown == 9
def test_root_config_update() -> None: def test_root_config_update() -> None:

Loading…
Cancel
Save