From b5e1ea7217bb5567b6773ce7577c60b5ca910aa6 Mon Sep 17 00:00:00 2001 From: "sunil.n" Date: Thu, 27 Nov 2025 16:06:24 +0530 Subject: [PATCH] Implement query api in data.py - to connect influxdb, fetch NSSI performance reports periodically Change-Id: Id449267a2379f261e595d7463ff212bea9c9aea8 Signed-off-by: sunil.n --- .../rapp-slice-prb-prediction/README.md | 19 +++++++++++++++++++ .../rapp-slice-prb-prediction/src/data.py | 13 ++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/sample-rapp-generator/rapp-slice-prb-prediction/README.md b/sample-rapp-generator/rapp-slice-prb-prediction/README.md index f027fe2..109b2c1 100644 --- a/sample-rapp-generator/rapp-slice-prb-prediction/README.md +++ b/sample-rapp-generator/rapp-slice-prb-prediction/README.md @@ -265,6 +265,25 @@ The method returns a pandas DataFrame with the following structure: - `{tag_nssi_id}`: Network Slice Subnet Instance identifier - KPI fields as configured in `field_names` (PRB usage, data volume, RRC connections) +##### query() +The `query()` method provides robust database query execution with automatic retry logic for handling temporary connection failures. This method ensures reliable data retrieval by implementing exponential backoff retry mechanism. + +**Features:** +- **Automatic Retry**: Retries failed queries with 60-second delays +- **Error Handling**: Catches `RequestException` and `ConnectionError` for network issues +- **Logging**: Detailed error logging for troubleshooting connection issues +- **Data Frame Return**: Returns results as pandas DataFrame for easy analysis + +**Usage Example:** +```python +# Execute custom query with retry logic +db = DATABASE() +if db.connect(): + query = 'from(bucket:"test") |> range(start:-1h)' + result = db.query(query) + # Process query results +``` + #### Integration with RAPP Architecture The DATABASE class serves as the foundation for all data operations in the RAPP: diff --git a/sample-rapp-generator/rapp-slice-prb-prediction/src/data.py b/sample-rapp-generator/rapp-slice-prb-prediction/src/data.py index 652fe8c..0a1b303 100644 --- a/sample-rapp-generator/rapp-slice-prb-prediction/src/data.py +++ b/sample-rapp-generator/rapp-slice-prb-prediction/src/data.py @@ -97,4 +97,15 @@ class DATABASE(object): ''' result = self.query(query) - return result \ No newline at end of file + return result + + # Query data + def query(self, query): + while True: + try: + query_api = self.client.query_api() + result = query_api.query_data_frame(org=self.org, query=query) + return result + except (RequestException, ConnectionError) as e: + logger.error(f'Failed to query influxdb: {e}, retrying in 60 seconds...') + time.sleep(60) \ No newline at end of file -- 2.16.6