Skip to content

{Core} Add SessionId for telemetry#15076

Merged
houk-ms merged 3 commits intoAzure:devfrom
houk-ms:sessionid-for-telemetry
Sep 15, 2020
Merged

{Core} Add SessionId for telemetry#15076
houk-ms merged 3 commits intoAzure:devfrom
houk-ms:sessionid-for-telemetry

Conversation

@houk-ms
Copy link
Contributor

@houk-ms houk-ms commented Sep 8, 2020

Description

SessionId is used to help us identify whether the users are running their CLI commands in the same terminal. It can help us analysis the user behavior, by which we may be able to cluster the commands and improve CLI error rate measurement. It may also help us separate interactive users from automation scripts.

This PR

  • adds session id for telemetry
  • adds package psutil as azure-cli dependency (except for cygwin)

Note

The package psutil was remove from CLI dependencies in #11665 because of cygwin incompatibility. In this PR, we reintroduce the package and provide a workaround to avoid installing it in cygwin.

Known Issue

For special systems which do not support psutil like Cygwin, the sessionID can not be calculated. But it is set to empty, so that we can filter them easily.

For automation script, the sessionIDs of the commands in script will be the same except for the first command. It only occurs on None-windwos OSes and only in automation scripts.

@yonzhan
Copy link
Collaborator

yonzhan commented Sep 8, 2020

Core

while process and process.ppid() and process.pid != process.ppid():
parent_process = process.parent()
if parent_process and process.create_time() - parent_process.create_time() > time_threshold:
content = '{}{}{}'.format(_get_installation_id(), parent_process.create_time(), parent_process.pid)
Copy link
Member

Choose a reason for hiding this comment

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

I thought you mentioned will distinguish by terminal type right?

Copy link
Contributor Author

@houk-ms houk-ms Sep 9, 2020

Choose a reason for hiding this comment

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

It turns out to be an invalid method. For there may be the cases where a shell was called in another shell, e.g, powershell will call cmd to execute CLI command. So we can't recognize the target terminal processs only by the name.

I think the method I proposed here is better for practice. It can deal with all kinds of OSes and their different terminals.

Copy link
Contributor

Choose a reason for hiding this comment

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

Please test below scenario:

  1. write a script which has following content, let's give it a name script.sh

#!/bin/bash
az vm list -g resource_group # It's better that the time cost of this command is over 1 second.
az vm list -g resource_group

  1. open a terminal or tty and run following command

bash script.sh

check whether the sessionId returned by the 2 commands are the same.

Copy link
Contributor Author

@houk-ms houk-ms Sep 11, 2020

Choose a reason for hiding this comment

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

For automation script, the sessionIDs of the commands in script will be the same except for the first command. It only occurs on None-windwos OSes and only in automation scripts. It will be recorded as known issue before we can find a better method to get sessionID.

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, you convince me. 👍

@houk-ms houk-ms merged commit ee7bd2d into Azure:dev Sep 15, 2020
@pspag
Copy link

pspag commented Oct 4, 2020

Hello, not sure if this is the right place to report this, but it seems this change introduced a regression issue which once more breaks building azure-cli with pip in cygwin, due to the re-introduction of psutil. This was previously fixed in #11665. The issue had been originally reported in #9399.

Please let me know if you would like this reported in a new issue.

@houk-ms
Copy link
Contributor Author

houk-ms commented Oct 9, 2020

@pspag Sorry for the inconvenience. We removed the psutil dependency for Cygwin in setup.py, but it only takes effect when using source installation. We will schedule to fix the issue as soon as we can.

As a workaround to use the latest CLI in cygwin, try to

  1. Download the source package from pypi
  2. pip install the source package

@pspag
Copy link

pspag commented Oct 11, 2020

@houk-ms many thanks for your reply. No problem at all, since I came across this I just wanted to report it as I imagine it will be also affecting others. In the meantime I use 2.11.1 where this feature is not included.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants