Skip to main content

A comprehensive database management library for Brownie metadata with backup, SSL, and monitoring capabilities

Project description

Brownie Metadata Database

Version License Python PostgreSQL

The Brownie Metadata Database is the central metadata store for the Brownie incident assistant platform. It provides enterprise-grade data management, access control, and operational capabilities for managing incident data, team configurations, and system metadata.

Version 0.1.0 - Complete database infrastructure with enterprise security, monitoring, and high availability features.

Overview

Brownie is an AI-powered incident assistant that helps teams manage and resolve incidents more effectively. This metadata database serves as the backbone for storing and managing:

  • Team Configurations: Team structures, roles, and permissions
  • Incident Metadata: Incident types, priorities, and resolution data
  • Agent Configurations: AI agent settings and behavior parameters
  • User Management: User accounts, authentication, and access control
  • System Statistics: Performance metrics and operational data

Database Schema

The database includes the following core tables:

  • organizations - Multi-tenant organization management
  • teams - Team structures within organizations
  • users - User accounts and authentication
  • incidents - Incident tracking and metadata
  • agent_configs - AI agent configuration settings
  • stats - System performance and usage statistics

System Architecture

graph TB
    subgraph "Brownie Platform"
        A[Brownie Agent] --> B[Config Service]
        B --> C[FastAPI Gateway]
        A --> C
        C --> D[Metadata Database]
    end

Related Repositories:

Quick Start

Prerequisites

  • Docker and Docker Compose
  • Git

1. Clone and Setup

git clone https://github.com/longyi-brownie/brownie-metadata-database.git
cd brownie-metadata-database

2. Generate SSL Certificates

Required before starting services - Generate development certificates for SSL/TLS:

./scripts/setup-dev-certs.sh

This creates:

  • dev-certs/ca.crt - Certificate Authority
  • dev-certs/server.crt - PostgreSQL server certificate
  • dev-certs/server.key - PostgreSQL server private key
  • dev-certs/client.crt - Client certificate for database connections
  • dev-certs/client.key - Client private key for database connections

3. Start Database & Monitoring Services

docker compose up -d

This will start:

  • PostgreSQL with SSL and certificate authentication
  • Database migrations
  • Redis for caching
  • Enterprise metrics sidecar - Custom business & technical metrics
  • Prometheus - Metrics collection and alerting
  • Grafana - Enterprise dashboards ready for copy-paste

4. Verify Everything Works

# Check all services are running
docker compose ps

# Test database connection with certificates
docker compose exec postgres psql -U brownie-fastapi-server -d brownie_metadata -c "SELECT version();"

# Test Redis connection
docker compose exec redis redis-cli ping

# Test metrics collection
curl http://localhost:9091/metrics

# Access Grafana dashboards
open http://localhost:3000
# Login: admin/admin

5. Access Services

  • PostgreSQL: localhost:5432 (certificate auth required)
  • Redis: localhost:6379
  • Prometheus: http://localhost:9090
  • Grafana: http://localhost:3000 (admin/admin)
  • Custom Metrics: http://localhost:9091/metrics

๐Ÿ“ Project Structure

brownie-metadata-database/
โ”œโ”€โ”€ alembic/                    # Database migrations
โ”œโ”€โ”€ k8s/                        # Kubernetes deployment configs
โ”œโ”€โ”€ monitoring/                 # Enterprise monitoring stack
โ”‚   โ”œโ”€โ”€ dashboards/            # Grafana dashboards
โ”‚   โ”œโ”€โ”€ alerts/                # Prometheus alerting rules
โ”‚   โ”œโ”€โ”€ provisioning/          # Grafana auto-configuration
โ”‚   โ””โ”€โ”€ README.md              # Monitoring documentation
โ”œโ”€โ”€ runbooks/                  # Operational procedures
โ”‚   โ”œโ”€โ”€ RUNBOOK-*.md          # Specific runbooks
โ”‚   โ””โ”€โ”€ README.md             # Runbook index
โ”œโ”€โ”€ scripts/                   # Database setup scripts
โ”‚   โ”œโ”€โ”€ init-db.sql           # Database initialization
โ”‚   โ”œโ”€โ”€ setup-dev-certs.sh    # Certificate generation
โ”‚   โ”œโ”€โ”€ setup-postgres-ssl.sh # SSL configuration
โ”‚   โ”œโ”€โ”€ pg_hba.conf           # PostgreSQL auth config
โ”‚   โ””โ”€โ”€ postgresql.conf       # PostgreSQL server config
โ”œโ”€โ”€ src/                       # Core database code
โ”‚   โ”œโ”€โ”€ certificates.py       # Server certificate management
โ”‚   โ””โ”€โ”€ database/             # SQLAlchemy models and connection
โ”œโ”€โ”€ tests/                     # Test suite
โ”œโ”€โ”€ metrics_sidecar/          # Custom metrics collection
โ”œโ”€โ”€ docker-compose.yml        # Complete stack definition
โ”œโ”€โ”€ Dockerfile                # Database migration container
โ”œโ”€โ”€ Dockerfile.metrics        # Metrics sidecar container
โ””โ”€โ”€ README.md                 # This file

