Implement query api in data.py - to connect influxdb, fetch NSSI performance reports... 20/15320/1
authorsunil.n <sunil.n@samsung.com>
Thu, 27 Nov 2025 10:36:24 +0000 (16:06 +0530)
committersunil.n <sunil.n@samsung.com>
Thu, 27 Nov 2025 10:36:24 +0000 (16:06 +0530)
Change-Id: Id449267a2379f261e595d7463ff212bea9c9aea8
Signed-off-by: sunil.n <sunil.n@samsung.com>
sample-rapp-generator/rapp-slice-prb-prediction/README.md
sample-rapp-generator/rapp-slice-prb-prediction/src/data.py

index f027fe2..109b2c1 100644 (file)
@@ -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:
index 652fe8c..0a1b303 100644 (file)
@@ -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