Skip to content

#168 support for client metrics - #169

Merged
nicoloboschi merged 6 commits into
diennea:masterfrom
dmercuriali:168-client-metrics
Jun 21, 2021
Merged

nicoloboschi merged 6 commits into
diennea:masterfrom
dmercuriali:168-client-metrics

Conversation

@dmercuriali

@dmercuriali dmercuriali commented Jun 16, 2021 •

Copy link
Copy Markdown
Contributor

Added a MetricsProvider interface so that an application can pass it's implementation to che CacheClient (by standard constructor or builder).
The application should provide it's implementation of the Gauge interface, which represents the actual metric. A gauge can be added to, subtracted from and be resetted.
If no MetricsProvided is provided by the application, a standard no-op NullMetricsProvider is used.

The Gauge implementation will also receive the entry key which triggered the metric update so that it may take decisions based on that (ex. manage metric labels). The entry key is passed in RawString format to avoid a useless toString invokation if the entry key is not needed by the implementation.
If an entry key is not available (ex. invalidateByPrefix), null is passed.

The exposed metrics are:

  • blazingcache.client.puts > number of put operations

  • blazingcache.client.loads > number of load operations

  • blazingcache.client.touches > number of touch operations

  • blazingcache.client.gets > number of get operations

  • blazingcache.client.fetches > number of fetch operations

  • blazingcache.client.evictions > number of eviction operations

  • blazingcache.client.invalidations > number of invalidate operations

  • blazingcache.client.hits > number of cache hits

  • blazingcache.client.gets.miss.fetchhit > number of cache misses, followed by a fetch hit

  • blazingcache.client.gets.miss.fetchmiss > number of cache misses, followed by a fetch miss

  • blazingcache.client.memory.actualusage > current memory usage as bytes

  • I hereby declare this contribution to be licenced under the Apache License Version 2.0, January 2004

@dmercuriali
dmercuriali marked this pull request as ready for review June 16, 2021 09:49

@eolivelli eolivelli left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

interesting work !

@dmercuriali

Copy link
Copy Markdown
Contributor Author

Updated the PR so that blazingcache passes the entry key which triggered the metric update to the update methods of the Gauge (inc, dec, add).
This way an implementation can take decisions based on the entry key (ex. extract metric label from it)

@dmercuriali
dmercuriali requested a review from eolivelli June 17, 2021 09:43

@eolivelli eolivelli left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I am not a fan of the latest change, I left a comment

*
* @param entryKey key of the entry which triggered this event. Might be {@code null}
*/
void inc(RawString entryKey);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I have never seen this before in a Metrics system.
why are you doing this ?
because you want to track per-key metrics ?

this way it does not look like a Metrics system but it is more like a callback/hook mechanism

this is quite dangerous because the metrics provider should be as light weight as possible and it must not impact the execution of BC code.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We have a multi tenant system where a single cacheclient is used for multiple tenants. To differentiate a cache entry of one tenant from the same entry of another tenant we add a prefix to the actual key.

In blazing cache we end up with something like
tenant1code#entrykey1
tenant2code#entrykey1

We would like to be able to track per-tenant metrics, but this 'tenantcode' extraction should be done by the application, not blazing cache.
With this implementation we can receive the entrykey, extrapolate the code, and log the event on a labeled metric.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What about naming this class GaugeSet ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If you think it's best, I can revert the last changes (go back to the simple gauge without the RawString param) and create a new issue for implementing a hook mechanism so that we can manage the per-tenant labeled metrics directly in our application.
Still, for our use case, we would need a hook on every operation that is now tracked by the metrics and i fear that it might bloat the code more than the parameterized gauge.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

IMHO we can keep this change, just renaming Gauge to GaugeSet

@dmercuriali

Copy link
Copy Markdown
Contributor Author

Renamed Gauge to GaugeSet

@nicoloboschi nicoloboschi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@nicoloboschi
nicoloboschi merged commit 404986b into diennea:master Jun 21, 2021
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.

3 participants