Enterprise Monitoring Features

  • โœ… Custom Metrics Sidecar - Collects database, Redis, and business metrics
  • โœ… Ready-to-Use Dashboards - Copy-paste Grafana dashboards for enterprise customers
  • โœ… Alerting Rules - Pre-configured alerts for database health and business metrics
  • โœ… SSL/TLS Configuration - PostgreSQL starts with SSL enabled
  • โœ… Certificate Authentication - Only clients with valid certificates can connect
  • โœ… User Creation - brownie-fastapi-server user created automatically
  • โœ… Database Migrations - Schema applied automatically

๐Ÿ“Š Complete Monitoring Documentation
๐Ÿ“š Operational Runbooks

Kubernetes (Production):

# 1. Apply PostgreSQL configuration
kubectl apply -f k8s/postgres-config.yaml

# 2. Deploy with automated setup
kubectl apply -k k8s/

# PostgreSQL is automatically configured with:
# - pg_hba.conf for certificate auth
# - User creation and permissions
# - Certificate mounting

Manual Setup (If Needed):

-- Create user that matches certificate CN
CREATE USER "brownie-fastapi-server" WITH CERTIFICATE;

-- Grant necessary permissions
GRANT CONNECT ON DATABASE brownie_metadata TO "brownie-fastapi-server";
GRANT USAGE ON SCHEMA public TO "brownie-fastapi-server";
GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA public TO "brownie-fastapi-server";
GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA public TO "brownie-fastapi-server";

What's Automated:

  • โœ… User Creation - brownie-fastapi-server user with certificate auth
  • โœ… Permissions - All necessary database permissions
  • โœ… pg_hba.conf - Certificate authentication configuration
  • โœ… Certificate Mounting - Server certificates in containers
  • โœ… Future Tables - Permissions for Alembic migrations

Docker Compose (Development) - Detailed:

  1. Clone and start the services:
   git clone https://github.com/longyi-brownie/brownie-metadata-database
   cd brownie-metadata-database
   docker compose up -d
  1. Verify the services are running:
   docker compose ps
  1. Check the application:
   curl http://localhost:8000/health

Docker Infrastructure:

graph TB
    subgraph "Docker Compose"
        A[PostgreSQL :5432]
        B[Redis :6379]
        C[Prometheus :9090]
        D[Grafana :3000]
        E[Backup Service]
        F[Migration Service]
    end
    
    subgraph "External Storage"
        G[S3/GCS/Azure]
    end
    
    E -->|Backup| G
    F -->|Schema Updates| A
    A -->|Metrics| C
    C -->|Dashboards| D
    
    style A fill:#e8f5e8
    style E fill:#fff2cc
    style F fill:#fff2cc

Available Components:

  • โœ… PostgreSQL - Primary database
  • โœ… Redis - Caching and sessions
  • โœ… Prometheus - Metrics collection
  • โœ… Grafana - Metrics visualization
  • โœ… Backup Service - Automated database backups
  • โœ… Migration Service - Database schema updates

Future Components:

  • ๐Ÿ”„ Read Replicas - For read scaling (planned)
  • ๐Ÿ”„ Custom Metrics Scraper - PostgreSQL-specific metrics (planned)

Kubernetes (Production) - Detailed:

  1. Deploy to Kubernetes:
   kubectl apply -k k8s/
  1. Check deployment status:
   kubectl get pods -n brownie-metadata
  1. Access the application:
   kubectl port-forward -n brownie-metadata svc/brownie-metadata-app 8000:8000
   curl http://localhost:8000/health

Kubernetes Architecture:

graph TB
    subgraph "Kubernetes Cluster"
        subgraph "brownie-metadata namespace"
            A[App Pods] --> B[PostgreSQL Primary]
            A --> C[PostgreSQL Replicas]
            A --> D[Redis Cluster]
            A --> E[PgBouncer]
        end
        
        subgraph "Monitoring"
            F[Prometheus] --> A
            G[Grafana] --> F
            H[AlertManager] --> F
        end
        
        subgraph "Backup"
            I[Backup CronJob] --> J[Cloud Storage]
        end
    end

Helm Charts (Advanced):

For production deployments with custom configurations:

# Install with Helm
helm install brownie-metadata-db ./k8s/helm \
  --namespace brownie-metadata \
  --create-namespace \
  --set database.replicas=3 \
  --set app.replicas=5

# Scale the deployment
helm upgrade brownie-metadata-db ./k8s/helm \
  --set app.replicas=10 \
  --set database.patroni.replicas=5

Configuration

Environment Variables

Database Configuration:

DB_HOST=postgres
DB_PORT=5432
DB_NAME=brownie_metadata
DB_USER=brownie
DB_SSL_MODE=verify-full
# Certificates automatically read from /certs directory

Certificate Management:

# For development (local certificates)
LOCAL_CERT_DIR=dev-certs

# For production (Vault integration)
VAULT_ENABLED=true
VAULT_URL=https://vault.company.com
VAULT_TOKEN=your-vault-token
VAULT_CERT_PATH=secret/brownie-metadata/certs

Backup Configuration:

BACKUP_PROVIDER=s3
BACKUP_DESTINATION=my-backup-bucket/database
BACKUP_SCHEDULE=0 2 * * *
BACKUP_RETENTION_DAYS=30

Monitoring Configuration:

METRICS_ENABLED=true
METRICS_PORT=8001
LOG_LEVEL=INFO

Kubernetes Configuration

ConfigMap:

apiVersion: v1
kind: ConfigMap
metadata:
  name: brownie-metadata-config
data:
  # Database configuration
  DB_HOST: "postgres"
  DB_PORT: "5432"
  DB_NAME: "brownie_metadata"
  DB_USER: "brownie"
  DB_SSL_MODE: "verify-full"
  
  # Application configuration
  LOG_LEVEL: "INFO"
  METRICS_ENABLED: "true"

Secrets:

apiVersion: v1
kind: Secret
metadata:
  name: brownie-metadata-secrets
type: Opaque
data:
  # These are placeholders - certificates loaded from Vault or local files
  database-client-cert: "PLACEHOLDER_DO_NOT_USE"
  database-client-key: "PLACEHOLDER_DO_NOT_USE"
  database-ca-cert: "PLACEHOLDER_DO_NOT_USE"

Proper Secret Management:

# Option 1: Create from local files (development)
kubectl create secret generic brownie-metadata-secrets \
  --from-file=database-server-cert=dev-certs/server.crt \
  --from-file=database-server-key=dev-certs/server.key \
  --from-file=database-ca-cert=dev-certs/ca.crt

# Option 2: Use Vault (production)
# Certificates automatically loaded from Vault via CertificateManager

Database Connection

Connect via psql

Docker Compose:

docker exec -it brownie-metadata-postgres psql -U brownie -d brownie_metadata

Kubernetes:

kubectl exec -it -n brownie-metadata <postgres-pod> -- psql -U brownie -d brownie_metadata

Test Database Connection

-- Check database version
SELECT version();

-- List all tables
\dt

-- Check table schemas
\d organizations
\d teams
\d users
\d incidents

-- Sample queries
SELECT COUNT(*) FROM organizations;
SELECT COUNT(*) FROM teams;
SELECT COUNT(*) FROM users;
SELECT COUNT(*) FROM incidents;

API Access

Health Check:

curl http://localhost:8000/health

API Documentation:

# OpenAPI/Swagger UI
open http://localhost:8000/docs

# ReDoc documentation
open http://localhost:8000/redoc

Access Control

Database Authentication

Client Certificate Authentication:

  • No passwords - Uses client certificates for authentication
  • Certificate CN: brownie-fastapi-server (matches certificate Common Name)
  • mTLS Support: Mutual TLS verification in production
  • Encrypted Connections: All database traffic encrypted in transit

Certificate Management:

  • Development: Local certificate files (gitignored)
  • Production: Vault PKI automatic certificate generation
  • Rotation: Automatic certificate rotation via Vault

FastAPI Server Authentication

User Authentication (Handled by FastAPI Server):

  • JWT/OAuth: User authentication and authorization
  • RBAC: Role-based access control
  • Organization Scoping: Multi-tenant data isolation
  • API Keys: Service-to-service authentication

Database Access:

  • SQLAlchemy ORM: Type-safe database queries
  • Connection Pooling: Efficient database connections
  • Certificate-based: All database access uses client certificates

Enterprise Features

For enterprise-grade access control including SSO, LDAP integration, advanced RBAC, and compliance features, please contact us at info@brownie-ai.com for licensing information.

Production Deployment

Metrics and Dashboards

The system includes comprehensive monitoring with Grafana dashboards and Prometheus metrics:

Access Dashboards:

# Grafana (admin/admin)
open http://localhost:3000

# Prometheus metrics
open http://localhost:9090

Key Metrics:

  • Request rate and response times
  • Database performance and connections
  • User activity and organization metrics
  • Incident volume and resolution times
  • System resource utilization

