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

Laravel cache adapter #32

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

Conversation

pselge-5anker
Copy link
Contributor

This PR adds a laravel cache adapter, to leverage all of the laravel cache storage implementations.
I manually tested it with the database, redis, file and array drivers.

I'll provide programmatic tests asap, I just need to read up on Pest first.

Copy link
Member

@freekmurze freekmurze left a comment

Choose a reason for hiding this comment

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

Ping me when tests have been added 👍

src/Adapters/LaravelCacheAdapter.php Outdated Show resolved Hide resolved
src/Adapters/LaravelCacheAdapter.php Show resolved Hide resolved

private const CACHE_KEY_SUFFIX = '_METRICS';

private const STORES = [Gauge::TYPE, Counter::TYPE, Histogram::TYPE, Summary::TYPE];
Copy link
Member

Choose a reason for hiding this comment

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

Refactor this to a regular array.

Copy link
Member

Choose a reason for hiding this comment

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

In fact the rest of the const, can be refactored the regular protected properties as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

what do you mean by regular array?
as a property instead of a const?

src/Adapters/LaravelCacheAdapter.php Outdated Show resolved Hide resolved
src/PrometheusServiceProvider.php Outdated Show resolved Hide resolved
Copy link
Member

@freekmurze freekmurze left a comment

Choose a reason for hiding this comment

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

Some small nitpicks

@@ -43,4 +43,17 @@
* Allow storage to be wiped after a render of data in metrics controller.
*/
'wipe_storage_after_rendering' => false,

/**
Copy link
Member

Choose a reason for hiding this comment

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

Could you make this doc block smaller. Only 1 or 2 sentences. Move the rest of the explanation to a new section in the readme.


class LaravelCacheAdapter extends InMemory
{
protected string $cacheKeyPrefix = 'PROMETHEUS_';
Copy link
Member

Choose a reason for hiding this comment

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

Let's make these values less "screamy" by using a lowercase value.


protected function cacheKey(string $type): string
{
return $this->cacheKeyPrefix.$type.$this->cacheKeySuffix;
Copy link
Member

Choose a reason for hiding this comment

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

Use string interpolation here.

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.

None yet

2 participants