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

Increase RawNotifications raw size and used defaults #127

Merged
merged 2 commits into from
Oct 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ PLUGINS = ["nautobot_circuit_maintenance"]
```py
PLUGINS_CONFIG = {
"nautobot_circuit_maintenance": {
"raw_notifications": {
"initial_days_since": 100,
"raw_notification_size": 500,
},
"raw_notification_initial_days_since": 100,
"raw_notification_size": 16384,
"notification_sources": [
{
...
Expand All @@ -43,12 +41,12 @@ PLUGINS_CONFIG = {
}
```

In the `raw_notifications` section, you can define:
Plugin config parameters:

- `initial_days_since`: define how many days back the plugin will check for `RawNotification`s for each
- `raw_notification_initial_days_since`: define how many days back the plugin will check for `RawNotification`s for each
`NotificationSource`, in order to limit the number of notifications to be processed on the first run of the plugin.
In subsequent runs, the last notification date will be used as the reference to limit. If not defined, it defaults to **365 days**.
- `raw_notification_size`: define how many bytes from a notification will be stored in the database to not store too big objects. If not defined, it defaults to **1000** bytes.
- `raw_notification_size`: define how many bytes from a notification will be stored in the database to not store too big objects. If not defined, it defaults to **8192** bytes.

The `notification_sources` have custom definition depending on the `Source` type, and are defined in the [Usage](#Usage) section.

Expand Down
1 change: 0 additions & 1 deletion development/nautobot_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@
# Each key in the dictionary is the name of an installed plugin and its value is a dictionary of settings.
PLUGINS_CONFIG = {
"nautobot_circuit_maintenance": {
"raw_notifications": {"initial_days_since": 365},
"notification_sources": [
{
"name": "my imap source",
Expand Down
5 changes: 4 additions & 1 deletion nautobot_circuit_maintenance/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ class CircuitMaintenanceConfig(PluginConfig):
min_version = "1.0.0-beta.4"
max_version = "1.999"
required_settings = []
default_settings = {}
default_settings = {
"raw_notification_initial_days_since": 365,
"raw_notification_size": 8192,
}
glennmatthews marked this conversation as resolved.
Show resolved Hide resolved
caching_config = {}

def ready(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

# pylint: disable=broad-except
PLUGIN_SETTINGS = settings.PLUGINS_CONFIG.get("nautobot_circuit_maintenance", {})
MAX_INITIAL_DAYS_SINCE = 365


def create_circuit_maintenance(
Expand Down Expand Up @@ -304,14 +303,14 @@ def process_raw_notification(logger: Job, notification: MaintenanceNotification)


def get_since_reference(logger: Job) -> int:
"""Get the timestamp from the latest processed RawNotification or a reference from config `initial_days_since`."""
"""Get the timestamp from the latest processed RawNotification or a reference from config `raw_notification_initial_days_since`."""
# Latest retrieved notification will limit the scope of notifications to retrieve
last_raw_notification = RawNotification.objects.last()
if last_raw_notification:
since_reference = last_raw_notification.date.timestamp()
else:
since_reference = datetime.datetime.utcnow() - datetime.timedelta(
days=PLUGIN_SETTINGS.get("raw_notifications", {}).get("initial_days_since", MAX_INITIAL_DAYS_SINCE)
days=PLUGIN_SETTINGS.get("raw_notification_initial_days_since")
)
since_reference = int(since_reference.timestamp())
logger.log_info(message=f"Processing notifications since {since_reference}")
Expand Down
5 changes: 1 addition & 4 deletions nautobot_circuit_maintenance/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from .choices import CircuitImpactChoices, CircuitMaintenanceStatusChoices, NoteLevelChoices

PLUGIN_SETTINGS = settings.PLUGINS_CONFIG.get("nautobot_circuit_maintenance", {})
DEFAULT_RAW_NOTIFICATION_SIZE = 1000


@extras_features(
Expand Down Expand Up @@ -250,9 +249,7 @@ class Meta: # noqa: D106 "Missing docstring in public nested class"
def save(self, *args, **kwargs):
"""Custom save for RawNotification."""
# Limiting the size of the notification stored.
self.raw = self.raw[
: PLUGIN_SETTINGS.get("raw_notifications", {}).get("raw_notification_size", DEFAULT_RAW_NOTIFICATION_SIZE)
]
self.raw = self.raw[: PLUGIN_SETTINGS.get("raw_notification_size")]
super().save(*args, **kwargs)

def __str__(self):
Expand Down