Skip to content
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

Refactor frontend logging #926

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open

Refactor frontend logging #926

wants to merge 13 commits into from

Conversation

mbarnes
Copy link
Collaborator

@mbarnes mbarnes commented Dec 4, 2024

What this PR does

I wanted to make what I thought was a small change to the frontend logs (essentially the last commit here). But when I realized the logger attribute I added ("api_version") was not showing up in logs, the ensuing investigation led me down a rabbit hole that resulted in some major logging refactoring.

Note: This extends #920, which is still outstanding, so its commits are duplicated here until it's merged. Only the last 3 commits are unique to this pull request.

@mbarnes mbarnes force-pushed the frontend-logging branch 2 times, most recently from dc243b6 to b9ff0c4 Compare December 4, 2024 17:02
@mbarnes mbarnes marked this pull request as ready for review December 6, 2024 13:48
@mbarnes mbarnes enabled auto-merge December 6, 2024 17:00
Copy link

Please rebase pull request.

Matthew Barnes added 13 commits December 17, 2024 14:18
Works for any document type now, and just stores a slice rather
than the entire cache for that document type.
A new function NewQueryItemsSinglePageIterator alters the behavior
of QueryItemsIterator to stop after the first "page" of items and
record the Cosmos DB continuation token. The continuation token
can be retrieved from the iterator with GetContinuationToken.

A QueryItemsIterator created with NewQueryItemsIterator will never
have a continuation token because it iterates until the last item.

The in-memory cache also adds a GetContinuationToken method to its
iterator implementation to fulfill the interface contract, but it
always returns an empty string.
For CosmosDBClient, the maxItems argument controls the type
of iterator returned. A positive maxItems returns a single-
page iterator with a possible continuation token, otherwise
the iterator continues until the last item.

Since the in-memory cache does not have continuation tokens,
the maxItems argument is ignored.

This also drops the resourceType argument. Callers first need to
parse the iterator items into resource documents before checking
the resource type.
Add "externalID" and "internalID" parameters so the returned
document is a minimum valid OperationDocument for writing.
The operation item must now be created in the database prior to
calling ExposeOperation. ExposeOperation does all its processing
in a database update callback.

This is because there is an increasing number of cases where we
create an implicit async operation with no visible status endpoint.
Calling ExposeOperation makes an implicit async operation explicit,
with a status endpoint for ARM to poll. Hence the rename.

The tradeoff is explicit asyncrhonous operations now require two
database operations (create and update) but it helps make the RP
logic cleaner. This could possibly be mitigated in the future by
using Cosmos DB's transactional batch operations, but it's gonna
take some serious refactoring to get there.
CancelActiveOperation marks the status of any active operation on
the resource as canceled.
Will be reusing DeleteResource for subscription deletion.

Add database bookkeeping for the resource and any child resources.
This includes creating implicit operations for each resource being
deleted. The caller may then expose the returned operation ID.
By my read of the Subscription Lifecycle API Reference [1], we
should favor 200 OK over 201 Created when creating or updating
a subscription.

[1]
https://github.com/cloud-and-ai-microsoft/resource-provider-contract/blob/master/v1.0/subscription-lifecycle-api-reference.md#response
Called when a subscription is deleted. The method is idempotent in
case of multiple subscription PUT requests.
Don't count on OperationID being set in OperationDocuments.
Implicit async operations will not have this field set. Get
the subscription ID from ExternalID instead.
LoggerFromContext will never fail now.

Middleware functions were falling back to the default logger, but
we do this from within LoggerFromContext now so the fallback logic
doesn't have to be repeated everywhere.
Always retrieve the logger from the request context. This ensures
we're using the correct logger in case middleware functions add a
logging attribute.
Add a logger attribute for the request's "api-version" parameter
from MiddlewareValidateAPIVersion.

Also remove the "<api-version>: <function-name>" log messages from
the HTTP handler methods. I added these messages when the handlers
were no more than stubs to test request routing but they no longer
add value to the frontend logs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant