Skip to content
This repository has been archived by the owner on Jul 28, 2023. It is now read-only.

Improve logging #579

Merged
merged 54 commits into from
Mar 17, 2020
Merged

Improve logging #579

merged 54 commits into from
Mar 17, 2020

Conversation

lgarc15
Copy link
Contributor

@lgarc15 lgarc15 commented Mar 5, 2020

Summary

Addresses #524

Details and comments

This PR sets up a logger for the package, which allows loggers within the modules to inherit the correct level when the QISKIT_IBMQ_PROVIDER_LOG_LEVEL environment variable is set. Also, it allows users to specify a filename to place logs into, via the QISKIT_IBMQ_PROVIDER_LOG_FILE environment variable.

It also adds more debugging messages, using Session.request as the centralized logging placement.

An example of the log format is:

websocket.get_job_status:DEBUG:2020-03-17 16:21:45,632: Received message from websocket: {'hubInfo': '...', 'id': '5e70f8f18a2f2f0018e12452', 'endDate': '2020-03-17T16:21:43.196Z', 'backend': {'id': '5ae875670f020500393162ad', 'name': '...'}, 'kind': 'q-object-external-storage', 'status': 'COMPLETED', 'creationDate': '2020-03-17T16:21:05.284Z'}

The first part:
websocket.get_job_status:DEBUG:2020-03-17 16:21:45,632:
is formatted automatically.

The second part:
Received message from websocket: {'hubInfo': '...', 'id': '5e70f8f18a2f2f0018e12452', 'endDate': '2020-03-17T16:21:43.196Z', 'backend': {'id': '5ae875670f020500393162ad', 'name': '...'}, 'kind': 'q-object-external-storage', 'status': 'COMPLETED', 'creationDate': '2020-03-17T16:21:05.284Z'}
is the specified message to include in the log.

qiskit/providers/ibmq/ibmqbackend.py Outdated Show resolved Hide resolved
qiskit/providers/ibmq/utils/utils.py Outdated Show resolved Hide resolved
qiskit/providers/ibmq/utils/utils.py Outdated Show resolved Hide resolved
qiskit/providers/ibmq/api/rest/job.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@jyu00 jyu00 left a comment

Choose a reason for hiding this comment

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

Some response data is also worth logging - like job cancel which has not been super reliable.

qiskit/providers/ibmq/api/session.py Outdated Show resolved Hide resolved
qiskit/providers/ibmq/__init__.py Outdated Show resolved Hide resolved
qiskit/providers/ibmq/utils/utils.py Show resolved Hide resolved
@lgarc15 lgarc15 changed the title Improve logging (WIP) Improve logging Mar 11, 2020
@lgarc15
Copy link
Contributor Author

lgarc15 commented Mar 11, 2020

TODO: Fix test_log_file since tests are run in parallel.

Copy link
Collaborator

@jyu00 jyu00 left a comment

Choose a reason for hiding this comment

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

