-
Notifications
You must be signed in to change notification settings - Fork 62
feat(api): add Fabric skill telemetry #282
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
Open
shirasassoon
wants to merge
16
commits into
microsoft:main
Choose a base branch
from
shirasassoon:add-fabric-skill-attribution
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+214
−4
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
25a4126
feat(api): add Fabric skill attribution
0197c2f
Merge upstream main into add-fabric-skill-attribution
a2ecdf0
chore: skip changelog for skill attribution
779305b
docs: keep skill attribution internal
ecefc1e
refactor: align skill attribution with telemetry
cd63e1b
refactor: use command-scoped skill attribution
5e0ba0f
revert format change
shirasassoon 8c28418
test: consolidate skill attribution coverage
9500c4b
Merge remote-tracking branch 'origin/add-fabric-skill-attribution' in…
7aa5c66
Merge branch 'main' into add-fabric-skill-attribution
shirasassoon d0c0fbb
remove validation
bcecf0a
header exclusion logic
2073a7f
fix failing test
e5f97a6
feedback
f4b1db7
add prefix
1e98fde
update tests
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,181 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT License. | ||
|
|
||
| import argparse | ||
| from argparse import Namespace | ||
| from unittest.mock import patch | ||
|
|
||
| import pytest | ||
|
|
||
| from fabric_cli.client.fab_api_client import do_request | ||
| from fabric_cli.core import fab_constant, fab_state_config | ||
| from fabric_cli.core import fab_logger as logger | ||
| from fabric_cli.core.fab_auth import FabAuth | ||
| from fabric_cli.core.fab_context import Context | ||
| from fabric_cli.core.fab_decorators import set_command_context | ||
| from fabric_cli.core.fab_parser_setup import create_parser_and_subparsers | ||
| from fabric_cli.parsers import fab_global_params | ||
|
|
||
| pytestmark = pytest.mark.usefixtures("reset_context") | ||
|
|
||
|
|
||
| class DummyResponse: | ||
| status_code = 200 | ||
| text = "{}" | ||
| content = b"{}" | ||
| headers: dict[str, str] = {} | ||
|
|
||
|
|
||
| def test_skill_argument_is_hidden_success(): | ||
| parser = argparse.ArgumentParser() | ||
| fab_global_params.add_global_flags(parser) | ||
|
|
||
| skill_flag = next( | ||
| action for action in parser._actions if "--skill" in action.option_strings | ||
| ) | ||
|
|
||
| assert skill_flag.help == argparse.SUPPRESS | ||
| assert "--skill" not in parser.format_help() | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "command", | ||
| [ | ||
| ["--skill", "semantic-model-authoring", "export", "ws.Workspace", "-o", "out"], | ||
| ["export", "--skill", "semantic-model-authoring", "ws.Workspace", "-o", "out"], | ||
| ["export", "ws.Workspace", "-o", "out", "--skill", "semantic-model-authoring"], | ||
| ["--skill", "semantic-model-authoring", "job", "run", "ws.Notebook"], | ||
| ["job", "run", "ws.Notebook", "--skill", "semantic-model-authoring"], | ||
| ], | ||
| ) | ||
| def test_skill_argument_is_preserved_across_command_tree_success(command): | ||
| parser, _ = create_parser_and_subparsers() | ||
|
|
||
| args = parser.parse_args(command) | ||
|
|
||
| assert args.skill == "semantic-model-authoring" | ||
|
|
||
|
|
||
| def test_command_context_uses_skill_argument_success(): | ||
| @set_command_context() | ||
| def command(args: Namespace) -> None: | ||
| assert Context().fabric_skill == "argument-skill" | ||
|
|
||
| command(Namespace(command_path="export", skill="argument-skill")) | ||
|
|
||
|
|
||
| def test_command_context_clears_previous_skill_success(): | ||
| Context().fabric_skill = "previous-skill" | ||
|
|
||
| @set_command_context() | ||
| def command(args: Namespace) -> None: | ||
| assert Context().fabric_skill is None | ||
|
|
||
| command(Namespace(command_path="export", skill=None)) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "value", | ||
| [ | ||
| "", | ||
| " ", | ||
| "bad\nvalue", | ||
| "bad\rvalue", | ||
| "-leading", | ||
| "a", | ||
| "semantic-model_authoring.v2", | ||
| "a" * 129, | ||
| ], | ||
| ids=[ | ||
| "empty", | ||
| "whitespace", | ||
| "newline", | ||
| "carriage-return", | ||
| "leading-hyphen", | ||
| "single-character", | ||
| "punctuation", | ||
| "long", | ||
| ], | ||
| ) | ||
| def test_fabric_skill_setter_preserves_string_value_success(value): | ||
| Context().fabric_skill = value | ||
|
|
||
| assert Context().fabric_skill == value | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "value", | ||
| [123, True, [], {}, object()], | ||
| ids=["integer", "boolean", "list", "dictionary", "object"], | ||
| ) | ||
| def test_fabric_skill_setter_normalizes_non_string_value_success(value): | ||
| Context().fabric_skill = value | ||
|
|
||
| assert Context().fabric_skill is None | ||
|
|
||
|
|
||
| @patch.object(FabAuth(), "get_access_token", return_value="dummy-token") | ||
| @pytest.mark.parametrize( | ||
| "audience, expects_skill_header", | ||
| [ | ||
| (None, True), | ||
| ("fabric", True), | ||
| ("storage", False), | ||
| ("azure", False), | ||
| ("powerbi", False), | ||
| ], | ||
| ) | ||
| def test_skill_header_is_scoped_to_fabric_api_success( | ||
| _mock_get_token, audience, expects_skill_header | ||
| ): | ||
| Context().fabric_skill = "semantic-model-authoring" | ||
| args = Namespace(uri="items", method="get", audience=audience) | ||
|
|
||
| with patch( | ||
| "requests.Session.request", return_value=DummyResponse() | ||
| ) as mock_request: | ||
| do_request(args) | ||
|
|
||
| request_headers = mock_request.call_args.kwargs["headers"] | ||
| if expects_skill_header: | ||
| assert ( | ||
| request_headers[fab_constant.FABRIC_SKILL_HEADER] | ||
| == "semantic-model-authoring" | ||
| ) | ||
| else: | ||
| assert fab_constant.FABRIC_SKILL_HEADER not in request_headers | ||
|
|
||
|
|
||
| @patch.object(FabAuth(), "get_access_token", return_value="dummy-token") | ||
| def test_skill_header_is_omitted_when_skill_is_not_set_success(_mock_get_token): | ||
| args = Namespace(uri="items", method="get", audience="fabric") | ||
|
|
||
| with patch( | ||
| "requests.Session.request", return_value=DummyResponse() | ||
| ) as mock_request: | ||
| do_request(args) | ||
|
|
||
| request_headers = mock_request.call_args.kwargs["headers"] | ||
| assert fab_constant.FABRIC_SKILL_HEADER not in request_headers | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "header_name", | ||
| [fab_constant.FABRIC_SKILL_HEADER, "X-MS-FABRIC-SKILL"], | ||
| ids=["canonical-case", "uppercase"], | ||
| ) | ||
| def test_skill_header_is_not_logged_success(monkeypatch, header_name): | ||
| monkeypatch.setattr(fab_state_config, "get_config", lambda key: "true") | ||
|
|
||
| with patch.object(logger, "get_logger") as mock_get_logger: | ||
| logger.log_debug_http_request( | ||
| "GET", | ||
| "http://example.com", | ||
| {header_name: "semantic-model-authoring"}, | ||
| 10, | ||
| ) | ||
|
|
||
| logged_messages = [ | ||
| call.args[0] for call in mock_get_logger.return_value.debug.call_args_list | ||
| ] | ||
| assert not any("semantic-model-authoring" in message for message in logged_messages) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.