-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#62815] server: Add telemetry endpoints
This commit implements telemetry endpoints for receiving batched logs from registered devices. Since it adds a new logs table to the database, a 3rd alembic revision is added to allow for migrations.
- Loading branch information
Kacper Zienkiewicz
committed
Aug 19, 2024
1 parent
3c0b44e
commit 8025017
Showing
13 changed files
with
998 additions
and
47 deletions.
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
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,81 @@ | ||
from typing import ClassVar, Type, List | ||
import datetime | ||
from dataclasses import field | ||
from typing import Optional | ||
|
||
import marshmallow | ||
from marshmallow import ValidationError | ||
import marshmallow_dataclass | ||
from rdfm.schema.validators import Contains | ||
|
||
|
||
@marshmallow_dataclass.dataclass | ||
class LogRouteParameters(): | ||
"""Represents GET parameters passed to a log route""" | ||
since: Optional[datetime.datetime] = field(metadata={ | ||
"required": False, | ||
"format": "rfc" | ||
}) | ||
to: Optional[datetime.datetime] = field(metadata={ | ||
"required": False, | ||
"format": "rfc" | ||
}) | ||
name: Optional[str] = field(metadata={ | ||
"required": False | ||
}) | ||
Schema: ClassVar[Type[marshmallow.Schema]] = marshmallow.Schema | ||
|
||
|
||
@marshmallow_dataclass.dataclass | ||
class LogEntry(): | ||
"""Represents a single log entry within a batch of logs | ||
""" | ||
device_timestamp: datetime.datetime = field(metadata={ | ||
"required": True, | ||
"format": "rfc" | ||
}) | ||
name: str = field(metadata={ | ||
"required": True | ||
}) | ||
entry: str = field(metadata={ | ||
"required": True | ||
}) | ||
Schema: ClassVar[Type[marshmallow.Schema]] = marshmallow.Schema | ||
|
||
|
||
@marshmallow_dataclass.dataclass | ||
class LogBatch(): | ||
"""Represents a log batch | ||
""" | ||
batch: List[LogEntry] = field(metadata={ | ||
"required": True | ||
}) | ||
Schema: ClassVar[Type[marshmallow.Schema]] = marshmallow.Schema | ||
|
||
|
||
@marshmallow_dataclass.dataclass | ||
class Log(): | ||
"""Represents a log entry | ||
""" | ||
id: int = field(metadata={ | ||
"required": True | ||
}) | ||
created: Optional[datetime.datetime] = field(metadata={ | ||
"required": True, | ||
"allowed_none": True, | ||
"format": "rfc" | ||
}) | ||
device_id: int = field(metadata={ | ||
"required": True | ||
}) | ||
device_timestamp: datetime.datetime = field(metadata={ | ||
"required": True, | ||
"format": "rfc" | ||
}) | ||
name: str = field(metadata={ | ||
"required": True | ||
}) | ||
entry: str = field(metadata={ | ||
"required": True | ||
}) | ||
Schema: ClassVar[Type[marshmallow.Schema]] = marshmallow.Schema |
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,35 @@ | ||
"""Add logs table | ||
Revision ID: 3 | ||
Revises: 2 | ||
Create Date: 2024-07-25 10:13:47.069428 | ||
""" | ||
from typing import Sequence, Union | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = '3' | ||
down_revision: Union[str, None] = '2' | ||
branch_labels: Union[str, Sequence[str], None] = None | ||
depends_on: Union[str, Sequence[str], None] = None | ||
|
||
|
||
def upgrade() -> None: | ||
op.create_table('logs', | ||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), | ||
sa.Column('created', sa.DateTime(), nullable=False), | ||
sa.Column('device_id', sa.Integer(), nullable=False), | ||
sa.Column('device_timestamp', sa.DateTime(), nullable=False), | ||
sa.Column('name', sa.Text(), nullable=False), | ||
sa.Column('entry', sa.Text(), nullable=False), | ||
sa.ForeignKeyConstraint(['device_id'], ['devices.id'], ondelete='RESTRICT'), | ||
sa.PrimaryKeyConstraint('id') | ||
) | ||
|
||
|
||
def downgrade() -> None: | ||
op.drop_table('logs') |
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
Oops, something went wrong.