Screenshots:

Brownie Business Metrics Dashboard Business metrics dashboard showing organizations, teams, users, and incident trends

Brownie Database Overview Dashboard Database overview dashboard with connection stats, table sizes, and Redis metrics

Alerting

Enterprise-grade alerting with multiple notification channels:

Alert Categories:

  • Critical: Service down, high error rates, SLA breaches
  • Warning: Performance degradation, resource issues
  • Info: User growth, unusual patterns

Notification Channels:

  • PagerDuty integration
  • Slack notifications
  • Email alerts
  • Microsoft Teams

Backup and Disaster Recovery

Automated backup system with cloud storage support:

Supported Providers:

  • AWS S3
  • Google Cloud Storage
  • Azure Blob Storage
  • Local filesystem

Backup Configuration:

# Set backup parameters
export BACKUP_PROVIDER="s3"
export BACKUP_DESTINATION="my-backup-bucket/database"
export BACKUP_SCHEDULE="0 2 * * *"  # Daily at 2 AM
export BACKUP_RETENTION_DAYS="30"
export BACKUP_ACCESS_KEY="your-access-key"
export BACKUP_SECRET_KEY="your-secret-key"

Backup Operations:

# Create backup
curl -X POST http://localhost:8000/backup/create

# List backups
curl http://localhost:8000/backup/list

# Restore backup
curl -X POST http://localhost:8000/backup/restore \
  -H "Content-Type: application/json" \
  -d '{"backup_name": "backup-2024-01-15"}'

Recovery Time Objectives:

  • Local restore: < 5 minutes
  • Cloud restore: < 15 minutes
  • Cross-region: < 30 minutes

Operations

Database Migrations

See Database Migration Runbook for detailed procedures.

Quick Commands:

# Docker Compose
docker compose exec app alembic upgrade head

# Kubernetes
kubectl exec -it -n brownie-metadata <app-pod> -- alembic upgrade head

# Create new migration
alembic revision --autogenerate -m "Add new table"
alembic upgrade head

Scaling Operations

See Scaling Operations Runbook for comprehensive scaling procedures.

Quick Commands:

# Scale application replicas
kubectl scale deployment brownie-metadata-app --replicas=5 -n brownie-metadata

# Add read replicas
kubectl scale statefulset patroni --replicas=3 -n brownie-metadata

# Deploy PgBouncer
kubectl apply -f k8s/pgbouncer.yaml

Disaster Recovery

See Disaster Recovery Runbook for complete recovery procedures.

Quick Commands:

# Restore from backup
kubectl exec -n brownie-metadata deployment/brownie-metadata-app -- python -c "
from src.backup.manager import BackupManager
from src.backup.config import BackupConfig
config = BackupConfig.from_env()
manager = BackupManager(config)
manager.restore_backup('backup_name')
"

Database Sharding for Enterprise

See Database Sharding Runbook for comprehensive sharding strategies and implementation.

Quick Overview:

  • Team-Based Sharding: Route data by team_id for team isolation
  • Time-Based Sharding: Partition by created_at for archival
  • Hybrid Sharding: Combine team and time-based partitioning

Performance Tuning:

  • Database connection pooling
  • Query optimization
  • Index management
  • Cache configuration

Support

Documentation

Getting Help

Contributing

We welcome contributions! Please see our Contributing Guide for details.

License

This project is licensed under the MIT License - see the LICENSE file for details.


Brownie Metadata Database - Enterprise metadata management for incident response

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

brownie_metadata_db-0.1.0.tar.gz (29.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

brownie_metadata_db-0.1.0-py3-none-any.whl (41.2 kB view details)

Uploaded Python 3

File details

Details for the file brownie_metadata_db-0.1.0.tar.gz.

File metadata

  • Download URL: brownie_metadata_db-0.1.0.tar.gz
  • Upload date:
  • Size: 29.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for brownie_metadata_db-0.1.0.tar.gz
Algorithm Hash digest
SHA256 014f3aafdeb9f387ac5fe161d42235095a0ad160deaaa9d59b1148662fe604f4
MD5 6012de85297264be7856d638fae6a139
BLAKE2b-256 cea41713d7b7360890bdf8e0306f638847b0aa08b668cd0f4209404b255fcf39

See more details on using hashes here.

File details

Details for the file brownie_metadata_db-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for brownie_metadata_db-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 99170f067e9a829770659ab187e0c6c03d3cf0d5b1119f1b60837992aba75cf0
MD5 7705c1f3bb312c3f10de0294c5782621
BLAKE2b-256 babcf8184ccc5911f6b1150b30b45170ea876e36f69860d4c830186290631b77

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page