-
Notifications
You must be signed in to change notification settings - Fork 2
Conversation
This is definitely great start. We can discuss the RBAC, but having API client free of OpenStack specific logic sounds fine to me. |
As was discussed on our meeting, I will:
|
This commit adds: - commands: delete clear-tombstones snapshot - Better rbac injection as well as a possibility to disable rbac. - Configuration of prometheus_client through env variables and /etc/openstack/prometheus.yaml It also does some further cleanup. It makes the list and show commands use our prometheus client in prometheus_client.py
I incorporated the changes we talked about. The changes include mainly:
It also does some further cleanup. It makes the list and For the RBAC I'm including a label {project_id='some_id'} after each metric name in each query. The PromQL is quite specific about where labels can be placed, so before injecting the RBAC into the user's query, I'm querying prometheus to find out all of the metric names, so that I can find them inside the query. If we don't want to do this additional query we would probably need to restrict what kind of user queries we support or implement a proper PromQL parser (one can be seen here). During the development, I encountered a few things, on which I'd like to know your opinion.
|
I also wanted to add a "create" command similarly to the gnocchi client, but there isn't an endpoint in prometheus for creating metrics. |
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.
Few points for discussion, but otherwise this is legit.
observabilityclient/v1/rbac.py
Outdated
|
||
def _enrich_labels(self, labels, disable_rbac): | ||
if not self.rbac_init_successful and not disable_rbac: | ||
raise ObservabilityRbacError("Unauthorized. Couldn't " |
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.
Wouldn't it be better to fail in constructor rather than later in the process when enriching is used?
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.
This is what I initially implemented, but then I figured, that there is a possibility to disable rbac with each function/command. So even if the constructor can't find the project_id, you should still be able to do openstack metric list --disable-rbac
. That's why I moved the exception from the constructor to here.
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.
Now, that I know, that even the openstack command is able to log, I'll at least log a warning in the constructor.
observabilityclient/v1/rbac.py
Outdated
return labels | ||
|
||
# TODO aren't the additional labels just making | ||
# the code confusing? Are they useful? |
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.
My 2cents: Maybe and No. User can construct whatever query with various labels in it, so I personally don't see a point of having additional parameters for additional parameters.
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 agree, I removed the code
It seems to me that this library is not available downstream (at least it's not obvious from list of Brew builds). Checking on OSP deployment @lnatapov has on seal31 it confirms that we don't have that package (no python-pyyaml nor python3-pyyaml nor PyYAML). So if you can't achieve same with standard YAML lib, we would need to package and ship it ourselves.
Hardcoding paths in case of configuration is fine, but I would add more option and ideally consistent options with the rest of the client: https://github.com/openstack/python-openstackclient/blob/7ea78b6ef65481c8e97bac959b4f11e3ecae8a3e/doc/source/cli/man/openstack.rst#config-files
That is a good question. If we are sure enough that the query enriching mechanism allows most of the queries (which to me it seems so), I would say that only admin users should be able to fetch metrics of any project.
If we want to have an outupt of show command consistent with the past, then I would keep it as it is now (eg. accepting just metric name). Having a query command to display something like max_over_time(ceilometer_image_size{resource='abcd'}[15m]) for example shoud be a purpose of query command and indeed will be used for autoscaling.
By admin users maybe, yes.
As I wrote in comments, this seems unnecessary to me. |
I don't think there is a standard yaml lib in python (if there is, please correct me). But I don't think we need to package it just because of this. If the config file doesn't get much more complex, it should be pretty easy to just parse it by ourselves. Using regexes, it's probably just a few lines of code. |
YAML library is being distributed in two forms. One is a C-binding to libyaml which usually is part of Python distribution and then you can have pure Python implementation which we would have to package. Not that I would know that fact yesterday, but I never had to install additional package to be able to |
I've implemented Martin's comments.
I also discovered, that label values can be any unicode character, which would break the current rbac implementation if "}" is a part of a label value. Fix for that will follow shortly. |
I added a support for unicode label values, which wouldn't work before. The rbac is getting quite complex. What I tried seemed to work. I'll come up with some extensive unit tests to make sure it really does what it should. I'm leaving for 2 weeks vacation. I feel like I implemented most of what Martin noted, and there aren't any other reviews here right now. My suggestion is to merge this (unless somebody sees something awful here), so that Martin can start using it in his aodh evaluator. Please leave notes/reviews here, or somewhere else. I'm planning to take a look at them when I'm back and open another PR with them. |
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.
My review was centered around using a better command than "observabilityclient" from the cli. As we agreed on the meeting, re-use "metrics" is perfectly fit.
This PR adds initial functionality to interact with prometheus.
There are 2 parts to the client. First adds a library to query prometheus from python, this can be used from a future aodh prometheus evaluator. The second part uses this to interact with prometheus from cli. Examples of both can be seen in the README. Kudos to @paramite for the prometheus_client.py
There are a few questions regarding the future development:
Which cli commands (if any) do we want to support?
Right now I added the list, show and query commands. I think it might be useful to replicate at least some of the basic
openstack metric
commands. Only the query command uses the PrometheusAPIClient right now. If we want to keep list and show, it'll need to be slightly modified. (list and show use the prometheus-api-client library, which we decided not to use because of packaging difficulties)Where do we want to enforce the RBAC?
There is a class
PrometheusRBAC
prepared in prometheus_client.py. But I think it might be better to decouple openstack specific logic from prometheus_client.py. We could put the code for that into QueryManager.query, where it is right now (although it would need to be a bit more robust).Where do we get the host and port for prometheus?
It seems to me like the other openstack plugins just ask keystone for this information, but keystone doesn't know anything about prometheus. It could be specified as a parameter by whoever is creating the client from the python library. In case of cli, we could add --host and --port args. Right now it's hardcoded to 127.0.0.1:9090