Skip to content

fix: reset user agent for each requests in local pfs #7587

fix: reset user agent for each requests in local pfs

fix: reset user agent for each requests in local pfs #7587

GitHub Actions / promptflow SDK CLI Azure E2E Test Result [zhangxingzhi/reset-user-agent-for-each-pfs-request](https://github.com/microsoft/promptflow/actions/workflows/promptflow-sdk-cli-azure-e2e-test.yml?query=branch:zhangxingzhi/reset-user-agent-for-each-pfs-request++) failed Mar 11, 2024 in 0s

1 fail, 19 skipped, 148 pass in 3m 45s

  4 files  ±0    4 suites  ±0   3m 45s ⏱️ +2s
168 tests ±0  148 ✅  - 1  19 💤 ±0  1 ❌ +1 
672 runs  ±0  592 ✅  - 4  76 💤 ±0  4 ❌ +4 

Results for commit ee5e471. ± Comparison against earlier commit 2657a08.

Annotations

Check warning on line 0 in tests.sdk_cli_azure_test.e2etests.test_telemetry.TestTelemetry

See this annotation in the file changed.

@github-actions github-actions / promptflow SDK CLI Azure E2E Test Result [zhangxingzhi/reset-user-agent-for-each-pfs-request](https://github.com/microsoft/promptflow/actions/workflows/promptflow-sdk-cli-azure-e2e-test.yml?query=branch:zhangxingzhi/reset-user-agent-for-each-pfs-request++)

All 4 runs failed: test_sdk_telemetry_ua (tests.sdk_cli_azure_test.e2etests.test_telemetry.TestTelemetry)

artifacts/Test Results (Python 3.10) (OS ubuntu-latest)/test-results.xml [took 0s]
artifacts/Test Results (Python 3.11) (OS ubuntu-latest)/test-results.xml [took 0s]
artifacts/Test Results (Python 3.8) (OS ubuntu-latest)/test-results.xml [took 0s]
artifacts/Test Results (Python 3.9) (OS ubuntu-latest)/test-results.xml [took 0s]
Raw output
ValueError: too many values to unpack (expected 2)
self = <sdk_cli_azure_test.e2etests.test_telemetry.TestTelemetry object at 0x7f94ac33bd00>
pf = <promptflow.azure._pf_client.PFClient object at 0x7f94a4abee00>

    def test_sdk_telemetry_ua(self, pf):
        from promptflow import PFClient
        from promptflow.azure import PFClient as PFAzureClient
    
        # log activity will pick correct ua
        def assert_ua(*args, **kwargs):
            ua = pydash.get(kwargs, "extra.custom_dimensions.user_agent", None)
            ua_dict = parse_ua_to_dict(ua)
            assert ua_dict.keys() == {"promptflow-sdk"}
    
        logger = MagicMock()
        logger.info = MagicMock()
        logger.info.side_effect = assert_ua
    
        # clear user agent before test
        context = OperationContext().get_instance()
        context.user_agent = ""
        # get telemetry logger from SDK should not have extension ua
        # start a clean local SDK client
        with environment_variable_overwrite(PF_USER_AGENT, ""):
            PFClient()
            user_agent = ClientUserAgentUtil.get_user_agent()
            ua_dict = parse_ua_to_dict(user_agent)
            assert ua_dict.keys() == {"promptflow-sdk"}
    
            # Call log_activity
            with log_activity(logger, "test_activity", activity_type=ActivityType.PUBLICAPI):
                # Perform some activity
                pass
    
        # start a clean Azure SDK client
        with environment_variable_overwrite(PF_USER_AGENT, ""):
            PFAzureClient(
                ml_client=pf._ml_client,
                subscription_id=pf._ml_client.subscription_id,
                resource_group_name=pf._ml_client.resource_group_name,
                workspace_name=pf._ml_client.workspace_name,
            )
            user_agent = ClientUserAgentUtil.get_user_agent()
            ua_dict = parse_ua_to_dict(user_agent)
            assert ua_dict.keys() == {"promptflow-sdk"}
    
            # Call log_activity
            with log_activity(logger, "test_activity", activity_type=ActivityType.PUBLICAPI):
                # Perform some activity
                pass
    
        PFAzureClient(
            ml_client=pf._ml_client,
            subscription_id=pf._ml_client.subscription_id,
            resource_group_name=pf._ml_client.resource_group_name,
            workspace_name=pf._ml_client.workspace_name,
            user_agent="a/1.0.0",
        )
        user_agent = ClientUserAgentUtil.get_user_agent()
>       ua_dict = parse_ua_to_dict(user_agent)

tests/sdk_cli_azure_test/e2etests/test_telemetry.py:278: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

ua = 'promptflow-sdk/0.0.1a/1.0.0promptflow-sdk/0.0.1'

    def parse_ua_to_dict(ua):
        """Parse string user agent to dict with name as ua name and value as ua version."""
        ua_dict = {}
        ua_list = ua.split(" ")
        for item in ua_list:
            if item:
>               key, value = item.split("/")
E               ValueError: too many values to unpack (expected 2)

promptflow/_utils/utils.py:270: ValueError