Skip to content

Commit b19d029

Browse files
feat!: Remove all readers and fix all linting errors for v0.0.15 release. (#64)
1 parent 4c1406d commit b19d029

7 files changed

Lines changed: 12 additions & 1093 deletions

File tree

README-protocol.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ CLP's intermediate representation (IR) is made to be:
55
- Capable of flushing write buffers on demand so readers can access the
66
latest data
77

8-
See [encoder.py](src/clp_logging/encoder.py) and
9-
[decoder.py](src/clp_logging/decoder.py) to see the implementation.
10-
118
# Background
129
CLP parses a log event into zero or more variables, a timestamp, and a logtype.
1310
There are two major types of variables:

README.md

Lines changed: 3 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -189,75 +189,11 @@ from clp_logging.handlers import CLPSockHandler
189189
CLPSockHandler(Path("example.clp.zst")).stop_listener()
190190
```
191191

192-
## CLP readers (decoders)
192+
## Read IR streams
193193

194194
> [!WARNING]
195-
> The readers and all the other non-logging APIs currently available in this library are scheduled
196-
> for deprecation in an upcoming release. To access our newest and improved CLP IR analytics
197-
> interface (which offers advanced features like high-performance decoding and enhanced query search
198-
> capabilities) check out [clp-ffi-py][9].
199-
200-
### CLPStreamReader
201-
202-
- Read/decode any arbitrary stream
203-
- Can be used as an iterator that returns each log message as an object
204-
- Can skip n logs: `clp_reader.skip_nlogs(N)`
205-
- Can skip to first log after given time (since unix epoch):
206-
- `clp_reader.skip_to_time(TIME)`
207-
208-
### CLPFileReader
209-
210-
- Simple wrapper around CLPStreamHandler that calls open
211-
212-
#### Example code: CLPFileReader
213-
214-
```python
215-
from pathlib import Path
216-
from typing import List
217-
218-
from clp_logging.readers import CLPFileReader, Log
219-
220-
# create a list of all Log objects
221-
log_objects: List[Log] = []
222-
with CLPFileReader(Path("example.clp.zst")) as clp_reader:
223-
for log in clp_reader:
224-
log_objects.append(log)
225-
```
226-
227-
### CLPSegmentStreaming
228-
229-
* Classes that inherit from CLPBaseReader can only read a single CLP IR stream from start to finish. This is necessary because, to determine the timestamp of an individual log, the starting timestamp (from the IR stream preamble) and all timestamp deltas up to that log must be known. In scenarios where an IR stream is periodically uploaded in chunks, users would need to either continuously read the entire stream or re-read the entire stream from the start.
230-
* The CLPSegmentStreaming class has the ability to take an input IR stream and segment it, outputting multiple independent IR streams. This makes it possible to read arbitrary segments of the original input IR stream without needing to decode it from the start.
231-
* In technical terms, the segment streaming reader allows the read operation to start from a non-zero offset and streams the legally encoded logs from one stream to another.
232-
* Each read call will return encoded metadata that can be used to resume from the current call.
233-
234-
#### Example code: CLPSegmentStreaming
235-
236-
```python
237-
from clp_logging.readers import CLPSegmentStreaming
238-
from clp_logging.protocol import Metadata
239-
240-
segment_idx: int = 0
241-
segment_max_size: int = 8192
242-
offset: int = 0
243-
metadata: Metadata = None
244-
while True:
245-
bytes_read: int
246-
with open("example.clp", "rb") as fin, open(f"{segment_idx}.clp", "wb") as fout:
247-
bytes_read, metadata = CLPSegmentStreaming.read(
248-
fin,
249-
fout,
250-
offset=offset,
251-
max_bytes_to_write=segment_max_size,
252-
metadata=metadata
253-
)
254-
segment_idx += 1
255-
offset += bytes_read
256-
if metadata == None:
257-
break
258-
```
259-
260-
In the example code provided, "example.clp" is streamed into segments named "0.clp", "1.clp", and so on. Each segment is smaller than 8192 bytes and can be decoded independently.
195+
> All readers are removed from this library since v0.0.15. To read an IR stream, use [clp-ffi-py][9]
196+
> instead.
261197
262198
## Log level timeout feature: CLPLogLevelTimeout
263199

src/clp_logging/decoder.py

Lines changed: 0 additions & 166 deletions
This file was deleted.

src/clp_logging/handlers.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ def _exit_handler(signum: int, frame: Optional[FrameType]) -> None:
373373
@staticmethod
374374
def _handle_client(
375375
conn: socket.socket,
376-
log_queue: "Queue[Tuple[int, bytes]]",
376+
log_queue: "Queue[Tuple[int, Union[bytes, bytearray]]]",
377377
) -> int:
378378
"""
379379
Continuously reads from an individual `CLPSockHandler` and sends the
@@ -416,7 +416,7 @@ def _handle_client(
416416
@staticmethod
417417
def _aggregator(
418418
log_path: Path,
419-
log_queue: "Queue[Tuple[int, bytes]]",
419+
log_queue: "Queue[Tuple[int, Union[bytes, bytearray]]]",
420420
timestamp_format: Optional[str],
421421
timezone: Optional[str],
422422
timeout: int,
@@ -463,7 +463,7 @@ def log_fn(msg: str) -> None:
463463
FourByteEncoder.encode_preamble(last_timestamp_ms, timestamp_format, timezone)
464464
)
465465
while not CLPSockListener._signaled:
466-
msg: bytes
466+
msg: Union[bytes, bytearray]
467467
try:
468468
loglevel, msg = log_queue.get(timeout=timeout)
469469
except Empty:
@@ -524,7 +524,7 @@ def _server(
524524
"""
525525
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
526526
sock.settimeout(timeout)
527-
log_queue: "Queue[Tuple[int, bytes]]" = Queue()
527+
log_queue: "Queue[Tuple[int, Union[bytes, bytearray]]]" = Queue()
528528
ret: int = CLPSockListener._try_bind(sock, sock_path)
529529
sock.listen()
530530
os.write(parent_fd, b"\x00")

0 commit comments

Comments
 (0)