Hello community,
here is the log from the commit of package hanadb_exporter for openSUSE:Factory
checked in at 2019-12-14 12:19:01
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/hanadb_exporter (Old)
and /work/SRC/openSUSE:Factory/.hanadb_exporter.new.4691 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "hanadb_exporter"
Sat Dec 14 12:19:01 2019 rev:7 rq:756852 version:0.6.0
Changes:
--------
--- /work/SRC/openSUSE:Factory/hanadb_exporter/hanadb_exporter.changes
2019-12-11 12:13:57.964531091 +0100
+++
/work/SRC/openSUSE:Factory/.hanadb_exporter.new.4691/hanadb_exporter.changes
2019-12-14 12:23:36.763197206 +0100
@@ -1,0 +2,6 @@
+Tue Dec 10 11:18:30 UTC 2019 - Xabier Arbulu <[email protected]>
+
+- Version 0.6.0 Change configuration files location from /etc
+to /usr/etc
+
+-------------------------------------------------------------------
Old:
----
hanadb_exporter-0.5.3.tar.gz
New:
----
hanadb_exporter-0.6.0.tar.gz
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Other differences:
------------------
++++++ hanadb_exporter.spec ++++++
--- /var/tmp/diff_new_pack.uuuLrk/_old 2019-12-14 12:23:37.143197149 +0100
+++ /var/tmp/diff_new_pack.uuuLrk/_new 2019-12-14 12:23:37.143197149 +0100
@@ -20,13 +20,12 @@
%bcond_without test
%endif
-# Compat macro for new _fillupdir macro introduced in Nov 2017
-%if ! %{defined _fillupdir}
- %define _fillupdir /var/adm/fillup-templates
-%endif
+%define _prefix /usr
+%define oldsyscondir /etc
+%define _sysconfdir %{_prefix}/etc
Name: hanadb_exporter
-Version: 0.5.3
+Version: 0.6.0
Release: 0
Summary: SAP HANA database metrics exporter
License: Apache-2.0
@@ -61,21 +60,16 @@
rm -r %{buildroot}%{python3_sitelib}/tests
# Add daemon files
+mkdir -p %{buildroot}%{oldsyscondir}/hanadb_exporter
mkdir -p %{buildroot}%{_sysconfdir}/hanadb_exporter
install -D -m 644 daemon/[email protected]
%{buildroot}%{_unitdir}/[email protected]
-mkdir -p %{buildroot}%{_fillupdir}
-mkdir -p %{buildroot}%{_sysconfdir}/sysconfig
-install -D -m 0644 daemon/hanadb_exporter.sysconfig
%{buildroot}%{_fillupdir}/sysconfig.hanadb_exporter
install -D -m 0644 config.json.example
%{buildroot}%{_docdir}/hanadb_exporter/config.json.example
install -D -m 0644 metrics.json
%{buildroot}%{_docdir}/hanadb_exporter/metrics.json
install -D -m 0644 logging_config.ini
%{buildroot}%{_docdir}/hanadb_exporter/logging_config.ini
%post
%service_add_post [email protected]
-if [ ! -e %{_sysconfdir}/sysconfig/hanadb_exporter ]; then
- %fillup_only hanadb_exporter
-fi
rm -rf %{_sysconfdir}/hanadb_exporter/*
ln -s %{_docdir}/hanadb_exporter/config.json.example
%{_sysconfdir}/hanadb_exporter/config.json.example
ln -s %{_docdir}/hanadb_exporter/metrics.json
%{_sysconfdir}/hanadb_exporter/metrics.json
@@ -96,6 +90,7 @@
%endif
%files
+%defattr(-,root,root,-)
%if 0%{?sle_version:1} && 0%{?sle_version} < 120300
%doc README.md docs/METRICS.md LICENSE
%else
@@ -105,11 +100,12 @@
%{python3_sitelib}/*
%{_bindir}/hanadb_exporter
+%dir %{_sysconfdir}
+%dir %{oldsyscondir}/hanadb_exporter
%dir %{_sysconfdir}/hanadb_exporter
%{_docdir}/hanadb_exporter/config.json.example
%{_docdir}/hanadb_exporter/metrics.json
%{_docdir}/hanadb_exporter/logging_config.ini
-%{_fillupdir}/sysconfig.hanadb_exporter
%{_unitdir}/[email protected]
%changelog
++++++ hanadb_exporter-0.5.3.tar.gz -> hanadb_exporter-0.6.0.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/hanadb_exporter-0.5.3/README.md
new/hanadb_exporter-0.6.0/README.md
--- old/hanadb_exporter-0.5.3/README.md 2019-12-10 12:20:40.946509434 +0100
+++ new/hanadb_exporter-0.6.0/README.md 2019-12-13 10:04:45.859565696 +0100
@@ -108,6 +108,11 @@
python3 hanadb_exporter/main.py -c config.json -m metrics.json
```
+If a `config.json` configuration file is stored in `/etc/hanadb_exporter` the
exporter can be started with the next command too:
+```
+hanadb_exporter --identifier config # Notice that the identifier matches with
the config file without extension
+```
+
### Running as a daemon
The hanadb_exporter can be executed using `systemd`. For that, the best option
is to install the
project using a rpm package. This can be done following the next steps (this
example is for tumbleweed):
@@ -124,12 +129,11 @@
Even using this way, the SAP HANA database connector package must be installed
independently (see [Installation](#installation)).
After that we need to create the configuration file as
`/etc/hanadb_exporter/my-exporter.json` (the name is relevant as we will use it
to start the daemon).
-The [config.json.example](./config.json.example) can be used as example (the
example file is
-stored in `/etc/hanadb_exporter` folder too).
+The [config.json.example](./config.json.example) can be used as example (the
example file is stored in `/usr/etc/hanadb_exporter` folder too).
-The default [metrics file](./metrics.json) is stored in
`/etc/hanadb_exporter/metrics.json`.
+The default [metrics file](./metrics.json) is stored in
`/usr/etc/hanadb_exporter/metrics.json`. If a new `metrics.json` is stored in
`/etc/hanadb_exporter` this will be used.
-The logging configuration file can be updated as well to customize it (stored
in `/etc/hanadb_exporter/logging_config.ini`)
+The logging configuration file can be updated as well to customize changing
the new configuration file `logging.config_file` entry (default one available
in `/usr/etc/hanadb_exporter/logging_config.ini`).
Now, the exporter can be started as a daemon. As we can have multiple
`hanadb_exporter` instances running in one machine, the service is created
using a template file, so an extra information must be given to `systemd` (this
is done adding the `@` keyword after the service name together with the name of
the configuration file created previously in
`/etc/hanadb_exporter/{name}.json`):
```
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/hanadb_exporter-0.5.3/daemon/hanadb_exporter.sysconfig
new/hanadb_exporter-0.6.0/daemon/hanadb_exporter.sysconfig
--- old/hanadb_exporter-0.5.3/daemon/hanadb_exporter.sysconfig 2019-12-10
12:20:40.946509434 +0100
+++ new/hanadb_exporter-0.6.0/daemon/hanadb_exporter.sysconfig 1970-01-01
01:00:00.000000000 +0100
@@ -1,3 +0,0 @@
-# hanadb_exporter daemon configuration file
-# Exported metrics configuration file path
-METRICS_FILE=/etc/hanadb_exporter/metrics.json
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/hanadb_exporter-0.5.3/daemon/[email protected]
new/hanadb_exporter-0.6.0/daemon/[email protected]
--- old/hanadb_exporter-0.5.3/daemon/[email protected] 2019-12-10
12:20:40.946509434 +0100
+++ new/hanadb_exporter-0.6.0/daemon/[email protected] 2019-12-13
10:04:45.859565696 +0100
@@ -4,8 +4,7 @@
[Service]
Type=simple
-EnvironmentFile=/etc/sysconfig/hanadb_exporter
-ExecStart=/usr/bin/hanadb_exporter -c /etc/hanadb_exporter/%i.json -m
$METRICS_FILE
+ExecStart=/usr/bin/hanadb_exporter --identifier %i
[Install]
WantedBy=multi-user.target
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/hanadb_exporter-0.5.3/docs/README.md
new/hanadb_exporter-0.6.0/docs/README.md
--- old/hanadb_exporter-0.5.3/docs/README.md 2019-12-10 12:20:40.946509434
+0100
+++ new/hanadb_exporter-0.6.0/docs/README.md 1970-01-01 01:00:00.000000000
+0100
@@ -1,2 +0,0 @@
-# docs
-Use this folder to store all the documentation files
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/hanadb_exporter-0.5.3/hanadb_exporter/__init__.py
new/hanadb_exporter-0.6.0/hanadb_exporter/__init__.py
--- old/hanadb_exporter-0.5.3/hanadb_exporter/__init__.py 2019-12-10
12:20:40.946509434 +0100
+++ new/hanadb_exporter-0.6.0/hanadb_exporter/__init__.py 2019-12-13
10:04:45.859565696 +0100
@@ -8,4 +8,4 @@
:since: 2019-05-09
"""
-__version__ = "0.5.3"
+__version__ = "0.6.0"
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/hanadb_exporter-0.5.3/hanadb_exporter/main.py
new/hanadb_exporter-0.6.0/hanadb_exporter/main.py
--- old/hanadb_exporter-0.5.3/hanadb_exporter/main.py 2019-12-10
12:20:40.946509434 +0100
+++ new/hanadb_exporter-0.6.0/hanadb_exporter/main.py 2019-12-13
10:04:45.859565696 +0100
@@ -9,6 +9,7 @@
"""
import sys
+import os
import traceback
import logging
from logging.config import fileConfig
@@ -23,7 +24,11 @@
from hanadb_exporter import db_manager
LOGGER = logging.getLogger(__name__)
-
+CONFIG_FOLDER = '/etc/hanadb_exporter'
+METRICS_FILES = [
+ '/etc/hanadb_exporter/metrics.json',
+ '/usr/etc/hanadb_exporter/metrics.json'
+]
def parse_config(config_file):
"""
@@ -40,9 +45,11 @@
"""
parser = argparse.ArgumentParser()
parser.add_argument(
- "-c", "--config", help="Path to hanadb_exporter configuration file",
required=True)
+ "-c", "--config", help="Path to hanadb_exporter configuration file")
+ parser.add_argument(
+ "-m", "--metrics", help="Path to hanadb_exporter metrics file")
parser.add_argument(
- "-m", "--metrics", help="Path to hanadb_exporter metrics file",
required=True)
+ "--identifier", help="Identifier of the configuration file from
/etc/hanadb_exporter")
parser.add_argument(
"-v", "--verbosity",
help="Python logging level. Options: DEBUG, INFO, WARN, ERROR (INFO by
default)")
@@ -72,20 +79,39 @@
sys.excepthook = handle_exception
+def find_metrics_file():
+ """
+ Find metrics predefined files in default locations
+ """
+ for metric_file in METRICS_FILES:
+ if os.path.isfile(metric_file):
+ return metric_file
+ raise ValueError(
+ 'metrics file does not exist in {}'.format(",".join(METRICS_FILES)))
+
+
# Start up the server to expose the metrics.
def run():
"""
Main execution
"""
args = parse_arguments()
- config = parse_config(args.config)
+ if args.config is not None:
+ config = parse_config(args.config)
+ elif args.identifier is not None:
+ config = parse_config('{}/{}.json'.format(CONFIG_FOLDER,
args.identifier))
+ else:
+ raise ValueError('configuration file or identifier must be used')
if config.get('logging', None):
setup_logging(config)
else:
logging.basicConfig(level=args.verbosity or logging.INFO)
- metrics = args.metrics
+ if args.metrics:
+ metrics = args.metrics
+ else:
+ metrics = find_metrics_file()
try:
hana_config = config['hana']
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/hanadb_exporter-0.5.3/hanadb_exporter.changes
new/hanadb_exporter-0.6.0/hanadb_exporter.changes
--- old/hanadb_exporter-0.5.3/hanadb_exporter.changes 2019-12-10
12:20:40.950507434 +0100
+++ new/hanadb_exporter-0.6.0/hanadb_exporter.changes 2019-12-13
10:04:45.859565696 +0100
@@ -1,4 +1,10 @@
-------------------------------------------------------------------
+Tue Dec 10 11:18:30 UTC 2019 - Xabier Arbulu <[email protected]>
+
+- Version 0.6.0 Change configuration files location from /etc
+to /usr/etc
+
+-------------------------------------------------------------------
Tue Dec 10 09:17:42 UTC 2019 - Xabier Arbulu <[email protected]>
- Version 0.5.3 Improve metrics collection if some of the rows
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/hanadb_exporter-0.5.3/hanadb_exporter.spec
new/hanadb_exporter-0.6.0/hanadb_exporter.spec
--- old/hanadb_exporter-0.5.3/hanadb_exporter.spec 2019-12-10
12:20:40.950507434 +0100
+++ new/hanadb_exporter-0.6.0/hanadb_exporter.spec 2019-12-13
10:04:45.859565696 +0100
@@ -20,13 +20,12 @@
%bcond_without test
%endif
-# Compat macro for new _fillupdir macro introduced in Nov 2017
-%if ! %{defined _fillupdir}
- %define _fillupdir /var/adm/fillup-templates
-%endif
+%define _prefix /usr
+%define oldsyscondir /etc
+%define _sysconfdir %{_prefix}/etc
Name: hanadb_exporter
-Version: 0.5.3
+Version: 0.6.0
Release: 0
Summary: SAP HANA database metrics exporter
License: Apache-2.0
@@ -61,21 +60,16 @@
rm -r %{buildroot}%{python3_sitelib}/tests
# Add daemon files
+mkdir -p %{buildroot}%{oldsyscondir}/hanadb_exporter
mkdir -p %{buildroot}%{_sysconfdir}/hanadb_exporter
install -D -m 644 daemon/[email protected]
%{buildroot}%{_unitdir}/[email protected]
-mkdir -p %{buildroot}%{_fillupdir}
-mkdir -p %{buildroot}%{_sysconfdir}/sysconfig
-install -D -m 0644 daemon/hanadb_exporter.sysconfig
%{buildroot}%{_fillupdir}/sysconfig.hanadb_exporter
install -D -m 0644 config.json.example
%{buildroot}%{_docdir}/hanadb_exporter/config.json.example
install -D -m 0644 metrics.json
%{buildroot}%{_docdir}/hanadb_exporter/metrics.json
install -D -m 0644 logging_config.ini
%{buildroot}%{_docdir}/hanadb_exporter/logging_config.ini
%post
%service_add_post [email protected]
-if [ ! -e %{_sysconfdir}/sysconfig/hanadb_exporter ]; then
- %fillup_only hanadb_exporter
-fi
rm -rf %{_sysconfdir}/hanadb_exporter/*
ln -s %{_docdir}/hanadb_exporter/config.json.example
%{_sysconfdir}/hanadb_exporter/config.json.example
ln -s %{_docdir}/hanadb_exporter/metrics.json
%{_sysconfdir}/hanadb_exporter/metrics.json
@@ -96,6 +90,7 @@
%endif
%files
+%defattr(-,root,root,-)
%if 0%{?sle_version:1} && 0%{?sle_version} < 120300
%doc README.md docs/METRICS.md LICENSE
%else
@@ -105,11 +100,12 @@
%{python3_sitelib}/*
%{_bindir}/hanadb_exporter
+%dir %{_sysconfdir}
+%dir %{oldsyscondir}/hanadb_exporter
%dir %{_sysconfdir}/hanadb_exporter
%{_docdir}/hanadb_exporter/config.json.example
%{_docdir}/hanadb_exporter/metrics.json
%{_docdir}/hanadb_exporter/logging_config.ini
-%{_fillupdir}/sysconfig.hanadb_exporter
%{_unitdir}/[email protected]
%changelog
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/hanadb_exporter-0.5.3/tests/main_test.py
new/hanadb_exporter-0.6.0/tests/main_test.py
--- old/hanadb_exporter-0.5.3/tests/main_test.py 2019-12-10
12:20:40.950507434 +0100
+++ new/hanadb_exporter-0.6.0/tests/main_test.py 2019-12-13
10:04:45.859565696 +0100
@@ -53,9 +53,12 @@
mock_parser.assert_called_once_with()
mocked_parser.add_argument.assert_has_calls([
mock.call(
- "-c", "--config", help="Path to hanadb_exporter configuration
file", required=True),
+ "-c", "--config", help="Path to hanadb_exporter configuration
file"),
mock.call(
- "-m", "--metrics", help="Path to hanadb_exporter metrics
file", required=True),
+ "-m", "--metrics", help="Path to hanadb_exporter metrics
file"),
+ mock.call(
+ "--identifier",
+ help="Identifier of the configuration file from
/etc/hanadb_exporter"),
mock.call(
"-v", "--verbosity",
help="Python logging level. Options: DEBUG, INFO, WARN, ERROR
(INFO by default)")
@@ -88,6 +91,19 @@
mock.call('my_config_file', defaults={'logfilename':
'/var/log/hanadb_exporter_123.123.123.123_1234'})
])
+ @mock.patch('os.path.isfile')
+ def test_find_metrics_file(self, mock_isfile):
+ mock_isfile.return_value = True
+ metric_file = main.find_metrics_file()
+ assert metric_file == main.METRICS_FILES[0]
+
+ @mock.patch('os.path.isfile')
+ def test_find_metrics_file_error(self, mock_isfile):
+ mock_isfile.side_effect = [False, False]
+ with pytest.raises(ValueError) as err:
+ main.find_metrics_file()
+ assert 'metrics file does not exist in
{}'.format(",".join(main.METRICS_FILES)) in str(err.value)
+
@mock.patch('hanadb_exporter.main.LOGGER')
@mock.patch('hanadb_exporter.main.parse_arguments')
@mock.patch('hanadb_exporter.main.parse_config')
@@ -152,6 +168,84 @@
mock_sleep.assert_called_once_with(1)
@mock.patch('hanadb_exporter.main.LOGGER')
+ @mock.patch('hanadb_exporter.main.find_metrics_file')
+ @mock.patch('hanadb_exporter.main.parse_arguments')
+ @mock.patch('hanadb_exporter.main.parse_config')
+ @mock.patch('hanadb_exporter.main.setup_logging')
+ @mock.patch('hanadb_exporter.main.db_manager.DatabaseManager')
+ @mock.patch('hanadb_exporter.main.prometheus_exporter.SapHanaCollectors')
+ @mock.patch('hanadb_exporter.main.REGISTRY.register')
+ @mock.patch('hanadb_exporter.main.start_http_server')
+ @mock.patch('logging.getLogger')
+ @mock.patch('time.sleep')
+ def test_run_defaults(
+ self, mock_sleep, mock_get_logger, mock_start_server,
mock_registry,
+ mock_exporters, mock_db_manager, mock_setup_logging,
+ mock_parse_config, mock_parse_arguments, mock_find_metrics,
mock_logger):
+
+ mock_arguments = mock.Mock(config=None, metrics=None,
identifier='config')
+ mock_parse_arguments.return_value = mock_arguments
+
+ mock_find_metrics.return_value = 'new_metrics'
+
+ config = {
+ 'hana': {
+ 'host': '10.10.10.10',
+ 'port': 1234,
+ 'user': 'user',
+ 'password': 'pass'
+ },
+ 'logging': {
+ 'log_file': 'my_file',
+ 'config_file': 'my_config_file'
+ }
+ }
+ mock_parse_config.return_value = config
+
+ db_instance = mock.Mock()
+ db_instance.get_connectors.return_value = 'connectors'
+ mock_db_manager.return_value = db_instance
+
+ mock_collector = mock.Mock()
+ mock_exporters.return_value = mock_collector
+
+ mock_sleep.side_effect = Exception
+
+ with pytest.raises(Exception):
+ main.run()
+
+ mock_parse_arguments.assert_called_once_with()
+
mock_parse_config.assert_called_once_with("{}/{}.json".format(main.CONFIG_FOLDER,
'config'))
+ mock_setup_logging.assert_called_once_with(config)
+ mock_find_metrics.assert_called_once_with()
+ mock_db_manager.assert_called_once_with()
+ db_instance.start.assert_called_once_with(
+ '10.10.10.10', 1234, user='user', password='pass',
+ userkey=None, multi_tenant=True, timeout=600)
+ db_instance.get_connectors.assert_called_once_with()
+ mock_exporters.assert_called_once_with(
+ connectors='connectors', metrics_file='new_metrics')
+
+ mock_registry.assert_called_once_with(mock_collector)
+ mock_logger.info.assert_has_calls([
+ mock.call('exporter sucessfully registered'),
+ mock.call('starting to serve metrics')
+ ])
+ mock_start_server.assert_called_once_with(8001, '0.0.0.0')
+ mock_sleep.assert_called_once_with(1)
+
+ @mock.patch('hanadb_exporter.main.parse_arguments')
+ def test_run_invalid_args(self, mock_parse_arguments):
+
+ mock_arguments = mock.Mock(config=None, identifier=None)
+ mock_parse_arguments.return_value = mock_arguments
+
+ with pytest.raises(ValueError) as err:
+ main.run()
+
+ assert 'configuration file or identifier must be used' in
str(err.value)
+
+ @mock.patch('hanadb_exporter.main.LOGGER')
@mock.patch('hanadb_exporter.main.parse_arguments')
@mock.patch('hanadb_exporter.main.parse_config')
@mock.patch('hanadb_exporter.main.db_manager.DatabaseManager')