-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/flex data schema #36
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
Changes from all commits
12b0aa5
c814480
0fc742c
c47c09c
f1dd570
c6b94f9
2c53405
28405bd
651d9a9
1f6e826
823ab78
3678763
83966fd
9c0251b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| INFLUX_PORT=8086 | ||
| INFLUX_ADMIN_USER=admin | ||
| INFLUX_ADMIN_PASSWORD=changeme | ||
| INFLUX_ORG=nwdaf | ||
| INFLUX_BUCKET=raw_data | ||
| INFLUX_TOKEN=your-super-secret-token | ||
|
|
||
| CLICKHOUSE_HTTP_PORT=8123 | ||
| CLICKHOUSE_TCP_PORT=9000 | ||
| CLICKHOUSE_DB=analytics | ||
| CLICKHOUSE_USER=default | ||
| CLICKHOUSE_PASSWORD=changeme |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| timestamp: datetime | ||
| cell_index: integer |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| # Optional/allowed extra fields for raw data points | ||
|
|
||
| datarate: float | ||
| mean_latency: float | ||
| rsrp: float | ||
| sinr: float | ||
| rsrq: float | ||
| direction: string | ||
| network: string | ||
| cqi: float | ||
| primary_bandwidth: float | ||
| ul_bandwidth: float |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| - cell_index | ||
| - network |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| FROM clickhouse/clickhouse-server:24.1.2.5 | ||
|
|
||
| COPY sql/ /docker-entrypoint-initdb.d/ | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,13 @@ | ||
| import os | ||
| import asyncio | ||
| from threading import Thread | ||
| import os | ||
| from contextlib import asynccontextmanager | ||
| from threading import Thread | ||
|
|
||
| from fastapi import FastAPI | ||
|
|
||
| from src.configs import load_all | ||
| from src.routers.v1 import v1_router | ||
| from src.services.databases import ClickHouse, Influx | ||
|
|
||
| from src.sink import KafkaSinkManager | ||
|
|
||
| KAFKA_HOST = os.getenv("KAFKA_HOST", "localhost") | ||
|
|
@@ -19,7 +20,7 @@ async def lifespan(app: FastAPI): | |
| # Initialize database connections (singleton, handles connection internally) | ||
| Influx.service # Access triggers lazy initialization | ||
| ClickHouse.service # Access triggers lazy initialization | ||
|
|
||
| load_all() | ||
|
Comment on lines
21
to
+23
|
||
| sink_manager = KafkaSinkManager(KAFKA_HOST, KAFKA_PORT) | ||
|
|
||
| def kafka_worker(): | ||
|
|
@@ -33,17 +34,10 @@ def kafka_worker(): | |
| except Exception as e: | ||
| print(f"Kafka worker crashed: {e}") | ||
|
|
||
| kafka_thread = Thread( | ||
| target=kafka_worker, | ||
| daemon=True, | ||
| name="kafka-sink-thread" | ||
| ) | ||
| kafka_thread = Thread(target=kafka_worker, daemon=True, name="kafka-sink-thread") | ||
| kafka_thread.start() | ||
|
|
||
| print( | ||
| f"API started (Kafka connecting in background to " | ||
| f"{KAFKA_HOST}:{KAFKA_PORT})" | ||
| ) | ||
| print(f"API started (Kafka connecting in background to {KAFKA_HOST}:{KAFKA_PORT})") | ||
|
|
||
| yield | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| from .clickhouse_conf import ClickhouseConf | ||
| from .conf import Conf | ||
| from .influx_conf import InfluxConf | ||
| from .schema_conf import SchemaConf | ||
|
|
||
| __all__ = ["ClickhouseConf", "InfluxConf", "SchemaConf"] | ||
|
|
||
|
|
||
| def load_all() -> None: | ||
| """Load all configs""" | ||
| config: Conf | ||
| for config in [ClickhouseConf, InfluxConf, SchemaConf]: | ||
| config.load() |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,15 +1,19 @@ | ||||||||||||||||||||||||||||
| class Conf: | ||||||||||||||||||||||||||||
| @classmethod | ||||||||||||||||||||||||||||
| def load_env(cls,file:str=".env")->None: | ||||||||||||||||||||||||||||
| def load_env(cls, file: str = ".env") -> None: | ||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||
| Load configuration from env | ||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||
| raise NotImplementedError | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| @classmethod | ||||||||||||||||||||||||||||
| def get(cls)->dict: | ||||||||||||||||||||||||||||
| def get(cls) -> dict: | ||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||
| Get a dict with the loaded confs. | ||||||||||||||||||||||||||||
| If not loaded yet, then load in the function | ||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||
| raise NotImplementedError | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| @classmethod | ||||||||||||||||||||||||||||
| def load(cls) -> None: | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
| def load(cls) -> None: | |
| def load(cls) -> None: | |
| """ | |
| Load configuration for this Conf subclass. | |
| By default, this delegates to ``load_env`` so that env-based | |
| configuration classes only need to implement ``load_env``. | |
| Subclasses that load configuration from other sources (for example, | |
| YAML files) are expected to override this method and provide their | |
| own loading logic instead of, or in addition to, calling | |
| ``load_env``. | |
| """ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The SQL files are copied to /docker-entrypoint-initdb.d/ which is the standard ClickHouse initialization directory. However, there's no guarantee about the execution order of multiple SQL files. The file is named with a "01_" prefix suggesting ordering, but this should be documented or verified that ClickHouse processes files in alphanumeric order. If there are dependencies between SQL files, this could cause initialization failures.