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
Adding 'namespace' for prometheus metrics #13738
Conversation
@@ -93,7 +101,8 @@ def _metric(self, metric, factory, documentation, labels=None): | |||
try: | |||
return self._metrics[metric] | |||
except KeyError: | |||
self._metrics[metric] = factory(metric, documentation, labels) | |||
full_metric_name = "%s_%s" % (self.metrics_namespace, metric) | |||
self._metrics[metric] = factory(full_metric_name, documentation, labels) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line too long (84 > 79 characters)
This changes includes the information required about the new configuration parameter introduced in home-assistant/core#13738
CONFIG_SCHEMA = vol.Schema({ | ||
DOMAIN: recorder.FILTER_SCHEMA, | ||
DOMAIN: recorder.FILTER_SCHEMA.extend({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the origin filter schema from https://github.com/home-assistant/home-assistant/blob/dev/homeassistant/helpers/entityfilter.py
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't know that there was a helper for that :) I believe that the following commit addresses what you asked?
I messed up a little bit at the middle (I was not in my main development machine, and did some silly mistakes). While looking into other components and seeing the entity_filter helper, I felt that moving the filter into its own entry in the settings is a better approach. That means more breaking changes, although the code is easier to mainteinance. The settings will be like this:
Although the default
will keep working because everything else is optional. I will update the documentation PR accordingly |
@pvizeli I think that the changes done were the ones you were requesting. Could you confirm that it looks good? At least that specific aspect. |
No my change request are the same: https://github.com/home-assistant/home-assistant/blob/3fd61d8f456f14796e41dc05c77a7ab60861eb84/homeassistant/components/alexa/__init__.py#L34 You should not access to a other component from your componenent. That break the interface logic they we use. As next, with the helper, we can provide a config feature they work over multible component in same way. We need migrate all the old ways to this helper. |
I don't understand... Are you refering to an alexa component? I only touched Prometheus stuff... in fact, your change request was related to a stuff that was already there (but given that I was changing that part, it was the moment to fix it). I think that there is no reference to other component, or I am missing something. |
CONF_PROM_NAMESPACE = 'namespace' | ||
PROM_NAMESPACE = 'hass' | ||
|
||
CONFIG_SCHEMA = vol.Schema({ | ||
DOMAIN: FILTER_SCHEMA.extend({ | ||
DOMAIN: vol.All({ | ||
vol.Optional(CONF_FILTER, default={}): entityfilter.FILTER_SCHEMA, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pvizeli This is what you asked, isn't it? Using the entityfilter.FILTER_SCHEMA
at this point (instead of the previous other-component-stuff-that-may-break).
Could you please update the dependency ( |
@fabaff Updated to Main functionality is working as expected --let me remind that there are breaking changes on the naming of metrics, albeit I defend that there is "a greater good" behind the rename. I don't know why coveralls is complaining now (or at all). Maybe it has to do with my f*** up when I started on the wrong branch? (shame on me). |
You can ignore coveralls. It has already been fixed upstream. You removed the PR instructions that you need to follow to get Travis to pass… run |
DOMAIN: recorder.FILTER_SCHEMA, | ||
DOMAIN: vol.All({ | ||
vol.Optional(CONF_FILTER, default={}): entityfilter.FILTER_SCHEMA, | ||
vol.Optional(CONF_PROM_NAMESPACE, default=PROM_NAMESPACE): cv.string, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should make it have no default and not add it if not provided.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you mean that the metrics name, by default, should not have application prefix at all? The reason for that is to have the "previous" (current, actual) behaviour of prometheus component by default?
I redid the branch because there were so many mistakes on my part that commit history was a mess. @pvizeli I think that I addressed your issues at a certain point but that was not clear. On the new commits, if 72351dc is not what you were asking, then please tell me so because that means that I still not know what to change :( That commit is in fact unrelated to the purpose of this PR, but it was a good moment to improve it. @balloob I assumed that you wanted to have no default and, if no The breaking changes are related to the use of |
Is this PR good to go? Or it still has issues? |
* Add information for the namespace option This changes includes the information required about the new configuration parameter introduced in home-assistant/core#13738 * Nesting include/exclude into filter directive * ✏️ Language tweaks * Reflecting the optionality of namespace setting
* Updating prometheus client version * Using `entity_filter` as filter mechanism * New optional `namespace` configuration
Description:
Add a "namespace" for all the component metrics. This is a breaking change, motivated by "official best practices" see Prometheus documentation
The code could be tweaked to be non-breaking. IMHO, it is more sane and well-organized to force a top-level namespace and share that by all the metrics --instead of starting the metric name by the hass domain-- but it is arguably the best approach. Before adding the documentation I wanted to discuss that and listen to other opinions. If there is consensus in a different solution, I have no problem modifying this PR to follow the guidelines.
Example entry for
configuration.yaml
(if applicable):Result:
Going to http://hass.example.net:8123/api/prometheus shows:
Checklist:
tox
. Your PR cannot be merged unless tests pass