This file provides guidance to WARP (warp.dev) when working with code in this repository.
This is the Transpara OPC UA Extractor, a Python-based service that connects to OPC UA servers, monitors data nodes, and forwards data to TStore. It supports three operation modes: ACTIVE (full operation), LOG_ONLY (monitoring without data forwarding), and CONFIG (configuration validation only).
app/main.py: Entry point with operation mode management, resource lifecycle, and FastAPI serverapp/opcua_client.py: Core OPC UA client logic with connection management, subscription handling, and enumeration detectionapp/core/config.py: Configuration management using Pydantic settings with YAML config loadingapp/api/: FastAPI REST API for testing connections and validating configurationsapp/state.py: Application state management singleton
The application follows a complex state machine documented in the README.md mermaid diagram:
- Start → Operation Mode Validation → Resource Initialization
- OPC UA Connection → Node Monitoring → Data Handling
- Error Handling with automatic reconnection and retry logic
- Async Context Manager:
manage_resources()handles complete resource lifecycle - State Management: Connection state tracking with counters (
connection_success_count,consecutive_errors) - Enumeration Caching:
OpcUaEnumerationsManagerdetects and caches OPC UA enumerations - Retry Logic: Exponential backoff for connections and subscriptions
# Install dependencies
pip install -r requirements.txt
# Run the application directly
python app/main.py
# Run FastAPI development server only
python start.py# Build Docker image
docker build -t transpara/extractor-opcua:dev .
# Build and push (production)
./build.sh
# Run with docker-compose
docker-compose up# The application includes built-in REST API endpoints for testing:
# - POST /api/v1/test-connection - Test OPC UA server connectivity
# - POST /api/v1/validate-items - Validate monitored items
# - GET /api/v1/available-items - Get available OPC UA items
# - GET /api/v1/health - Health check endpointapp/opcua_config.yaml: OPC UA server settings, monitored items, security configuration- Environment Variables: Runtime settings via
.envor container environment
OPERATION_MODE: Controls application behavior (ACTIVE/LOG_ONLY/CONFIG)OPCUA_ENDPOINT_URL: Target OPC UA server URLTSTORE_API_URL: Destination for data forwarding- Security settings:
security_mode,security_policy, user identity configuration
The application supports live configuration updates through settings.wait_for_config_update() mechanism that triggers resource restarts when configuration changes.
# Deploy using Helm chart
helm install extractor-opcua ./helm/
# The helm chart includes:
# - Deployment with configurable replicas
# - Service for API access
# - ConfigMap for configuration managementKey environment variables for container deployment:
OPCUA_ENDPOINT_URL,TSTORE_API_URL,OPERATION_MODEEXTRACTOR_PREFIX,SOURCE_TZ,LOG_LEVEL- TStore configuration:
TSTORE_FLUSH_SIZE,TSTORE_FLUSH_INTERVAL_SECONDS
- Connection Management: Automatic reconnection with exponential backoff
- Subscription Monitoring: Error threshold tracking with forced reconnection
- Health Checks: Docker health check endpoint at
/health
- Uses Transpara's
tloggingframework - Configurable log levels via
LOG_LEVELenvironment variable - Structured error tracking with counters and state information
- Health Check:
GET /health- Docker health check endpoint - Connection Test:
POST /test-connection- Validate OPC UA connectivity - Item Validation:
POST /validate-items- Test monitored item configuration
- Core:
fastapi,asyncua,pydantic-settings,transpara-sdk - Runtime:
uvicornfor ASGI server
app/core/: Configuration and operation mode managementapp/api/: FastAPI routes and request/response schemasapp/schemas.py: Pydantic models for API and configurationapp/opcua_client.py: Main OPC UA client implementation with enumeration handling
- Integration tests via REST API endpoints
- Configuration validation through
/validate-itemsendpoint - Connection testing via
/test-connectionendpoint - Health monitoring through Docker healthcheck
Uses semantic-release for automated versioning:
- Conventional Commits:
feat:(minor),fix:(patch), breaking changes (major) - Automated: GitHub Actions workflow on main branch pushes
- Docker Images: Tagged and pushed to
transpara/extractor-opcua