eko / gocache

☔️ A complete Go cache library that brings you multiple ways of managing your caches
https://vincent.composieux.fr/article/i-wrote-gocache-a-complete-and-extensible-go-cache-library/
MIT License
2.46k stars 195 forks source link

support custom prometheus registry #145

Closed jack-evans closed 1 year ago

jack-evans commented 2 years ago

Steps for Reproduction

Currently, the prometheus metrics implementation for the cache only supports the use of the default registerer. This introduces global state into peoples applications and makes it difficult for people with custom registerers to use the prometheus metrics implementation.

Expected behavior:

allow people the option of using a custom metrics registry

Actual behavior:

No metrics for people using a custom prometheus metrics registry

Platforms:

Include browser, operating system and respective versions

Versions:

Which versions are you running?

eko commented 1 year ago

Hi, you can now set a custom Prometheus registry, namespace and channel using the following options:

    serviceName := "my-test-service-name"

    customNamespace := "my_custom_namespace"
    customRegistry := prometheus.NewRegistry()
    customChannel := make(chan codec.CodecInterface, 100)

    // When
    metrics := NewPrometheus(
        serviceName,
        WithCodecChannel(customChannel),
        WithNamespace(customNamespace),
        WithRegisterer(customRegistry),
    )

I close this issue for now but feel free to reopen if you still have any issue.

Thank you