Skip to content

Cosmos Diagnostics#25678

Closed
bambriz wants to merge 9 commits into
Azure:mainfrom
bambriz:main
Closed

Cosmos Diagnostics#25678
bambriz wants to merge 9 commits into
Azure:mainfrom
bambriz:main

Conversation

@bambriz
Copy link
Copy Markdown
Member

@bambriz bambriz commented Aug 11, 2022

Description

Adds a new azure core policy that is a child class of HttpLoggingPolicy. By default it does the same actions as HttpLoggingPolicy, but with a flag it will enable it to log additional useful diagnostic information.

Here is an example of a succesful request and respone with diagnostic mode enabled:

Request URL: 'https://127.0.0.1:8081//dbs/QueryTest/colls/QueryContainer/docs/'
Request method: 'POST'
Request headers:
    'Cache-Control': 'no-cache'
    'x-ms-version': '2018-12-31'
    'x-ms-documentdb-query-iscontinuationexpected': 'False'
    'x-ms-consistency-level': 'Session'
    'x-ms-documentdb-isquery': 'true'
    'Content-Type': 'application/query+json'
    'x-ms-session-token': '0:-1#1109'
    'x-ms-documentdb-query-enablecrosspartition': 'True'
    'x-ms-date': 'Mon, 29 Aug 2022 23:48:50 GMT'
    'authorization': 'type%3Dmaster%26ver%3D1.0%26sig%3DzSh2uGiaQQBcXIgcaW044ubLlNhM41nLbIcpR6e3h3U%3D'
    'Accept': 'application/json'
    'Content-Length': '60'
    'User-Agent': 'azsdk-python-cosmos/4.3.1 Python/3.10.5 (Windows-10-10.0.19044-SP0)'
A body is sent with the request
Response status: 200
Response status reason: Ok
Elapsed Time: 0:00:00.004243
Response headers:
    'Cache-Control': 'no-store, no-cache'
    'Pragma': 'no-cache'
    'Transfer-Encoding': 'chunked'
    'Content-Type': 'application/json'
    'Server': 'Microsoft-HTTPAPI/2.0'
    'Access-Control-Allow-Origin': ''
    'Access-Control-Allow-Credentials': 'true'
    'x-ms-activity-id': 'a3dcb669-5931-4e16-9c69-c82f5bc28943'
    'x-ms-last-state-change-utc': 'Mon, 29 Aug 2022 23:32:06.188 GMT'
    'x-ms-resource-quota': 'documentSize=10240;documentsSize=10485760;documentsCount=-1;collectionSize=10485760;'
    'x-ms-resource-usage': 'documentSize=0;documentsSize=0;documentsCount=6;collectionSize=0;'
    'x-ms-schemaversion': '1.13'
    'lsn': '1109'
    'x-ms-item-count': '0'
    'x-ms-request-charge': '2.8'
    'x-ms-alt-content-path': 'dbs/QueryTest/colls/QueryContainer'
    'x-ms-content-path': 'po1LAOYi6xM='
    'x-ms-quorum-acked-lsn': '1109'
    'x-ms-current-write-quorum': '1'
    'x-ms-current-replica-set-size': '1'
    'x-ms-documentdb-partitionkeyrangeid': '0'
    'x-ms-xp-role': '0'
    'x-ms-cosmos-query-execution-info': '{"reverseRidEnabled":false,"reverseIndexScan":false}'
    'x-ms-global-Committed-lsn': '-1'
    'x-ms-number-of-read-regions': '0'
    'x-ms-transport-request-id': '787'
    'x-ms-cosmos-llsn': '1109'
    'x-ms-cosmos-quorum-acked-llsn': '1109'
    'x-ms-session-token': '0:-1#1109'
    'x-ms-request-duration-ms': '0.745'
    'x-ms-serviceversion': 'version=2.14.0.0'
    'x-ms-cosmos-is-partition-key-delete-pending': 'false'
    'x-ms-gatewayversion': 'version=2.14.0'
    'Date': 'Mon, 29 Aug 2022 23:48:50 GMT'

Here it is an example with the default HttpLogginPolicy:

Request URL: 'https://localhost:8081'
Request method: 'GET'
Request headers:
    'Cache-Control': 'no-cache'
    'x-ms-version': 'REDACTED'
    'x-ms-documentdb-query-iscontinuationexpected': 'REDACTED'
    'x-ms-date': 'REDACTED'
    'authorization': 'REDACTED'
    'Accept': 'application/json'
    'Content-Length': '0'
    'User-Agent': 'azsdk-python-cosmos/4.3.1 Python/3.10.5 (Windows-10-10.0.19044-SP0)'
No body was attached to the request
Response status: 200
Response headers:
    'Cache-Control': 'no-store, no-cache'
    'Pragma': 'no-cache'
    'Transfer-Encoding': 'chunked'
    'Content-Type': 'application/json'
    'Content-Location': 'REDACTED'
    'Server': 'Microsoft-HTTPAPI/2.0'
    'Access-Control-Allow-Origin': 'REDACTED'
    'Access-Control-Allow-Credentials': 'REDACTED'
    'x-ms-max-media-storage-usage-mb': 'REDACTED'
    'x-ms-media-storage-usage-mb': 'REDACTED'
    'x-ms-databaseaccount-consumed-mb': 'REDACTED'
    'x-ms-databaseaccount-reserved-mb': 'REDACTED'
    'x-ms-databaseaccount-provisioned-mb': 'REDACTED'
    'x-ms-gatewayversion': 'REDACTED'
    'Date': 'Tue, 30 Aug 2022 00:03:31 GMT'

And here are two examples with an exception:

Request URL: 'https://127.0.0.1:8081//dbs'
Request method: 'POST'
Request headers:
    'Cache-Control': 'no-cache'
    'x-ms-version': '2018-12-31'
    'x-ms-documentdb-query-iscontinuationexpected': 'False'
    'x-ms-consistency-level': 'Session'
    'x-ms-offer-throughput': '1200'
    'x-ms-date': 'Mon, 29 Aug 2022 23:48:50 GMT'
    'authorization': 'type%3Dmaster%26ver%3D1.0%26sig%3DKvfTl5dwCDzexR%2FD9zifLQkvYDvsxPgz0v8t00%2BRhZ8%3D'
    'Content-Type': 'application/json'
    'Accept': 'application/json'
    'Content-Length': '16'
    'User-Agent': 'azsdk-python-cosmos/4.3.1 Python/3.10.5 (Windows-10-10.0.19044-SP0)'
A body is sent with the request
Response status: 409
Response status reason: Conflict
Elapsed Time: 0:00:00.004218
Response status error message: Entity with the specified id already exists in the system. 
ActivityId: aaa20ce0-3b90-4b9c-8fba-bcb4d9b8191f, Microsoft.Azure.Documents.Common/2.14.0
Response headers:
    'Transfer-Encoding': 'chunked'
    'Content-Type': 'application/json'
    'Server': 'Microsoft-HTTPAPI/2.0'
    'Access-Control-Allow-Origin': ''
    'Access-Control-Allow-Credentials': 'true'
    'x-ms-activity-id': 'aaa20ce0-3b90-4b9c-8fba-bcb4d9b8191f'
    'x-ms-substatus': '3206'
    'x-ms-gatewayversion': 'version=2.14.0'
    'Date': 'Mon, 29 Aug 2022 23:48:50 GMT'

same one with default policy:

Request URL: 'https://127.0.0.1:8081//dbs'
Request method: 'POST'
Request headers:
    'Cache-Control': 'no-cache'
    'x-ms-version': 'REDACTED'
    'x-ms-documentdb-query-iscontinuationexpected': 'REDACTED'
    'x-ms-consistency-level': 'REDACTED'
    'x-ms-offer-throughput': 'REDACTED'
    'x-ms-date': 'REDACTED'
    'authorization': 'REDACTED'
    'Content-Type': 'application/json'
    'Accept': 'application/json'
    'Content-Length': '16'
    'User-Agent': 'azsdk-python-cosmos/4.3.1 Python/3.10.5 (Windows-10-10.0.19044-SP0)'
A body is sent with the request
Response status: 409
Response headers:
    'Transfer-Encoding': 'chunked'
    'Content-Type': 'application/json'
    'Server': 'Microsoft-HTTPAPI/2.0'
    'Access-Control-Allow-Origin': 'REDACTED'
    'Access-Control-Allow-Credentials': 'REDACTED'
    'x-ms-activity-id': 'REDACTED'
    'x-ms-substatus': 'REDACTED'
    'x-ms-gatewayversion': 'REDACTED'
    'Date': 'Tue, 30 Aug 2022 00:03:31 GMT'

