The /api/reload endpoint reloads configuration data from source files and rebuilds the knowledge graph. Use this when configuration files have been updated.
Endpoint
Request Body
No request body required.
Response
Success message confirming data was reloaded.
Examples
cURL
Python
JavaScript
Response
curl -X POST http://localhost:8000/api/reload
What Gets Reloaded
The reload process:
Clear existing graph
Deletes all nodes and edges from Neo4j using storage.clear_graph().
Re-parse configuration files
Parses all configuration files in the data/ directory:
data/docker-compose.yml (Docker Compose services)
data/teams.yaml (Team ownership)
data/k8s-deployments.yaml (Kubernetes resources, if present)
Rebuild graph
Adds all nodes and edges back to Neo4j with updated data.
The reload process clears the entire graph. Any manual changes made directly in Neo4j will be lost.
Use Cases
After Configuration Changes
Reload after updating configuration files:
# Update docker-compose.yml
vim data/docker-compose.yml
# Reload to see changes
curl -X POST http://localhost:8000/api/reload
Scheduled Refresh
Set up a cron job to periodically reload from source control:
#!/bin/bash
# reload-graph.sh
cd /path/to/ekg
git pull origin main
curl -X POST http://localhost:8000/api/reload
# Reload every hour
0 * * * * /path/to/reload-graph.sh
Integration with CI/CD
Trigger reload after configuration deployments:
# .github/workflows/deploy-config.yml
name : Deploy Config
on :
push :
paths :
- 'data/**'
jobs :
deploy :
runs-on : ubuntu-latest
steps :
- name : Checkout
uses : actions/checkout@v2
- name : Deploy configs
run : |
scp -r data/* prod-server:/app/data/
- name : Reload graph
run : |
curl -X POST https://ekg.company.com/api/reload
File Watch Script
Automatically reload when files change:
import time
import requests
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
class ConfigChangeHandler ( FileSystemEventHandler ):
def on_modified ( self , event ):
if event.src_path.endswith(( '.yml' , '.yaml' )):
print ( f "Config file changed: { event.src_path } " )
print ( "Reloading graph..." )
response = requests.post( "http://localhost:8000/api/reload" )
print (response.json()[ 'message' ])
observer = Observer()
observer.schedule(ConfigChangeHandler(), path = './data' , recursive = True )
observer.start()
try :
while True :
time.sleep( 1 )
except KeyboardInterrupt :
observer.stop()
observer.join()
Error Handling
Reload Failed
{
"detail" : "Failed to parse docker-compose.yml: Invalid YAML syntax"
}
Status Code : 500
Cause : Configuration file has syntax errors. Check:
YAML syntax is valid
Required fields are present
File permissions allow reading
Neo4j Connection Failed
{
"detail" : "Failed to connect to Neo4j"
}
Status Code : 500
Cause : Cannot connect to Neo4j database. Check:
Neo4j is running
NEO4J_URI is correct
Network connectivity
Implementation
From chat/app.py:185-193:
@app.post ( "/api/reload" )
async def reload_data ():
"""Reload configuration data."""
try :
await load_configuration_data()
return { "message" : "Data reloaded successfully" }
except Exception as e:
logger.error( f "Failed to reload data: { e } " )
raise HTTPException( status_code = 500 , detail = str (e))
The load_configuration_data() function from chat/app.py:90-134:
async def load_configuration_data ():
"""Load and parse configuration files into the graph."""
global storage
logger.info( "Loading configuration data..." )
# Clear existing data
storage.clear_graph()
data_dir = Path( "data" )
all_nodes = []
all_edges = []
# Load Docker Compose data
docker_compose_file = data_dir / "docker-compose.yml"
if docker_compose_file.exists():
connector = DockerComposeConnector()
nodes, edges = connector.parse( str (docker_compose_file))
all_nodes.extend(nodes)
all_edges.extend(edges)
# Load Teams data
teams_file = data_dir / "teams.yaml"
if teams_file.exists():
connector = TeamsConnector()
nodes, edges = connector.parse( str (teams_file))
all_nodes.extend(nodes)
all_edges.extend(edges)
# Load Kubernetes data (optional)
k8s_file = data_dir / "k8s-deployments.yaml"
if k8s_file.exists():
connector = KubernetesConnector()
nodes, edges = connector.parse( str (k8s_file))
all_nodes.extend(nodes)
all_edges.extend(edges)
# Store all data in graph
storage.add_nodes(all_nodes)
storage.add_edges(all_edges)
Reload time depends on the size of your configuration files. Expect 1-5 seconds for typical configurations.
Reload Duration
Small (< 20 services): < 1 second
Medium (20-100 services): 1-3 seconds
Large (100+ services): 3-10 seconds
Downtime
During reload:
Graph queries will return stale data until reload completes
The API remains available
Consider implementing a maintenance mode flag
Best Practices
Validate before reload
Run configuration validation first: python scripts/validate_config.py
# Only reload if validation passes
curl -X POST http://localhost:8000/api/reload
Backup before reload
Export the graph before destructive operations: # Neo4j dump
docker exec neo4j neo4j-admin dump --to=/backups/graph-backup.dump
Monitor reload status
Check application logs during reload:
Verify after reload
Confirm data loaded correctly: curl http://localhost:8000/api/entities | jq '.services | length'
Configuration Guide Learn about configuration files
Data Sources Configure data source connectors