Skip to content

allow for metric value class customization#1158

Open
mpnowacki-reef wants to merge 3 commits intoprometheus:masterfrom
reef-technologies:metric-value-class-customization
Open

allow for metric value class customization#1158
mpnowacki-reef wants to merge 3 commits intoprometheus:masterfrom
reef-technologies:metric-value-class-customization

Conversation

@mpnowacki-reef
Copy link

No description provided.

Comment on lines +700 to +704
def test_env_var_value_class(self):
# We need a class to point to. Let's use MutexValue itself but via string
os.environ['PROMETHEUS_VALUE_CLASS'] = 'prometheus_client.values.MutexValue'
importlib.reload(values)
self.assertEqual(values.ValueClass, values.MutexValue)

Choose a reason for hiding this comment

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

This doesn't test anything because MutexValue is the default. Better point at something non-default, maybe to values.MmapedValue or even some random class from stdlib (we won't use it anyway, just need to check assignment)

module = importlib.import_module(module_path)
return getattr(module, class_name)
except (ImportError, AttributeError) as e:
raise ImportError(f"Could not import PROMETHEUS_VALUE_CLASS '{value_class_path}': {e}") from None

Choose a reason for hiding this comment

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

Suggested change
raise ImportError(f"Could not import PROMETHEUS_VALUE_CLASS '{value_class_path}': {e}") from None
raise ImportError(f"Could not import PROMETHEUS_VALUE_CLASS '{value_class_path}'") from e

Copy link
Member

@csmarchbanks csmarchbanks left a comment

Choose a reason for hiding this comment

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

Can you describe your use case here a bit more? My initial reaction is that this is too complicated/niche to be supported by this client but I am happy to learn more.

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