second example with additional information:

Request URL: 'https://127.0.0.1:8081//dbs/Cowboys/colls/Bryan1/'
Request method: 'GET'
Request headers:
    'Cache-Control': 'no-cache'
    'x-ms-version': '2018-12-31'
    'x-ms-documentdb-query-iscontinuationexpected': 'False'
    'x-ms-consistency-level': 'Session'
    'x-ms-date': 'Mon, 29 Aug 2022 23:48:50 GMT'
    'authorization': 'type%3Dmaster%26ver%3D1.0%26sig%3D%2BfLkccvix8wbjgsXlBeVS1iyyZ3ouG%2BxxxalY0xNPLM%3D'
    'Accept': 'application/json'
    'Content-Length': '0'
    'User-Agent': 'azsdk-python-cosmos/4.3.1 Python/3.10.5 (Windows-10-10.0.19044-SP0)'
No body was attached to the request
Response status: 404
Response status reason: Not Found
Elapsed Time: 0:00:00.005835
Response status error message: Message: {"Errors":["Resource Not Found. Learn more: https:\/\/aka.ms\/cosmosdb-tsg-not-found"]} 
ActivityId: 062b07ce-bfe3-4d38-aed1-8fc917de5ebf, Request URI: /apps/DocDbApp/services/DocDbMaster0/partitions/780e44f4-38c8-11e6-8106-8cdcd42c33be/replicas/1p/, RequestStats:  
RequestStartTime: 2022-08-29T23:48:50.6901073Z, RequestEndTime: 2022-08-29T23:48:50.6921086Z,  Number of regions attempted:1 
{"systemHistory":[{"dateUtc":"2022-08-29T23:47:52.1674495Z","cpu":8.541,"memory":19873916.000,"threadInfo":{"isThreadStarving":"False","threadWaitIntervalInMs":0.097,"availableThreads":32766,"minThreads":8,"maxThreads":32767}},{"dateUtc":"2022-08-29T23:48:02.1705982Z","cpu":16.328,"memory":19877228.000,"threadInfo":{"isThreadStarving":"False","threadWaitIntervalInMs":0.0768,"availableThreads":32765,"minThreads":8,"maxThreads":32767}},{"dateUtc":"2022-08-29T23:48:12.1740513Z","cpu":35.491,"memory":19859740.000,"threadInfo":{"isThreadStarving":"False","threadWaitIntervalInMs":0.138,"availableThreads":32766,"minThreads":8,"maxThreads":32767}},{"dateUtc":"2022-08-29T23:48:22.1871249Z","cpu":23.223,"memory":19867468.000,"threadInfo":{"isThreadStarving":"False","threadWaitIntervalInMs":0.0252,"availableThreads":32765,"minThreads":8,"maxThreads":32767}},{"dateUtc":"2022-08-29T23:48:32.1893425Z","cpu":35.238,"memory":19733340.000,"threadInfo":{"isThreadStarving":"False","threadWaitIntervalInMs":0.0512,"availableThreads":32766,"minThreads":8,"maxThreads":32767}},{"dateUtc":"2022-08-29T23:48:42.2021204Z","cpu":24.219,"memory":19688028.000,"threadInfo":{"isThreadStarving":"False","threadWaitIntervalInMs":0.0531,"availableThreads":32766,"minThreads":8,"maxThreads":32767}}]} 
RequestStart: 2022-08-29T23:48:50.6911070Z; ResponseTime: 2022-08-29T23:48:50.6921086Z; StoreResult: StorePhysicalAddress: rntbd://127.0.0.1:10251/apps/DocDbApp/services/DocDbMaster0/partitions/780e44f4-38c8-11e6-8106-8cdcd42c33be/replicas/1p/, LSN: 3202, GlobalCommittedLsn: -1, PartitionKeyRangeId: , IsValid: True, StatusCode: 404, SubStatusCode: 0, RequestCharge: 1, ItemLSN: -1, SessionToken: -1#3202, UsingLocalLSN: False, TransportException: null, BELatencyMs: 0.353, ActivityId: 062b07ce-bfe3-4d38-aed1-8fc917de5ebf, RetryAfterInMs: , TransportRequestTimeline: {"requestTimeline":[{"event": "Created", "startTimeUtc": "2022-08-29T23:48:50.6901073Z", "durationInMs": 0.016},{"event": "ChannelAcquisitionStarted", "startTimeUtc": "2022-08-29T23:48:50.6901233Z", "durationInMs": 0.0054},{"event": "Pipelined", "startTimeUtc": "2022-08-29T23:48:50.6901287Z", "durationInMs": 0.3199},{"event": "Transit Time", "startTimeUtc": "2022-08-29T23:48:50.6904486Z", "durationInMs": 0.7001},{"event": "Received", "startTimeUtc": "2022-08-29T23:48:50.6911487Z", "durationInMs": 0.0636},{"event": "Completed", "startTimeUtc": "2022-08-29T23:48:50.6912123Z", "durationInMs": 0}],"serviceEndpointStats":{"inflightRequests":1,"openConnections":1},"connectionStats":{"waitforConnectionInit":"False","callsPendingReceive":0,"lastSendAttempt":"2022-08-29T23:48:50.5891152Z","lastSend":"2022-08-29T23:48:50.5900656Z","lastReceive":"2022-08-29T23:48:50.5900656Z"},"requestSizeInBytes":408,"responseMetadataSizeInBytes":173,"responseBodySizeInBytes":87}; 
 ResourceType: Collection, OperationType: Read 
RequestStart: 2022-08-29T23:48:50.6911070Z; ResponseTime: 2022-08-29T23:48:50.6921086Z; StoreResult: StorePhysicalAddress: rntbd://127.0.0.1:10251/apps/DocDbApp/services/DocDbMaster0/partitions/780e44f4-38c8-11e6-8106-8cdcd42c33be/replicas/1p/, LSN: 3202, GlobalCommittedLsn: -1, PartitionKeyRangeId: , IsValid: True, StatusCode: 404, SubStatusCode: 0, RequestCharge: 1, ItemLSN: -1, SessionToken: -1#3202, UsingLocalLSN: False, TransportException: null, BELatencyMs: 0.149, ActivityId: 062b07ce-bfe3-4d38-aed1-8fc917de5ebf, RetryAfterInMs: , TransportRequestTimeline: {"requestTimeline":[{"event": "Created", "startTimeUtc": "2022-08-29T23:48:50.6911070Z", "durationInMs": 0.0034},{"event": "ChannelAcquisitionStarted", "startTimeUtc": "2022-08-29T23:48:50.6911104Z", "durationInMs": 0.0014},{"event": "Pipelined", "startTimeUtc": "2022-08-29T23:48:50.6911118Z", "durationInMs": 0.219},{"event": "Transit Time", "startTimeUtc": "2022-08-29T23:48:50.6913308Z", "durationInMs": 0.8078},{"event": "Received", "startTimeUtc": "2022-08-29T23:48:50.6921386Z", "durationInMs": 0.0516},{"event": "Completed", "startTimeUtc": "2022-08-29T23:48:50.6921902Z", "durationInMs": 0}],"serviceEndpointStats":{"inflightRequests":2,"openConnections":1},"connectionStats":{"waitforConnectionInit":"False","callsPendingReceive":1,"lastSendAttempt":"2022-08-29T23:48:50.6911070Z","lastSend":"2022-08-29T23:48:50.6911070Z","lastReceive":"2022-08-29T23:48:50.5900656Z"},"requestSizeInBytes":408,"responseMetadataSizeInBytes":173,"responseBodySizeInBytes":87}; 
 ResourceType: Collection, OperationType: Read 
, SDK: Microsoft.Azure.Documents.Common/2.14.0
Response headers:
    'Transfer-Encoding': 'chunked'
    'Content-Type': 'application/json'
    'Content-Location': 'https://127.0.0.1:8081/dbs/Cowboys/colls/Bryan1/'
    'Server': 'Microsoft-HTTPAPI/2.0'
    'Access-Control-Allow-Origin': ''
    'Access-Control-Allow-Credentials': 'true'
    'x-ms-activity-id': '062b07ce-bfe3-4d38-aed1-8fc917de5ebf'
    'x-ms-last-state-change-utc': 'Mon, 29 Aug 2022 23:31:58.643 GMT'
    'x-ms-schemaversion': '1.13'
    'lsn': '3202'
    'x-ms-request-charge': '2'
    'x-ms-quorum-acked-lsn': '3202'
    'x-ms-current-write-quorum': '1'
    'x-ms-current-replica-set-size': '1'
    'x-ms-xp-role': '0'
    'x-ms-global-Committed-lsn': '-1'
    'x-ms-number-of-read-regions': '0'
    'x-ms-transport-request-id': '1801'
    'x-ms-cosmos-llsn': '3202'
    'x-ms-cosmos-quorum-acked-llsn': '3202'
    'x-ms-session-token': '0:-1#3202'
    'x-ms-request-duration-ms': '0.353'
    'x-ms-serviceversion': 'version=2.14.0.0'
    'x-ms-gatewayversion': 'version=2.14.0'
    'Date': 'Mon, 29 Aug 2022 23:48:50 GMT'

same one with default policy:

Request URL: 'https://127.0.0.1:8081//dbs/Cowboys/colls/Bryan1/'
Request method: 'GET'
Request headers:
    'Cache-Control': 'no-cache'
    'x-ms-version': 'REDACTED'
    'x-ms-documentdb-query-iscontinuationexpected': 'REDACTED'
    'x-ms-consistency-level': 'REDACTED'
    'x-ms-date': 'REDACTED'
    'authorization': 'REDACTED'
    'Accept': 'application/json'
    'Content-Length': '0'
    'User-Agent': 'azsdk-python-cosmos/4.3.1 Python/3.10.5 (Windows-10-10.0.19044-SP0)'
No body was attached to the request
Response status: 404
Response headers:
    'Transfer-Encoding': 'chunked'
    'Content-Type': 'application/json'
    'Content-Location': 'REDACTED'
    'Server': 'Microsoft-HTTPAPI/2.0'
    'Access-Control-Allow-Origin': 'REDACTED'
    'Access-Control-Allow-Credentials': 'REDACTED'
    'x-ms-activity-id': 'REDACTED'
    'x-ms-last-state-change-utc': 'REDACTED'
    'x-ms-schemaversion': 'REDACTED'
    'lsn': 'REDACTED'
    'x-ms-request-charge': 'REDACTED'
    'x-ms-quorum-acked-lsn': 'REDACTED'
    'x-ms-current-write-quorum': 'REDACTED'
    'x-ms-current-replica-set-size': 'REDACTED'
    'x-ms-xp-role': 'REDACTED'
    'x-ms-global-Committed-lsn': 'REDACTED'
    'x-ms-number-of-read-regions': 'REDACTED'
    'x-ms-transport-request-id': 'REDACTED'
    'x-ms-cosmos-llsn': 'REDACTED'
    'x-ms-cosmos-quorum-acked-llsn': 'REDACTED'
    'x-ms-session-token': 'REDACTED'
    'x-ms-request-duration-ms': 'REDACTED'
    'x-ms-serviceversion': 'REDACTED'
    'x-ms-gatewayversion': 'REDACTED'
    'Date': 'Tue, 30 Aug 2022 00:03:31 GMT'

bambriz added 2 commits July 28, 2022 13:53
A class that gathers useful diagnostics information.
Added system info to diagnostics. This also updates things related to getting exception data for diagnostics
@ghost ghost added Cosmos customer-reported Issues that are reported by GitHub users external to the Azure organization. labels Aug 11, 2022
@ghost
Copy link
Copy Markdown

ghost commented Aug 11, 2022

Thank you for your contribution bambriz! We will review the pull request and get back to you soon.

@ghost
Copy link
Copy Markdown

ghost commented Aug 11, 2022

CLA assistant check
All CLA requirements met.

Centralized diagnostics to client connection and we are now getting diagnostics right after we get a response
Applied diagnostics to async code. Diagnostics should work for async as it does for sync request.
Added consistency leve;, Operation type, and resource type to Cosmos Diagnostics.

Added additional fixes and code cleanup.
Removed left over print statement. Previous update also included query diagnostics.
@bambriz bambriz marked this pull request as ready for review August 23, 2022 20:29
@bambriz bambriz changed the title Draft Code for cosmos diagnostics Cosmos Diagnostics Aug 23, 2022
@sourabh1007
Copy link
Copy Markdown

Please put the whole request diagnostic string in the PR description.

@bambriz
Copy link
Copy Markdown
Member Author

bambriz commented Aug 23, 2022

I added the full text of the response that corresponds to its respective image.

Copy link
Copy Markdown

@jay-most jay-most left a comment

Choose a reason for hiding this comment

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

This isn't the full diagnostic story. Please refer to Java or .Net's implementation.

Comment thread sdk/cosmos/azure-cosmos/azure/cosmos/cosmos_client.py Outdated
@kushagraThapar
Copy link
Copy Markdown
Member

kushagraThapar commented Aug 24, 2022

@bambriz - we should avoid having response body as part of successful request diagnostics. Since the response body is already part of the response, and users can access it directly, it doesn't make sense to include it in the diagnostics.
However, in exception cases, it is totally okay to have the body, since the response body which comes from gateway has useful .Net diagnostics information in it.

For example, for this diagnostics sample, having body doesn't make sense:
image

And actually for requests that end up in exceptions, we should not call the field body, rather exceptionMessage (which should be only present when the exception occurs, and should be absent in case of successful requests):
image

Also, can you please attach the contract of the Diagnostics object? (basically all the fields that it will have and the information that those fields will contain).

@bambriz
Copy link
Copy Markdown
Member Author

bambriz commented Aug 24, 2022

This isn't the full diagnostic story. Please refer to Java or .Net's implementation.

Could you elaborate for me what you mean by the full diagnostic story? I am unsure what you mean by that.

@bambriz
Copy link
Copy Markdown
Member Author

bambriz commented Aug 24, 2022

@bambriz - we should avoid having response body as part of successful request diagnostics. Since the response body is already part of the response, and users can access it directly, it doesn't make sense to include it in the diagnostics. However, in exception cases, it is totally okay to have the body, since the response body which comes from gateway has useful .Net diagnostics information in it.

For example, for this diagnostics sample, having body doesn't make sense: image

And actually for requests that end up in exceptions, we should not call the field body, rather exceptionMessage (which should be only present when the exception occurs, and should be absent in case of successful requests): image

Also, can you please attach the contract of the Diagnostics object? (basically all the fields that it will have and the information that those fields will contain).

I should be able to do this. I will also attach the diagnostic object contract once I make these changes.

Comment thread sdk/cosmos/azure-cosmos/azure/cosmos/cosmos_diagnostics.py Outdated
Copy link
Copy Markdown
Member

@simorenoh simorenoh left a comment

Choose a reason for hiding this comment

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

please also try to add a test file to verify the responses for successful and error scenarios
please also add a small Changelog entry mentioning this revamp of diagnostics
and please add a small section to the README showing how one would use diagnostics for your responses and errors

Comment thread sdk/cosmos/azure-cosmos/azure/cosmos/_synchronized_request.py Outdated
Changed the way we got diagnsotics http data. Instead of the original approach, I am now using the azure core http policy. I made a child class and replaced it in client connection. By default it performs the same, but with a new flag it will include additional information the cosmos diagnostics class would include.
Comment thread sdk/cosmos/azure-cosmos/azure/cosmos/_cosmos_client_connection.py Outdated
Comment thread sdk/cosmos/azure-cosmos/azure/cosmos/_synchronized_request.py Outdated
Comment thread sdk/cosmos/azure-cosmos/azure/cosmos/_cosmos_client_connection.py Outdated
Comment thread sdk/cosmos/azure-cosmos/azure/cosmos/_cosmos_client_connection.py Outdated
Comment thread sdk/cosmos/azure-cosmos/azure/cosmos/_cosmos_client_connection.py
Comment thread sdk/cosmos/azure-cosmos/azure/cosmos/_cosmos_http_logging_policy.py Outdated
Comment thread sdk/cosmos/azure-cosmos/azure/cosmos/_cosmos_http_logging_policy.py Outdated

def on_request(self, request): # type: (PipelineRequest) -> None
if self._diagnostics_mode:
http_request = request.http_request
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Most of this logging looks like it's using the existing implementation, which means maintaining lots of duplicate code.
I would recommend something like:

