7

Currently I'm writing a program that can estimate the costs of an Azure application. For this I have the idea to intercept all the methods that will do (indirectly) a call to the (Azure) server. And for each of the methods decide to which aspect of the costs it belongs to (for example (storage-transactions, servicebus-transactions, token-requests etc.))

One of the difficulties of this is that I also want to intercept a method call when the class/method is mocked, so the program can also be used in (unit-)tests during the development of an Azure application.

So I was wondering if there is a way to 'subscribe' on a method of a class. And when this method is called an event will be fired. Or are there other (better) solutions to intercept storage-transactions, servicebus-transactions, token-request etc. also for classes that send for example a storage-transactions but are mocked?

Thanks in advance

EDIT 1: Does anyone know if there are some (helper) classes/libraries or references that contains/knows all the classes/methods that influences the Costs of an Azure application?

EDIT 2 Is this a good approach to achieve above problem? Or are there alternatives?

mrtentje
  • 1,402
  • 2
  • 22
  • 43
  • 1
    Not all calls are created equal, so you may find it difficult to establish a per-call cost basis. – Dave Swersky Dec 19 '12 at 22:02
  • 2
    To expand on Dave's comment, a call to a .ToList on a table service query could create many calls to the underlying REST API depending on how many rows are returned and the larger part of the cost could be data transfer costs depending on whether it's running in the same data center or not – knightpfhor Dec 20 '12 at 17:28
  • you can easy log application run. In google and our form are a lot of informations about this – TN888 Jan 09 '13 at 19:05

7 Answers7

3

You're referring to Aspect Oriented Programming (AOP.) AOP deals with intercepting dispatch messages between objects and their methods and properties. Logic may be executed that depends on the content of the calls.

Here's a question on AOP frameworks in .NET:

What is the best implementation for AOP in .Net?

Community
  • 1
  • 1
Dave Swersky
  • 34,502
  • 9
  • 78
  • 118
3

Create an HTTP proxy and have your application go through that proxy. That way you can really intercept each request to Windows Azure Storage / Service Bus / ...

While AOP is a good solution, it won't fit your needs. Take the CloudBlob.UploadFile method for example. From an AOP perspective this is a single call, but if you look at the number of HTTP transactions this can be a lot more than 1 call (large files are chunked and sent over multiple HTTP requests).

That's why you need to use something low level like an HTTP proxy if you want to monitor all calls to Windows Azure services.

Sandrino Di Mattia
  • 24,739
  • 2
  • 60
  • 65
  • Does it matter though if it's more than one HTTP call? What he should be measuring is the cost for each call from his code (in terms of time and processor spent), not necessarily the underlying details. Personally I would just use the Visual Studio code profiler to get a general sense, but it's only available in the Ultimate version AFAIK. ANTS Profiler would also work. – Matt Kerr Jan 08 '13 at 18:06
  • That's not the question. He clearly states that he wants to measure the Azure related cost, not the time/CPU cost. – Sandrino Di Mattia Jan 08 '13 at 18:24
  • Thanks for your answer. I've been prototyping with the http-proxy solution for a while... And I have a question how to track Azure TSQL and SQL Reporting services from Azure. Same thing with Service Bus (not everything in service bus results in a http (REST) call). Do you know how to tracks these? Eventual you can contact me by mail (see profile). – mrtentje Feb 17 '13 at 20:41
0

You may be able to use dynamic proxy to generate classes that intercept the calls to the underlying objects, record details about the call and then forward them.

I'm not exactly sure how you'd wire it all up, but hopefully this will get you going in the right direction.

Jason
  • 15,915
  • 3
  • 48
  • 72
  • I also don't know how I will wire up this all... but this is my first and only idea to implement this... Do you know if there are some Azure specific helper classes that might help me with this? – mrtentje Dec 19 '12 at 21:39
0

You're looking for an aspect-oriented solution. Something like PostSharp should work for you. I've used it with good success. Not sure if there are other free options available.

Jerod Venema
  • 44,124
  • 5
  • 66
  • 109
  • 1
    Castle Dynamic Proxy is another one: http://www.castleproject.org/projects/dynamicproxy/ Spring.NET has an AOP part: http://www.springframework.net/doc-latest/reference/html/aop.html – Matt Kerr Jan 08 '13 at 17:59
0

We use the Trace API to track method calls - I'd recommend reading Using Trace in Windows Azure Cloud Applications. Once you have the data captured in Azure Tables, it is easy to report on the data you are tracking (similar to diagnostics reporting).

viperguynaz
  • 12,044
  • 4
  • 30
  • 41
  • This solution solves the problem to identify which methods are Azure specific. But works this problem also for classes/methods that are mocked? (Like for example MoQ) – mrtentje Jan 09 '13 at 16:55
  • for mocks - you would have to get trace logs from the machine you are running tests on/ – viperguynaz Jan 09 '13 at 17:45
0

I did some work on what I consider Modern C# design, including proxy generation and dynamic method invocation based on interfaces. The blog explains how it works and how to use it.

I'm pretty sure that this works for your scenario.

The relevant link can be found:

Decorator proxies

and the more generic dynamic method invocation can be found:

Dynamic method invocation

atlaste
  • 30,418
  • 3
  • 57
  • 87
  • The only problem I am facing with this solution is that I have to identify all the cost related methods of Azure... – mrtentje Jan 09 '13 at 16:58
0

You can create log file. Write time and error or reaction. This is good solution. Half I ?

TN888
  • 7,659
  • 9
  • 48
  • 84