Can you also add logging to websocket and ensure any causing exceptions are logged (e.g. if there's raise ex2 from ex1 make sure both ex2 and ex1 are logged)?

qiskit/providers/ibmq/__init__.py Outdated Show resolved Hide resolved
qiskit/providers/ibmq/__init__.py Outdated Show resolved Hide resolved
qiskit/providers/ibmq/__init__.py Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
qiskit/providers/ibmq/utils/utils.py Outdated Show resolved Hide resolved
test/ibmq/test_ibmq_logger.py Outdated Show resolved Hide resolved
test/ibmq/test_ibmq_logger.py Outdated Show resolved Hide resolved
test/ibmq/test_ibmq_logger.py Show resolved Hide resolved
test/ibmq/test_ibmq_logger.py Outdated Show resolved Hide resolved
test/ibmq/test_ibmq_logger.py Outdated Show resolved Hide resolved
qiskit/providers/ibmq/__init__.py Show resolved Hide resolved
qiskit/providers/ibmq/__init__.py Outdated Show resolved Hide resolved
qiskit/providers/ibmq/__init__.py Outdated Show resolved Hide resolved
qiskit/providers/ibmq/__init__.py Outdated Show resolved Hide resolved
qiskit/providers/ibmq/api/session.py Outdated Show resolved Hide resolved
qiskit/providers/ibmq/api/session.py Outdated Show resolved Hide resolved
qiskit/providers/ibmq/api/clients/websocket.py Outdated Show resolved Hide resolved
test/ibmq/test_ibmq_logger.py Outdated Show resolved Hide resolved
@jyu00
Copy link
Collaborator

jyu00 commented Mar 16, 2020

One more comment. You mentioned that you wanted to reuse LOG_LEVEL for both test and mainline so the user doesn't have to specify two different variables. You can still accomplish this by manually setting the logging level of qiskit.providers.ibmq to LOG_LEVEL in IBMQTestCase.

@lgarc15
Copy link
Contributor Author

lgarc15 commented Mar 16, 2020

One more comment. You mentioned that you wanted to reuse LOG_LEVEL for both test and mainline so the user doesn't have to specify two different variables. You can still accomplish this by manually setting the logging level of qiskit.providers.ibmq to LOG_LEVEL in IBMQTestCase.

Are you suggesting changing the level of the qiskit.providers.ibmq logger within the tests, to the level specified by LOG_LEVEL, when LOG_LEVEL is set as an environment variable?

@jyu00
Copy link
Collaborator

jyu00 commented Mar 17, 2020

Some comments based on the Travis output:

  • Drop %(name)s from the log format to shorten the log. %(module)s.%(funcName)s should be enough to tell us where it's from.
  • Why is log level displayed as [secure]?
  • Drop /devices/.../queue/status and /devices/v/1
  • Log that we're uploading/downloading to/from object storage but don't log the actual url
  • Log request data only for certain endpoints

@jyu00
Copy link
Collaborator

jyu00 commented Mar 17, 2020

Are you suggesting changing the level of the qiskit.providers.ibmq logger within the tests, to the level specified by LOG_LEVEL, when LOG_LEVEL is set as an environment variable?

Yes, if the qiskit.providers.ibmq logger level is UNSET.

@lgarc15
Copy link
Contributor Author

lgarc15 commented Mar 17, 2020

Why is log level displayed as [secure]?

This was the case because I had the setting in my Travis CI to hide the value set for QISKIT_IBMQ_PROVIDER_LOG_LEVEL. I unchecked the box, so the log level will be present in future runs.

Also, I added this into IBMQTestCase ✅:

One more comment. You mentioned that you wanted to reuse LOG_LEVEL for both test and mainline so the user doesn't have to specify two different variables. You can still accomplish this by manually setting the logging level of qiskit.providers.ibmq to LOG_LEVEL in IBMQTestCase.

Copy link
Collaborator

@jyu00 jyu00 left a comment

Choose a reason for hiding this comment

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

This looks good, just a few small suggestions.

qiskit/providers/ibmq/__init__.py Outdated Show resolved Hide resolved
qiskit/providers/ibmq/api/session.py Outdated Show resolved Hide resolved
from the request, within the url and request data.

The following endpoint URLs are not logged in order to reduce noise: ``/users``
and ``/version``. Likewise, the request data is only logged for the following
Copy link
Collaborator

Choose a reason for hiding this comment

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

The docstring is now outdated with additional endpoints not being logged. It might be easier to either just say "not all endpoints are logged" or define a "constant" for excluded endpoints and just say those in the constant are not logged.

Copy link
Contributor Author

@lgarc15 lgarc15 Mar 17, 2020

Choose a reason for hiding this comment

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

I separated filtering out url logs by introducing another private method _is_worth_logging(...), in order to make the filtering more readable and maintainable (in case we add other endpoints in the future). Would it be better to have a "constant" defined or would the function be an okay addition instead?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I personally like a "constant" since it's obvious and easy to update, but it's not a big deal to just use the method.

test/ibmq/test_ibmq_logger.py Outdated Show resolved Hide resolved
test/ibmqtestcase.py Outdated Show resolved Hide resolved
@jyu00 jyu00 merged commit 62b4258 into Qiskit:master Mar 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants