-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A new model is introduced called `ContentAppStatus` is introduced which will record status check-in records from the Content App. The Content App will check in periodically checkin and write to the `ContentAppStatus` object. To tell the ContentAppStatus records apart for multiple Content Apps each Content App now requires a name. The name is auto-selected as '{pid}@{hostname}'. The Status API viewset now shows a 'content_apps' section which lists the ContentAppStatus records, showing their names and last heartbeat time. Adds a doc and feature changelog entries. https://pulp.plan.io/issues/4881 closes #4881
- Loading branch information
Brian Bouterse
committed
Jun 24, 2019
1 parent
ae6be0d
commit 96f6fec
Showing
11 changed files
with
190 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 @@ | ||
Adds documentation about the ``CONTENT_APP_TTL`` setting to the configuration page. |
This file contains 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,4 @@ | ||
Each Content App now heartbeats periodically, and Content Apps with recent heartbeats are shown in | ||
the Status API ``/pulp/api/v3/status/`` as a list called ``online_content_apps``. A new setting is | ||
introduced named ``CONTENT_APP_TTL`` which specifies the maximum time (in seconds) a Content App can | ||
not heartbeat and be considered online. |
This file contains 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 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,27 @@ | ||
# Generated by Django 2.2.2 on 2019-06-22 21:13 | ||
|
||
from django.db import migrations, models | ||
import uuid | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('core', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='ContentAppStatus', | ||
fields=[ | ||
('_id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), | ||
('_created', models.DateTimeField(auto_now_add=True)), | ||
('_last_updated', models.DateTimeField(auto_now=True, null=True)), | ||
('name', models.CharField(db_index=True, max_length=255, unique=True)), | ||
('last_heartbeat', models.DateTimeField(auto_now=True)), | ||
], | ||
options={ | ||
'abstract': False, | ||
}, | ||
), | ||
] |
This file contains 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 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,88 @@ | ||
""" | ||
Django models related to the Status API | ||
""" | ||
from datetime import timedelta | ||
|
||
from django.conf import settings | ||
from django.db import models | ||
from django.utils import timezone | ||
|
||
from pulpcore.app.models import Model | ||
|
||
|
||
class ContentAppStatusManager(models.Manager): | ||
|
||
def online(self): | ||
""" | ||
Returns a queryset of ``ContentAppStatus`` objects that are online. | ||
To be considered 'online', a ContentAppStatus must have a heartbeat timestamp within | ||
``settings.CONTENT_APP_TTL`` from now. | ||
Returns: | ||
:class:`django.db.models.query.QuerySet`: A query set of the ``ContentAppStatus`` | ||
objects which are considered 'online'. | ||
""" | ||
now = timezone.now() | ||
age_threshold = now - timedelta(seconds=settings.CONTENT_APP_TTL) | ||
|
||
return self.filter(last_heartbeat__gte=age_threshold) | ||
|
||
|
||
class ContentAppStatus(Model): | ||
""" | ||
Represents a Content App Status | ||
Fields: | ||
name (models.CharField): The name of the content app | ||
last_heartbeat (models.DateTimeField): A timestamp of this worker's last heartbeat | ||
""" | ||
objects = ContentAppStatusManager() | ||
|
||
name = models.CharField(db_index=True, unique=True, max_length=255) | ||
last_heartbeat = models.DateTimeField(auto_now=True) | ||
|
||
@property | ||
def online(self): | ||
""" | ||
Whether a content app can be considered 'online' | ||
To be considered 'online', a content app must have a heartbeat timestamp more recent than | ||
the ``CONTENT_APP_TTL`` setting. | ||
Returns: | ||
bool: True if the content app is considered online, otherwise False | ||
""" | ||
now = timezone.now() | ||
age_threshold = now - timedelta(seconds=settings.CONTENT_APP_TTL) | ||
|
||
return self.last_heartbeat >= age_threshold | ||
|
||
@property | ||
def missing(self): | ||
""" | ||
Whether a Content App can be considered 'missing' | ||
To be considered 'missing', a Content App must have a timestamp older than | ||
``SETTINGS.CONTENT_APP_TTL``. | ||
Returns: | ||
bool: True if the content app is considered missing, otherwise False | ||
""" | ||
now = timezone.now() | ||
age_threshold = now - timedelta(seconds=settings.CONTENT_APP_TTL) | ||
|
||
return self.last_heartbeat < age_threshold | ||
|
||
def save_heartbeat(self): | ||
""" | ||
Update the last_heartbeat field to now and save it. | ||
Only the last_heartbeat field will be saved. No other changes will be saved. | ||
Raises: | ||
ValueError: When the model instance has never been saved before. This method can | ||
only update an existing database record. | ||
""" | ||
self.save(update_fields=['last_heartbeat']) |
This file contains 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 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 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 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 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