def on_request(self, request):
    super().on_request(request)
    diagnostics_logging = request.context.setdefault(
        "enable_diagnostics",
        options.pop("enable_diagnostics, self._enable_diagnostics)
    )
    if diagnostics_logging and logger.isEnabledFor(logging.INFO):
        # Add the Cosmos specific stuff here

Copy link
Copy Markdown
Member Author

@bambriz bambriz Aug 30, 2022

Choose a reason for hiding this comment

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

Given the logic of the code, would it make sense to do this? The diagnostics logging includes additional information for headers that the original implementation excludes, then there's also the multirecord option logic. So while the code is very similar it also conflicts with one another. Since we are trying to get all the information we can get while the flag is set, it wouldn't make sense to make the redactions from the original policy. We also did something similar with AAD authentication since the original policy didn't work for what we needed in python cosmos. We made an entirely separate one for that.

Comment thread sdk/cosmos/azure-cosmos/azure/cosmos/cosmos_diagnostics.py Outdated
…ntry, and changelog for new changes

Removed Old cosmos diagnostics code
Added Cosmos Http Logging Policy Test
as well as readme entry and changelog. Other minor fixes.
@check-enforcer
Copy link
Copy Markdown

This pull request is protected by Check Enforcer.

What is Check Enforcer?

Check Enforcer helps ensure all pull requests are covered by at least one check-run (typically an Azure Pipeline). When all check-runs associated with this pull request pass then Check Enforcer itself will pass.

Why am I getting this message?

You are getting this message because Check Enforcer did not detect any check-runs being associated with this pull request within five minutes. This may indicate that your pull request is not covered by any pipelines and so Check Enforcer is correctly blocking the pull request being merged.

What should I do now?

If the check-enforcer check-run is not passing and all other check-runs associated with this PR are passing (excluding license-cla) then you could try telling Check Enforcer to evaluate your pull request again. You can do this by adding a comment to this pull request as follows:
/check-enforcer evaluate
Typically evaulation only takes a few seconds. If you know that your pull request is not covered by a pipeline and this is expected you can override Check Enforcer using the following command:
/check-enforcer override
Note that using the override command triggers alerts so that follow-up investigations can occur (PRs still need to be approved as normal).

What if I am onboarding a new service?

Often, new services do not have validation pipelines associated with them, in order to bootstrap pipelines for a new service, you can issue the following command as a pull request comment:
/azp run prepare-pipelines
This will run a pipeline that analyzes the source tree and creates the pipelines necessary to build and validate your pull request. Once the pipeline has been created you can trigger the pipeline using the following comment:
/azp run python - [service] - ci

database = client.create_database(DATABASE_NAME, logging_enable=True)
```

Alternatively, you can log using the CosmosHttpLoggingPolicy, which extends from the azure core HttpLoggingPolicy, by passing in your logger to the `logger` argument.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The HttpLoggingPolicy is a developer concept - not really an end user concept - so I would not refer to it by name, just discuss the keyword argument.

| CosmosHttpLoggingPolicy | SansIOHTTPPolicy | | | | |
| | | logger | X | X | If specified, it will be used to log information. |
| | | enable_diagnostics_logging | X | X | Used to enable logging additional diagnostic information. Defaults to `False` |
You can learn more about the different policies and how they work [here](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/core/azure-core/CLIENT_LIBRARY_DEVELOPER.md#available-policies)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would remove this line and the table above.

self._enable_diagnostics_logging = kwargs.pop("enable_diagnostics_logging", None)
super().__init__(logger, **kwargs)
if self._enable_diagnostics_logging:
self.logger = logger or logging.getLogger(__name__)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why do we need this alternative logger?

return

try:
parsed_url = list(urllib.parse.urlparse(http_request.url))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We shouldn't duplicate this section of code - could you point out where this deviates from the original implementation so we can figure out the best way to accommodate it?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same comment applies to response handling.

# Get logger in my context first (request has been retried)
# then read from kwargs (pop if that's the case)
# then use my instance logger
logger = request.context.setdefault("logger", options.pop("logger", self.logger))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why is this only done in the case of enable_diagnostics_logging?

@@ -0,0 +1,133 @@
# ------------------------------------
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks like an image file was accidentally committed?

@simorenoh simorenoh closed this Sep 6, 2022
@simorenoh
Copy link
Copy Markdown
Member

Closed PR since this is not the solution we're going with.

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

Labels

Cosmos customer-reported Issues that are reported by GitHub users external to the Azure organization.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants