Skip to content

Commit

Permalink
Add usage tracking project name (#3624)
Browse files Browse the repository at this point in the history
Add option to deanonymize usage tracking data by tagging it with a name using parsl.Config.project_name.
  • Loading branch information
NishchayKarle committed Sep 30, 2024
1 parent dd9150d commit 25374b1
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
5 changes: 5 additions & 0 deletions parsl/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ class Config(RepresentationMixin, UsageInformation):
Setting this field to 0 will disable usage tracking. Default (this field is not set): usage tracking is not enabled.
Parsl only collects minimal, non personally-identifiable,
information used for reporting to our funding agencies.
project_name: str, optional
Option to deanonymize usage tracking data.
If set, this value will be used as the project name in the usage tracking data and placed on the leaderboard.
initialize_logging : bool, optional
Make DFK optionally not initialize any logging. Log messages
will still be passed into the python logging system under the
Expand Down Expand Up @@ -118,6 +121,7 @@ def __init__(self,
max_idletime: float = 120.0,
monitoring: Optional[MonitoringHub] = None,
usage_tracking: int = 0,
project_name: Optional[str] = None,
initialize_logging: bool = True) -> None:

executors = tuple(executors or [])
Expand Down Expand Up @@ -154,6 +158,7 @@ def __init__(self,
self.max_idletime = max_idletime
self.validate_usage_tracking(usage_tracking)
self.usage_tracking = usage_tracking
self.project_name = project_name
self.initialize_logging = initialize_logging
self.monitoring = monitoring
self.std_autopath: Optional[Callable] = std_autopath
Expand Down
21 changes: 21 additions & 0 deletions parsl/tests/unit/test_usage_tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,24 @@ def test_invalid_types(level):
# we can't instantiate TypeCheckError if we're in typeguard 2.x environment
# because it does not exist... so check name using strings.
assert ex.type.__name__ in ["TypeCheckError", "TypeError"]


@pytest.mark.local
def test_valid_project_name():
"""Test valid project_name."""
assert (
Config(
usage_tracking=3,
project_name="unit-test",
).project_name == "unit-test"
)


@pytest.mark.local
@pytest.mark.parametrize("name", (1, 1.0, True, object()))
def test_invalid_project_name(name):
"""Test invalid project_name."""
with pytest.raises(Exception) as ex:
Config(usage_tracking=3, project_name=name)

assert ex.type.__name__ in ["TypeCheckError", "TypeError"]
8 changes: 8 additions & 0 deletions parsl/usage_tracking/usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def __init__(self, dfk, port=50077,
sys.version_info.minor,
sys.version_info.micro)
self.tracking_level = self.check_tracking_level()
self.project_name = self.config.project_name
self.start_time = None
logger.debug("Tracking level: {}".format(self.tracking_level))

Expand Down Expand Up @@ -153,6 +154,9 @@ def construct_start_message(self) -> bytes:
'platform.system': platform.system(),
'tracking_level': int(self.tracking_level)}

if self.project_name:
message['project_name'] = self.project_name

if self.tracking_level >= 2:
message['components'] = get_parsl_usage(self.dfk._config)

Expand Down Expand Up @@ -188,6 +192,10 @@ def construct_end_message(self) -> bytes:
'end': end_time,
'execution_time': end_time - self.start_time,
'components': [dfk_component] + get_parsl_usage(self.dfk._config)}

if self.project_name:
message['project_name'] = self.project_name

logger.debug(f"Usage tracking end message (unencoded): {message}")

return self.encode_message(message)
Expand Down

0 comments on commit 25374b1

Please sign in to comment.