Skip to content
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

Implement sorting of events via config file #81

Merged
merged 30 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
a734572
Raw sorting implementation
podliashanyk Oct 27, 2023
522e3b5
Finish sorting implementation
podliashanyk Mar 12, 2024
b142cc1
Add sort_by to config
podliashanyk Mar 12, 2024
edaae9a
Save configured sorting method in session
podliashanyk Mar 12, 2024
60b092f
Add basic documentation about implemented sorting methods
podliashanyk Mar 13, 2024
238893a
Remove unecessary underscores
stveit Mar 21, 2024
ab3a76a
Add sorting tests
stveit Mar 21, 2024
6f02009
Move config consts to a separate file
podliashanyk Apr 4, 2024
c9bb55f
Merge branch 'main' into events-sorting
podliashanyk Jun 10, 2024
0e09edb
Stop implicit None return when sorting
podliashanyk Jun 10, 2024
5cec4da
Fix docs
podliashanyk Jun 10, 2024
eed57be
Rename enum
podliashanyk Jun 10, 2024
0a36f9b
Fix errors in tests
podliashanyk Jun 10, 2024
bffce3f
Run tests with app context
podliashanyk Jun 10, 2024
482a46c
Document get_priority function
podliashanyk Jun 10, 2024
f6369ed
Add reports folder to gitignore
podliashanyk Jun 11, 2024
7fea3ce
Add tests for get_priority helper
podliashanyk Jun 11, 2024
70b7926
Specify param type in get_priority
podliashanyk Jun 11, 2024
45f90f3
Use event's own method for determining whether it is down
podliashanyk Jun 11, 2024
217919d
Simplify get_priority helper
podliashanyk Jun 11, 2024
7a5722a
Add more tests for sort_events helper
podliashanyk Jun 11, 2024
cbfb02e
Bump zinolib to 1.2.0
podliashanyk Jun 11, 2024
11f2772
Add flask-caching dependency
podliashanyk Jun 12, 2024
f930fc4
Configure SimpleCache for the app
podliashanyk Jun 12, 2024
3b00559
Use flask cache to re-sort event list if there are relevant ntie changes
podliashanyk Jun 12, 2024
bf5cf0f
Rename sort_by default method to raw in config
podliashanyk Jun 12, 2024
2ba497e
Polish if statements
podliashanyk Jun 12, 2024
ecae752
Split elifs from sort_events() into separate functions
podliashanyk Jun 12, 2024
336176c
Make caching configurable
podliashanyk Jun 12, 2024
5eeb3de
Move cache config to flask section
podliashanyk Jun 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,7 @@ venv.bak/
pip-selfcheck.json

# End of https://www.gitignore.io/api/venv,django,pycharm+all

### Tests ###
# Reports
reports
25 changes: 25 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,31 @@ The default timezone for timestamps is ``UTC``. Timezone information can be chan
the ``[howitz]``-section or setting the environment variable ``HOWITZ_TIMEZONE`` to ``LOCAL``. Timezone values other
than ``LOCAL`` and ``UTC`` provided in config will be ignored and fall back to ``UTC``.

Howitz uses caching. You can configure preferred caching type under the ``[caching]``-section.
See `Flask-Caching's configuration docs <https://flask-caching.readthedocs.io/en/latest/#configuring-flask-caching>`_ for available configuration options.
Default cache type is `SimpleCache <https://flask-caching.readthedocs.io/en/latest/#simplecache>`_


Configuring order in which events are sorted
--------------------------------------------

Sorting method can be changed under the ``[howitz]``-section by adding::

sort_by = "<valid sorting method>"

Valid sorting methods are:

* *raw* - Unchanged order in which Zino server sends events (by ID ascending).
* *lasttrans* - Newest transaction first, all IGNORED at the bottom. Default sorting in curitz.

* *severity* - Events of same color grouped together. The most severe (red) at the top and ignored at the bottom. Existing method in Ritz TK, but it is called 'default' there.
* *down-rev* - Shortest/none downtime first. Identical to an existing method in Ritz TK.
* *down* - Longest downtime first. Identical to an existing method in Ritz TK.
* *upd-rev* - Events with the most recent update date first. Identical to an existing method in Ritz TK.
* *upd* - Events with the oldest update date first. Identical to an existing method in Ritz TK.
* *age-rev* - Oldest events first. Identical to an existing method in Ritz TK.
* *age* - Newest events first. Identical to an existing method in Ritz TK.


Example config-file (for development)
-------------------------------------
Expand Down
4 changes: 4 additions & 0 deletions howitz.min.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ timezone='LOCAL'
[zino.connections.default]
server =

[caching]
CACHE_TYPE = 'FileSystemCache'
CACHE_DIR = './.howitz_cache'

[logging]
version = 1

Expand Down
5 changes: 5 additions & 0 deletions howitz.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ storage = "./howitz.sqlite3"
devmode = true
refresh_interval = 10
timezone='LOCAL'
sort_by="lasttrans"

[zino.connections.default]
server =
Expand All @@ -15,6 +16,10 @@ server =
#[zino.connections.other]
#server =

[caching]
CACHE_TYPE = 'FileSystemCache'
CACHE_DIR = './.howitz_cache'

hmpf marked this conversation as resolved.
Show resolved Hide resolved
[logging]
version = 1

Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ requires-python = ">=3.8"
dynamic = ["version"]
dependencies = [
"flask",
"flask-caching",
"flask_assets",
"flask-login",
"jinja2",
"zinolib>=1.1.1",
"zinolib>=1.2.0",
"werkzeug<3", # needed by flask-login
"pydantic",
]
Expand Down
7 changes: 6 additions & 1 deletion requirements-frozen.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,20 @@ annotated-types==0.6.0
# via pydantic
blinker==1.7.0
# via flask
cachelib==0.9.0
# via flask-caching
click==8.1.7
# via flask
flask==2.3.3
# via
# flask-assets
# flask-caching
# flask-login
# howitz (pyproject.toml)
flask-assets==2.1.0
# via howitz (pyproject.toml)
flask-caching==2.3.0
# via howitz (pyproject.toml)
flask-login==0.6.3
# via howitz (pyproject.toml)
itsdangerous==2.1.2
Expand Down Expand Up @@ -49,5 +54,5 @@ werkzeug==2.3.8
# flask
# flask-login
# howitz (pyproject.toml)
zinolib==1.1.1
zinolib==1.2.0
# via howitz (pyproject.toml)
13 changes: 13 additions & 0 deletions src/howitz/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


from logging.config import dictConfig
from flask_caching import Cache

from flask import Flask, g, redirect, url_for, current_app
from flask.logging import default_handler
Expand Down Expand Up @@ -101,6 +102,18 @@ def unauthorized():
assets.register("css", css)
css.build()

caching_dict = app.config.get("CACHING", {})
if caching_dict:
cache = Cache(config=caching_dict)
cache.init_app(app)
app.cache = cache
app.logger.debug('Caching config -> %s', caching_dict)
else:
cache = Cache(config={'CACHE_TYPE': 'SimpleCache'})
cache.init_app(app)
app.cache = cache
app.logger.warn('Caching config not found, setting up simple caching')

# import endpoints/urls
from . import endpoints
app.register_blueprint(endpoints.main)
Expand Down
2 changes: 2 additions & 0 deletions src/howitz/config/cache.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def get_config_dict(config_dict):
return config_dict.get('caching', None)
3 changes: 3 additions & 0 deletions src/howitz/config/defaults.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

DEFAULT_STORAGE = "./howitz.sqlite3"
DEFAULT_TIMEZONE = 'UTC'
7 changes: 4 additions & 3 deletions src/howitz/config/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
from pydantic import BaseModel
from pydantic.networks import IPvAnyAddress


DEFAULT_STORAGE = "./howitz.sqlite3"
DEFAULT_TIMEZONE = 'UTC'
from howitz.config.defaults import DEFAULT_TIMEZONE, DEFAULT_STORAGE
from howitz.endpoints import EventSort


hmpf marked this conversation as resolved.
Show resolved Hide resolved
class ServerConfig(BaseModel):
Expand All @@ -30,9 +29,11 @@ class HowitzConfig(ServerConfig, StorageConfig):
devmode: bool = Literal[False]
refresh_interval: int = 5
timezone: str = DEFAULT_TIMEZONE
sort_by: str = EventSort.DEFAULT


class DevHowitzConfig(DevServerConfig, DevStorageConfig):
devmode: bool = Literal[True]
refresh_interval: int = 5
timezone: str = DEFAULT_TIMEZONE
sort_by: str = EventSort.DEFAULT
5 changes: 4 additions & 1 deletion src/howitz/config/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from howitz.config import flask, howitz, log, zino1
from howitz.config import flask, howitz, log, zino1, cache
from zinolib.config.toml import parse_toml_config


Expand All @@ -14,6 +14,9 @@ def make_flask_config_dict(raw_config_dict):
log_dict = log.get_config_dict(raw_config_dict)
config_dict['LOGGING'] = log_dict

cache_dict = cache.get_config_dict(raw_config_dict)
config_dict['CACHING'] = cache_dict

zino_dict = zino1.get_config_dict(raw_config_dict)
zino_dict.pop("username", None)
zino_dict.pop("password", None)
Expand Down
Loading
Loading