Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions software/edge/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from contextlib import asynccontextmanager

from fastapi import BackgroundTasks, FastAPI, HTTPException
from fastapi.middleware.cors import CORSMiddleware

from app import db_client, poller, session_manager
from app.config import get_settings
Expand Down Expand Up @@ -46,6 +47,15 @@ async def lifespan(app: FastAPI):

app = FastAPI(title="Edge Service", lifespan=lifespan, docs_url="/")

# Allow Grafana dashboard to call the Swagger endpoints from the browser.
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)


async def high_frequency_polling_loop():
"""The main data collection loop that runs in the background."""
Expand Down
35 changes: 16 additions & 19 deletions software/edge/scripts/setup-replication.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,20 @@ fi

echo "Remote Org ID: $REMOTE_ORG_ID"

# Delete existing remote if it exists
# Delete existing replication with our name if it exists
echo "Cleaning up existing replication (if any)..."
EXISTING_REPL_ID=$(influx replication list --host "$INFLUX_HOST" --token "$INFLUX_TOKEN" --org "$INFLUX_ORG" 2>/dev/null | awk 'NR>1 && $2=="edge-to-ground" {print $1; exit}')
if [ -n "$EXISTING_REPL_ID" ]; then
echo "Deleting existing replication ID: $EXISTING_REPL_ID"
influx replication delete --id "$EXISTING_REPL_ID" --host "$INFLUX_HOST" --token "$INFLUX_TOKEN" 2>/dev/null || true
fi

# Delete existing remote with our name if it exists
echo "Cleaning up existing remote connection (if any)..."
EXISTING_REMOTE_ID=$(influx remote list --host $INFLUX_HOST --token $INFLUX_TOKEN --org $INFLUX_ORG --json 2>/dev/null | awk -F'"' '/"id":/ {print $4; exit}')
EXISTING_REMOTE_ID=$(influx remote list --host "$INFLUX_HOST" --token "$INFLUX_TOKEN" --org "$INFLUX_ORG" 2>/dev/null | awk 'NR>1 && $2=="ground-station" {print $1; exit}')
if [ -n "$EXISTING_REMOTE_ID" ]; then
echo "Deleting existing remote ID: $EXISTING_REMOTE_ID"
influx remote delete --id "$EXISTING_REMOTE_ID" \
--host "$INFLUX_HOST" --token "$INFLUX_TOKEN" 2>/dev/null || true
influx remote delete --id "$EXISTING_REMOTE_ID" --host "$INFLUX_HOST" --token "$INFLUX_TOKEN" 2>/dev/null || true
fi

# Create remote connection
Expand All @@ -49,13 +56,12 @@ influx remote create \
--remote-org-id "$REMOTE_ORG_ID" \
--org "$INFLUX_ORG" \
--host "$INFLUX_HOST" \
--token "$INFLUX_TOKEN"

# Get remote ID
REMOTE_ID=$(influx remote list --host $INFLUX_HOST --token $INFLUX_TOKEN --org $INFLUX_ORG --json | awk -F'"' '/"id":/ {print $4; exit}')
--token "$INFLUX_TOKEN" >/dev/null
# Fetch remote id from list output (table format)
REMOTE_ID=$(influx remote list --host "$INFLUX_HOST" --token "$INFLUX_TOKEN" --org "$INFLUX_ORG" 2>/dev/null | awk 'NR>1 && $2=="ground-station" {print $1; exit}')

# Get bucket ID
BUCKET_ID=$(influx bucket list --host $INFLUX_HOST --token $INFLUX_TOKEN --org $INFLUX_ORG --name $INFLUX_BUCKET --json | awk -F'"' '/"id":/ {print $4; exit}')
BUCKET_ID=$(influx bucket list --host "$INFLUX_HOST" --token "$INFLUX_TOKEN" --org "$INFLUX_ORG" --name "$INFLUX_BUCKET" 2>/dev/null | awk 'NR>1 {print $1; exit}')

if [ -z "$REMOTE_ID" ] || [ -z "$BUCKET_ID" ]; then
echo "Error: Could not get remote ID or bucket ID"
Expand All @@ -65,15 +71,6 @@ fi
echo "Remote ID: $REMOTE_ID"
echo "Bucket ID: $BUCKET_ID"

# Delete existing replication if it exists
echo "Cleaning up existing replication (if any)..."
EXISTING_REPL_ID=$(influx replication list --host $INFLUX_HOST --token $INFLUX_TOKEN --org $INFLUX_ORG --json 2>/dev/null | awk -F'"' '/"id":/ {print $4; exit}')
if [ -n "$EXISTING_REPL_ID" ]; then
echo "Deleting existing replication ID: $EXISTING_REPL_ID"
influx replication delete --id "$EXISTING_REPL_ID" \
--host "$INFLUX_HOST" --token "$INFLUX_TOKEN" 2>/dev/null || true
fi

# Create replication
echo "Creating replication stream..."
influx replication create \
Expand All @@ -90,5 +87,5 @@ echo "========================================="
echo "Replication setup complete!"
echo "========================================="
echo ""
influx replication list --host $INFLUX_HOST --token $INFLUX_TOKEN --org $INFLUX_ORG
influx replication list --host "$INFLUX_HOST" --token "$INFLUX_TOKEN" --org "$INFLUX_ORG"
echo ""
2 changes: 1 addition & 1 deletion software/ground/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ services:
- GF_SERVER_ROOT_URL=http://ground.local/
- GF_SECURITY_ADMIN_USER=${GRAFANA_ADMIN_USER:-admin}
- GF_SECURITY_ADMIN_PASSWORD=${GRAFANA_ADMIN_PASSWORD:-admin123}
- GF_INSTALL_PLUGINS=grafana-clock-panel
- GF_INSTALL_PLUGINS=grafana-clock-panel,volkovlabs-form-panel
- GF_PATHS_PROVISIONING=/etc/grafana/provisioning
- DATABASE__ORG=${DATABASE__ORG}
- DATABASE__BUCKET=${DATABASE__BUCKET}
Expand Down
Loading