forked from openstack/nova
-
Notifications
You must be signed in to change notification settings - Fork 10
Add prometheus exporter for nova-bigvm #388
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
Open
leust
wants to merge
1
commit into
stable/xena-m3
Choose a base branch
from
bigvm_exporter
base: stable/xena-m3
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| # Copyright 2022 SAP SE | ||
| # All Rights Reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
| # not use this file except in compliance with the License. You may obtain | ||
| # a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
| # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
| # License for the specific language governing permissions and limitations | ||
| # under the License. | ||
| from oslo_log import log as logging | ||
| from prometheus_client import CollectorRegistry | ||
| from prometheus_client import Counter | ||
| from prometheus_client import Gauge | ||
| from prometheus_client import start_http_server | ||
|
|
||
| import nova.conf | ||
|
|
||
| CONF = nova.conf.CONF | ||
|
|
||
| LOG = logging.getLogger(__name__) | ||
|
|
||
| REGISTRY = CollectorRegistry(auto_describe=True) | ||
|
|
||
| ERROR_FREEING = 'freeing' | ||
|
|
||
|
|
||
| class _BigVmPrometheusMetrics: | ||
|
|
||
| def __init__(self, registry): | ||
| self.host_errors_counter = \ | ||
| Counter('nova_bigvm_host_errors', | ||
| 'Counts errors that happened while reconciling ' | ||
| 'a host. The "error" is a short code meaning: ' | ||
| 'freeing = Error while freeing up a host', | ||
| labelnames=['error', 'vc', 'host', 'rp'], | ||
| registry=registry) | ||
|
|
||
| self.no_candidate_error_counter = \ | ||
| Counter('nova_bigvm_no_candidate_error', | ||
| 'Counter that increments each time the ' | ||
| 'reconciliation loop cannot find a ' | ||
| 'resource-provider for freeing-up a host.', | ||
| labelnames=['hv_size'], | ||
| registry=registry) | ||
|
|
||
| self.host_freeing_up_gauge = \ | ||
| Gauge('nova_bigvm_host_freeing_up', | ||
| 'Gauge for each BigVM host that is currently ' | ||
| 'being freed up.', | ||
| labelnames=['vc', 'host', 'rp'], | ||
| registry=registry) | ||
|
|
||
| self.free_hosts_count_gauge = \ | ||
| Gauge('nova_bigvm_free_hosts_count', | ||
| 'The total amount of available BigVM hosts ' | ||
| 'in the region.', | ||
| labelnames=['hv_size'], | ||
| registry=registry) | ||
|
|
||
| def bigvm_host_error(self, error, rp): | ||
| self.host_errors_counter.labels( | ||
| error, rp['vc'], rp['host'], rp['rp']['name']).inc() | ||
|
|
||
| def error_freeing(self, rp): | ||
| self.bigvm_host_error(ERROR_FREEING, rp) | ||
|
|
||
| def no_candidate_error(self, hv_size): | ||
| self.no_candidate_error_counter.labels(hv_size).inc() | ||
|
|
||
| def set_freeing_provider(self, rp): | ||
| self.host_freeing_up_gauge.labels( | ||
| rp['vc'], rp['host'], rp['rp']['name']).set(1) | ||
|
|
||
| def remove_freeing_provider(self, rp): | ||
| try: | ||
| self.host_freeing_up_gauge.remove( | ||
| rp['vc'], rp['host'], rp['rp']['name']) | ||
| except KeyError: | ||
| pass | ||
|
|
||
| def set_free_hosts_count(self, hv_size, count): | ||
| self.free_hosts_count_gauge.labels(hv_size).set(count) | ||
|
|
||
|
|
||
| bigvm_metrics = _BigVmPrometheusMetrics(REGISTRY) | ||
|
|
||
|
|
||
| def start_bigvm_exporter(): | ||
| port = CONF.bigvm_exporter_listen_port | ||
| start_http_server(port, registry=REGISTRY) | ||
| LOG.info("Started BigVM prometheus exporter on port %s", port) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Does this start a new process or a new thread?
If it starts a thread, does it start an eventlet greenthread (because eventlet patched the
threadingmodule) or does it spawn a native thread?If it spawns a greenthread, does the
prometheus_clientlibrary do anything blocking that could hinder the manager to run properly?If it spawns a native thread, we cannot use
logging(or anything else take takes athreading.Lock) anywhere inside that native thread or we risk a hanging service.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.
Everything behind is based on daemonic
threading.Thread, which to my understanding is patched byeventlet.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 missed to answer one question: Does
prometheus_clientuse anything that would block the process.eventletgreenthreads are not preempted, but give up the CPU when they would do blocking operations. This needs library support (or usage of one of the eventlet-patched functions). If the greenthread doesn't give up the CPU on blocking operations, no other greenthread will run.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 code adds one more greenthread to the
pgt()output. Here is it:Looking at the stack trace there is the
socketserver.pywhich is the module that's being used by the prometheus library to expose the endpoint.So this runs in a greenthread.