Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MAINTENANCE] Add test to check for missing usage events #4933

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
469f622
Add event to schema "data_context.run_profiler_with_dynamic_arguments"
anthonyburdi Apr 21, 2022
e0b8b33
Add new events to schemas.py
anthonyburdi Apr 21, 2022
b357d2c
Make sure all events from schemas.py have examples in valid_message_list
anthonyburdi Apr 21, 2022
2b306dd
Make gather_source_files public for use elsewhere
anthonyburdi Apr 21, 2022
254282a
First pass at test_all_events_are_in_schema()
anthonyburdi Apr 21, 2022
663470b
Add new events
anthonyburdi Apr 22, 2022
0829b82
Add new events to tests
anthonyburdi Apr 22, 2022
a6dd6e9
Merge branch 'develop' into BUGFIX/none/GREAT-815/add_missing_event_t…
anthonyburdi Apr 22, 2022
74a3181
Merge branch 'develop' into MAINTENANCE/none/none/add_test_to_check_f…
anthonyburdi Apr 22, 2022
c96e418
Add new enum with all event names
anthonyburdi Apr 22, 2022
fa4eb05
Remove magic strings from calls to @usage_statistics_enabled_method
anthonyburdi Apr 22, 2022
07cf891
Remove magic strings from calls to send_usage_message()
anthonyburdi Apr 22, 2022
feb3414
Cleanup
anthonyburdi Apr 22, 2022
efce827
Cleanup
anthonyburdi Apr 22, 2022
b21ec38
Docstrings
anthonyburdi Apr 22, 2022
a36708f
Merge branch 'develop' into MAINTENANCE/none/none/add_test_to_check_f…
anthonyburdi Apr 22, 2022
3d12a18
Add test for "data_context.run_validation_operator", fix broken test
anthonyburdi Apr 22, 2022
3a1792c
Merge branch 'develop' into MAINTENANCE/none/none/add_test_to_check_f…
anthonyburdi Apr 22, 2022
7a3c3c9
Merge branch 'develop' into MAINTENANCE/none/none/add_test_to_check_f…
anthonyburdi Apr 22, 2022
48c6c4c
Merge branch 'develop' into MAINTENANCE/none/none/add_test_to_check_f…
anthonyburdi Apr 23, 2022
5f4c5d7
Merge branch 'develop' into MAINTENANCE/none/none/add_test_to_check_f…
anthonyburdi Apr 25, 2022
39cf6e2
Merge branch 'develop' into MAINTENANCE/none/none/add_test_to_check_f…
anthonyburdi Apr 25, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion great_expectations/checkpoint/checkpoint.py
Expand Up @@ -26,6 +26,7 @@
get_batch_request_as_dict,
)
from great_expectations.core.config_peer import ConfigOutputModes, ConfigPeer
from great_expectations.core.usage_statistics.events import UsageStatsEvents
from great_expectations.core.usage_statistics.usage_statistics import (
get_checkpoint_run_usage_statistics,
usage_statistics_enabled_method,
Expand Down Expand Up @@ -77,7 +78,7 @@ def __init__(
# recent"). Currently, environment variable substitution is the only processing applied to evaluation parameters,
# while run_name_template also undergoes strftime datetime substitution
@usage_statistics_enabled_method(
event_name="checkpoint.run",
event_name=UsageStatsEvents.CHECKPOINT_RUN.value,
args_payload_fn=get_checkpoint_run_usage_statistics,
)
def run(
Expand Down
14 changes: 11 additions & 3 deletions great_expectations/cli/checkpoint.py
Expand Up @@ -8,6 +8,7 @@
from great_expectations.checkpoint.types.checkpoint_result import CheckpointResult
from great_expectations.cli import toolkit
from great_expectations.cli.pretty_printing import cli_message, cli_message_list
from great_expectations.core.usage_statistics.events import UsageStatsEvents
from great_expectations.core.usage_statistics.util import send_usage_message
from great_expectations.data_context.util import file_relative_path
from great_expectations.exceptions import InvalidTopLevelConfigKeyError
Expand Down Expand Up @@ -67,13 +68,20 @@ def checkpoint(ctx):
"""
ctx.obj.data_context = ctx.obj.get_data_context_from_config_file()

usage_stats_prefix = f"cli.checkpoint.{ctx.invoked_subcommand}"
cli_event_noun: str = "checkpoint"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these nouns or objects also become enums? I'm okay with how they're currently laid out just thinking out loud

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably, but we may also be able to get these from the click library as well. Let's plan for a future refactor with that in mind.

(
begin_event_name,
end_event_name,
) = UsageStatsEvents.get_cli_begin_and_end_event_names(
noun=cli_event_noun,
verb=ctx.invoked_subcommand,
)
send_usage_message(
data_context=ctx.obj.data_context,
event=f"{usage_stats_prefix}.begin",
event=begin_event_name,
success=True,
)
ctx.obj.usage_event_end = f"{usage_stats_prefix}.end"
ctx.obj.usage_event_end = end_event_name


@checkpoint.command(name="new")
Expand Down
17 changes: 13 additions & 4 deletions great_expectations/cli/datasource.py
Expand Up @@ -10,6 +10,7 @@
from great_expectations.cli import toolkit
from great_expectations.cli.pretty_printing import cli_message, cli_message_dict
from great_expectations.cli.util import verify_library_dependent_modules
from great_expectations.core.usage_statistics.events import UsageStatsEvents
from great_expectations.core.usage_statistics.util import send_usage_message
from great_expectations.data_context.templates import YAMLToString
from great_expectations.datasource.types import DatasourceTypes
Expand Down Expand Up @@ -47,13 +48,21 @@ class SupportedDatabaseBackends(enum.Enum):
def datasource(ctx):
"""Datasource operations"""
ctx.obj.data_context = ctx.obj.get_data_context_from_config_file()
usage_stats_prefix = f"cli.datasource.{ctx.invoked_subcommand}"

cli_event_noun: str = "datasource"
(
begin_event_name,
end_event_name,
) = UsageStatsEvents.get_cli_begin_and_end_event_names(
noun=cli_event_noun,
verb=ctx.invoked_subcommand,
)
send_usage_message(
data_context=ctx.obj.data_context,
event=f"{usage_stats_prefix}.begin",
event=begin_event_name,
success=True,
)
ctx.obj.usage_event_end = f"{usage_stats_prefix}.end"
ctx.obj.usage_event_end = end_event_name


@datasource.command(name="new")
Expand Down Expand Up @@ -262,7 +271,7 @@ def get_notebook_renderer(self, context) -> DatasourceNewNotebookRenderer:
def send_backend_choice_usage_message(self, context: DataContext) -> None:
send_usage_message(
data_context=context,
event="cli.new_ds_choice",
event=UsageStatsEvents.CLI_NEW_DS_CHOICE.value,
event_payload={
"type": self.datasource_type.value,
**self.usage_stats_payload,
Expand Down
14 changes: 11 additions & 3 deletions great_expectations/cli/docs.py
Expand Up @@ -4,6 +4,7 @@
from great_expectations.cli import toolkit
from great_expectations.cli.build_docs import build_docs
from great_expectations.cli.pretty_printing import cli_message, cli_message_list
from great_expectations.core.usage_statistics.events import UsageStatsEvents
from great_expectations.core.usage_statistics.util import send_usage_message
from great_expectations.exceptions import DataContextError

Expand All @@ -14,13 +15,20 @@ def docs(ctx):
"""Data Docs operations"""
ctx.obj.data_context = ctx.obj.get_data_context_from_config_file()

usage_stats_prefix = f"cli.docs.{ctx.invoked_subcommand}"
cli_event_noun: str = "docs"
(
begin_event_name,
end_event_name,
) = UsageStatsEvents.get_cli_begin_and_end_event_names(
noun=cli_event_noun,
verb=ctx.invoked_subcommand,
)
send_usage_message(
data_context=ctx.obj.data_context,
event=f"{usage_stats_prefix}.begin",
event=begin_event_name,
success=True,
)
ctx.obj.usage_event_end = f"{usage_stats_prefix}.end"
ctx.obj.usage_event_end = end_event_name


@docs.command(name="build")
Expand Down
3 changes: 2 additions & 1 deletion great_expectations/cli/init.py
Expand Up @@ -19,6 +19,7 @@
SECTION_SEPARATOR,
)
from great_expectations.cli.pretty_printing import cli_message
from great_expectations.core.usage_statistics.events import UsageStatsEvents
from great_expectations.core.usage_statistics.util import send_usage_message
from great_expectations.exceptions import (
DataContextError,
Expand Down Expand Up @@ -104,7 +105,7 @@ def init(ctx, usage_stats):
)
send_usage_message(
data_context=context,
event="cli.init.create",
event=UsageStatsEvents.CLI_INIT_CREATE.value,
success=True,
)
except DataContextError as e:
Expand Down
3 changes: 2 additions & 1 deletion great_expectations/cli/project.py
Expand Up @@ -10,6 +10,7 @@
from great_expectations.cli.pretty_printing import cli_colorize_string, cli_message
from great_expectations.cli.toolkit import load_data_context_with_error_handling
from great_expectations.cli.upgrade_helpers import GE_UPGRADE_HELPER_VERSION_MAP
from great_expectations.core.usage_statistics.events import UsageStatsEvents
from great_expectations.core.usage_statistics.util import send_usage_message
from great_expectations.data_context.types.base import CURRENT_GE_CONFIG_VERSION

Expand Down Expand Up @@ -38,7 +39,7 @@ def project_check_config(ctx):

send_usage_message(
data_context=context,
event="cli.project.check_config",
event=UsageStatsEvents.CLI_PROJECT_CHECK_CONFIG.value,
success=True,
)

Expand Down
14 changes: 11 additions & 3 deletions great_expectations/cli/store.py
Expand Up @@ -2,6 +2,7 @@

from great_expectations.cli import toolkit
from great_expectations.cli.pretty_printing import cli_message, cli_message_dict
from great_expectations.core.usage_statistics.events import UsageStatsEvents
from great_expectations.core.usage_statistics.util import send_usage_message


Expand All @@ -11,13 +12,20 @@ def store(ctx):
"""Store operations"""
ctx.obj.data_context = ctx.obj.get_data_context_from_config_file()

usage_stats_prefix = f"cli.store.{ctx.invoked_subcommand}"
cli_event_noun: str = "store"
(
begin_event_name,
end_event_name,
) = UsageStatsEvents.get_cli_begin_and_end_event_names(
noun=cli_event_noun,
verb=ctx.invoked_subcommand,
)
send_usage_message(
data_context=ctx.obj.data_context,
event=f"{usage_stats_prefix}.begin",
event=begin_event_name,
success=True,
)
ctx.obj.usage_event_end = f"{usage_stats_prefix}.end"
ctx.obj.usage_event_end = end_event_name


@store.command(name="list")
Expand Down
14 changes: 11 additions & 3 deletions great_expectations/cli/suite.py
Expand Up @@ -17,6 +17,7 @@
from great_expectations.core.usage_statistics.anonymizers.types.base import (
CLISuiteInteractiveFlagCombinations,
)
from great_expectations.core.usage_statistics.events import UsageStatsEvents
from great_expectations.core.usage_statistics.usage_statistics import (
edit_expectation_suite_usage_statistics,
)
Expand All @@ -42,13 +43,20 @@ def suite(ctx):
"""Expectation Suite operations"""
ctx.obj.data_context = ctx.obj.get_data_context_from_config_file()

usage_stats_prefix = f"cli.suite.{ctx.invoked_subcommand}"
cli_event_noun: str = "suite"
(
begin_event_name,
end_event_name,
) = UsageStatsEvents.get_cli_begin_and_end_event_names(
noun=cli_event_noun,
verb=ctx.invoked_subcommand,
)
send_usage_message(
data_context=ctx.obj.data_context,
event=f"{usage_stats_prefix}.begin",
event=begin_event_name,
success=True,
)
ctx.obj.usage_event_end = f"{usage_stats_prefix}.end"
ctx.obj.usage_event_end = end_event_name


@suite.command(name="new")
Expand Down
15 changes: 8 additions & 7 deletions great_expectations/cli/toolkit.py
Expand Up @@ -18,6 +18,7 @@
from great_expectations.cli.upgrade_helpers import GE_UPGRADE_HELPER_VERSION_MAP
from great_expectations.core.batch import BatchRequest
from great_expectations.core.expectation_suite import ExpectationSuite
from great_expectations.core.usage_statistics.events import UsageStatsEvents
from great_expectations.core.usage_statistics.util import send_usage_message
from great_expectations.data_context.data_context import DataContext
from great_expectations.data_context.types.base import CURRENT_GE_CONFIG_VERSION
Expand Down Expand Up @@ -470,7 +471,7 @@ def upgrade_project_strictly_multiple_versions_increment(
try:
send_usage_message(
data_context=context,
event="cli.project.upgrade.end",
event=UsageStatsEvents.CLI_PROJECT_UPGRADE_END.value,
success=True,
)
except Exception:
Expand Down Expand Up @@ -517,7 +518,7 @@ def upgrade_project(
confirm_prompt=upgrade_prompt,
continuation_message=EXIT_UPGRADE_CONTINUATION_MESSAGE,
data_context=data_context,
usage_stats_event="cli.project.upgrade.end",
usage_stats_event=UsageStatsEvents.CLI_PROJECT_UPGRADE_END.value,
)
cli_message(string=SECTION_SEPARATOR)

Expand Down Expand Up @@ -559,7 +560,7 @@ def upgrade_project(
data_context: DataContext = DataContext(context_root_dir=context_root_dir)
send_usage_message(
data_context=data_context,
event="cli.project.upgrade.end",
event=UsageStatsEvents.CLI_PROJECT_UPGRADE_END.value,
success=True,
)
except Exception:
Expand All @@ -579,7 +580,7 @@ def upgrade_project_one_or_multiple_versions_increment(
try:
send_usage_message(
data_context=context,
event="cli.project.upgrade.begin",
event=UsageStatsEvents.CLI_PROJECT_UPGRADE_BEGIN.value,
success=True,
)
except Exception:
Expand Down Expand Up @@ -640,7 +641,7 @@ def upgrade_project_one_or_multiple_versions_increment(
try:
send_usage_message(
data_context=context,
event="cli.project.upgrade.end",
event=UsageStatsEvents.CLI_PROJECT_UPGRADE_END.value,
success=True,
)
except Exception:
Expand Down Expand Up @@ -681,7 +682,7 @@ def upgrade_project_zero_versions_increment(
try:
send_usage_message(
data_context=context,
event="cli.project.upgrade.begin",
event=UsageStatsEvents.CLI_PROJECT_UPGRADE_BEGIN.value,
success=True,
)
except Exception:
Expand Down Expand Up @@ -716,7 +717,7 @@ def upgrade_project_zero_versions_increment(
try:
send_usage_message(
data_context=context,
event="cli.project.upgrade.end",
event=UsageStatsEvents.CLI_PROJECT_UPGRADE_END.value,
success=True,
)
except Exception:
Expand Down
4 changes: 2 additions & 2 deletions great_expectations/core/expectation_suite.py
Expand Up @@ -15,6 +15,7 @@
ExpectationConfigurationSchema,
expectationConfigurationSchema,
)
from great_expectations.core.usage_statistics.events import UsageStatsEvents
from great_expectations.core.util import (
convert_to_json_serializable,
ensure_json_serializable,
Expand Down Expand Up @@ -589,11 +590,10 @@ def _add_expectation(
return expectation_configuration

def send_usage_event(self, success: bool):
usage_stats_event_name: str = "expectation_suite.add_expectation"
usage_stats_event_payload: dict = {}
if self._data_context is not None:
self._data_context.send_usage_message(
event=usage_stats_event_name,
event=UsageStatsEvents.EXPECTATION_SUITE_ADD_EXPECTATION.value,
event_payload=usage_stats_event_payload,
success=success,
)
Expand Down