SIENTIAPDE-1445
Enhance PI Web API integration and update test configurations - Adjusted execution counts in tests.ipynb for better notebook state management. - Introduced a new pi_web_api_query structure in tests.ipynb for improved API configuration. - Updated API class to format timestamps using DATETIME_FORMAT_WITH_TZ. - Refactored PIWebAPIClient to ensure correct web ID retrieval and emit metrics accurately. - Streamlined workflow parameters in pi_web_api_scouter.py for clarity and flexibility.
This commit is contained in:
@@ -11,7 +11,7 @@ with workflow.unsafe.imports_passed_through():
|
|||||||
from sientia_do.observability.sientia_monitoring import SientiaMonitoring
|
from sientia_do.observability.sientia_monitoring import SientiaMonitoring
|
||||||
|
|
||||||
from scouter.utils.clients.pi_web_api_client import PIWebAPIClient
|
from scouter.utils.clients.pi_web_api_client import PIWebAPIClient
|
||||||
|
from sientia_do.temporal.constants import DATETIME_FORMAT_WITH_TZ
|
||||||
|
|
||||||
class API(SientiaMonitoring):
|
class API(SientiaMonitoring):
|
||||||
"""
|
"""
|
||||||
@@ -127,6 +127,8 @@ class API(SientiaMonitoring):
|
|||||||
)
|
)
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
|
latest_values['timestamp'] = latest_values['timestamp'].dt.strftime(DATETIME_FORMAT_WITH_TZ)
|
||||||
|
|
||||||
self.debug(f'Latest values: {latest_values}', metadata=metadata)
|
self.debug(f'Latest values: {latest_values}', metadata=metadata)
|
||||||
self.info(f'Gathered {len(latest_values)} tag values', metadata=metadata)
|
self.info(f'Gathered {len(latest_values)} tag values', metadata=metadata)
|
||||||
|
|
||||||
|
|||||||
@@ -212,10 +212,7 @@ class PIWebAPIClient(SientiaMonitoring):
|
|||||||
metric_object=metrics.GENERIC_REST_CLIENT_LAG,
|
metric_object=metrics.GENERIC_REST_CLIENT_LAG,
|
||||||
tags=core_labels,
|
tags=core_labels,
|
||||||
)
|
)
|
||||||
await self.emit_metric(
|
|
||||||
metric_object=metrics.GENERIC_REST_READ_COUNT,
|
|
||||||
tags=core_labels,
|
|
||||||
)
|
|
||||||
|
|
||||||
status_code = c.getinfo(pycurl.RESPONSE_CODE)
|
status_code = c.getinfo(pycurl.RESPONSE_CODE)
|
||||||
body = buffer.getvalue().decode('utf-8', errors='replace')
|
body = buffer.getvalue().decode('utf-8', errors='replace')
|
||||||
@@ -227,6 +224,10 @@ class PIWebAPIClient(SientiaMonitoring):
|
|||||||
)
|
)
|
||||||
raise PIMSRequestError(f"HTTP {status_code} calling '{full_url}': {body[:200]}")
|
raise PIMSRequestError(f"HTTP {status_code} calling '{full_url}': {body[:200]}")
|
||||||
|
|
||||||
|
await self.emit_metric(
|
||||||
|
metric_object=metrics.GENERIC_REST_READ_COUNT,
|
||||||
|
tags=core_labels,
|
||||||
|
)
|
||||||
try:
|
try:
|
||||||
return json.loads(body)
|
return json.loads(body)
|
||||||
except json.JSONDecodeError as e:
|
except json.JSONDecodeError as e:
|
||||||
@@ -315,7 +316,7 @@ class PIWebAPIClient(SientiaMonitoring):
|
|||||||
if isinstance(it, dict) and 'Timestamp' in it and 'Value' in it:
|
if isinstance(it, dict) and 'Timestamp' in it and 'Value' in it:
|
||||||
ts = it.get('Timestamp')
|
ts = it.get('Timestamp')
|
||||||
val = it.get('Value')
|
val = it.get('Value')
|
||||||
web_id = web_ids.get(tag_name)
|
web_id = web_ids[tag_name]['webid']
|
||||||
if ts is not None:
|
if ts is not None:
|
||||||
records.append(
|
records.append(
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -78,15 +78,17 @@ class PIWebAPIScouter:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pi_web_api_query = input_data['pi_web_api_query']
|
||||||
|
|
||||||
data = await workflow.execute_local_activity_method(
|
data = await workflow.execute_local_activity_method(
|
||||||
Activities.get_tag_values,
|
Activities.get_tag_values,
|
||||||
{
|
{
|
||||||
**metadata,
|
**metadata,
|
||||||
'endpoint': input_data['endpoint'],
|
'endpoint': pi_web_api_query['endpoint'],
|
||||||
'web_ids': input_data['model_tags'],
|
'web_ids': input_data['model_tags'],
|
||||||
'period': input_data['period'],
|
'period': pi_web_api_query['period'],
|
||||||
'api_timeout': input_data['api_timeout'],
|
'max_count': pi_web_api_query.get('max_count', 1),
|
||||||
'max_count': input_data.get('max_count', 1),
|
'api_timeout': pi_web_api_query['api_timeout'],
|
||||||
},
|
},
|
||||||
start_to_close_timeout=timedelta(seconds=60),
|
start_to_close_timeout=timedelta(seconds=60),
|
||||||
retry_policy=retry_policy,
|
retry_policy=retry_policy,
|
||||||
|
|||||||
22
tests.ipynb
22
tests.ipynb
@@ -2,7 +2,7 @@
|
|||||||
"cells": [
|
"cells": [
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 2,
|
"execution_count": 1,
|
||||||
"id": "9d16b24a",
|
"id": "9d16b24a",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
@@ -38,7 +38,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 3,
|
"execution_count": 14,
|
||||||
"id": "5e344fb0",
|
"id": "5e344fb0",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
@@ -69,20 +69,26 @@
|
|||||||
" \"CI-W3W03S1\": {\n",
|
" \"CI-W3W03S1\": {\n",
|
||||||
" \"aggr_func\": \"avg\",\n",
|
" \"aggr_func\": \"avg\",\n",
|
||||||
" \"data_range\": [\n",
|
" \"data_range\": [\n",
|
||||||
" -100,\n",
|
" -100000,\n",
|
||||||
" 100\n",
|
" 100000\n",
|
||||||
" ],\n",
|
" ],\n",
|
||||||
" \"webid\": \"F1DP-7fYgsRTtUOa7V9NIwSujATFUAAAUElIQVZDXENJLVczVzAzUzE\"\n",
|
" \"webid\": \"F1DP-7fYgsRTtUOa7V9NIwSujATFUAAAUElIQVZDXENJLVczVzAzUzE\"\n",
|
||||||
" },\n",
|
" },\n",
|
||||||
" \"CI-W3A05F1\": {\n",
|
" \"CI-W3A05F1\": {\n",
|
||||||
" \"aggr_func\": \"lts\",\n",
|
" \"aggr_func\": \"lts\",\n",
|
||||||
" \"data_range\": [\n",
|
" \"data_range\": [\n",
|
||||||
" -100,\n",
|
" -100000,\n",
|
||||||
" 100\n",
|
" 100000\n",
|
||||||
" ],\n",
|
" ],\n",
|
||||||
" \"webid\": \"F1DP-7fYgsRTtUOa7V9NIwSujAkVMAAAUElIQVZDXENJLVczQTA1RjE\"\n",
|
" \"webid\": \"F1DP-7fYgsRTtUOa7V9NIwSujAkVMAAAUElIQVZDXENJLVczQTA1RjE\"\n",
|
||||||
" }\n",
|
" }\n",
|
||||||
" },\n",
|
" },\n",
|
||||||
|
" \"pi_web_api_query\": {\n",
|
||||||
|
" \"endpoint\": \"/streamsets/recorded\",\n",
|
||||||
|
" \"period\": \"*-1d\",\n",
|
||||||
|
" \"max_count\": 1,\n",
|
||||||
|
" \"api_timeout\": 5\n",
|
||||||
|
" },\n",
|
||||||
" \"offset\": \"0m\",\n",
|
" \"offset\": \"0m\",\n",
|
||||||
" \"retention_time\": 3600,\n",
|
" \"retention_time\": 3600,\n",
|
||||||
" \"schedule_name\": \"pi-web-api-scouter-test\",\n",
|
" \"schedule_name\": \"pi-web-api-scouter-test\",\n",
|
||||||
@@ -97,7 +103,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": 6,
|
||||||
"id": "9350bff3",
|
"id": "9350bff3",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
@@ -112,7 +118,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 7,
|
"execution_count": 18,
|
||||||
"id": "45712d7a",
|
"id": "45712d7a",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
|
|||||||
Reference in New Issue
Block a user