azure-cosmos-dotnet-repository icon indicating copy to clipboard operation
azure-cosmos-dotnet-repository copied to clipboard

Provide the RU's used by an operation

Open SeanFarrow opened this issue 2 years ago • 9 comments

I'm just starting to use this to replace a self-written interface to Cosmos.

The one thing my current interface gives me is the RU cost of an operation.

Could this be surfaced in some way through the repository interface(s)?

The Two options I can think of currently are introducing an ItemWrapper, rather than IItem--although you may want to keep this as it is useful, or extending IItem itself.

To my thinking the former is the better option, kind of like an HttpResponse.

SeanFarrow avatar May 13 '22 06:05 SeanFarrow

Hi @SeanFarrow we do support this for some of the paging APIs. I think we could start logging this out if that is any help? We do in places but I think they are logged at Debug level.

mumby0168 avatar May 13 '22 20:05 mumby0168

@mumby0168 I suspected the information I wanted would be in the logs.

I'm using AppInsights, so use TelemetryClient to track this as a specific metric. in terms of a solution to this, I can see two options: Firstly, to change the signature of a method to provide the RU cost in the return value, which I don't think would make sense. Or, have an out parameter on each method that provides the RU cost. Doing this would mean a user who isn't interested in this could discard that parameter.

I am right in that the second would make more sense? Or, do you have any other options?

SeanFarrow avatar May 16 '22 04:05 SeanFarrow

Hi @SeanFarrow we would not want to modify the public API surface I do not think. So I don't think either the out parameter or the return type would work in this case. One option might be a set of new methods to all existing methods that allow you to collect the cost. But they would have to be new methods with new names. If we was to do that, I think I would prefer the return type option. out params can be a pain when using mocking libraries.

mumby0168 avatar May 18 '22 11:05 mumby0168

This seems like a cross-cutting concern - might it somehow be managed with an enclosing scope or wrapper class? Perhaps our core impl adds an pub/sub notification model using something like Mediatr for telemetry metrics of interest, including RUs, then those consumers that care can subscribe to those. That way it could be pay-to-play without adding complexity to the core API.

dcuccia avatar May 18 '22 14:05 dcuccia

I was thinking exactly this, maybe have an IMetricsTracker interface that can be passed in (but defaults to null if you don’t), then consumers that want this can implement there own. Of course we might want to provide implementations ourselves.

From: dcuccia @.> Sent: 18 May 2022 15:47 To: IEvangelist/azure-cosmos-dotnet-repository @.> Cc: Sean Farrow @.>; Mention @.> Subject: Re: [IEvangelist/azure-cosmos-dotnet-repository] Provide the RU's used by an operation (Issue #275)

This seems like a cross-cutting concern - might it somehow be managed with an enclosing scope or wrapper class? Perhaps our core impl adds an pub/sub notification model using something like Mediatr for telemetry metrics of interest, including RUs, then those consumers that care can subscribe to those. That way it could be pay-to-play without adding complexity to the core API.

— Reply to this email directly, view it on GitHubhttps://github.com/IEvangelist/azure-cosmos-dotnet-repository/issues/275#issuecomment-1130112587, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AALDK7XXVQGWSOSBU3T4PG3VKT7IDANCNFSM5V2MUPGQ. You are receiving this because you were mentioned.Message ID: @.***>

SeanFarrow avatar May 18 '22 15:05 SeanFarrow

@SeanFarrow @mumby0168 if we published Mediatr-style events such as those demoed here:

https://youtu.be/NmmpXcMxCjY?t=665

...then the consuming code could follow a wrapper pattern like this:

https://www.youtube.com/watch?v=dLPKwEeqwgU&t=705s

(using Nick Chapsas videos as shortcuts...could publish some sample code when I have time this weekend)

dcuccia avatar May 20 '22 20:05 dcuccia

Hi, was this ever added? I see RUs in logs but I would like to access them programmatically.

karpikpl avatar Jan 28 '23 05:01 karpikpl

@all-contributors please add @SeanFarrow for idea

IEvangelist avatar Apr 06 '23 13:04 IEvangelist

@IEvangelist

I've put up a pull request to add @SeanFarrow! :tada:

allcontributors[bot] avatar Apr 06 '23 13:04 allcontributors[bot]