Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Collect methods uses replacing prefix behaviour with unexpected behaviour #182

Closed
@heahoh

Description

@heahoh

Hi!

Got problem when using counters for future exponsing for prometheus with Redis adapter

Scenario
I've has config with redis prefix ($redis->setOption(\Redis::OPT_PREFIX, 'a'))
Increment some counter via lib getOrCreateCounter('space', 'name', 'help')->inc()
In redis db counter persisted in similiar name - aPROMETHEUS_counter_METRIC_KEYS, and hash table - aPROMETHEUS_:counter:space_name
Want to get all metrics via controller $registry->getMetricFamilySamples() but got no samples in result

With debug I found strange code - $raw = $this->redis->hGetAll(str_replace($this->redis->_prefix(''), '', $key));
That str_replace in total will replace all symbols a with emptyness - so I got PROMETHEUS_:counter:spce_nme instead of PROMETHEUS_:counter:space_name

I think possible solution is use ltrim($key, $this->redis->_prefix('')) instead of str_replace

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions