Skip to content

Commit b431247

Browse files
Merge pull request #1476 from julep-ai/f/user-analytics
Metabase
2 parents b9f7c3c + 1935dec commit b431247

File tree

11 files changed

+525
-1
lines changed

11 files changed

+525
-1
lines changed

.env.example

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ SKIP_CHECK_DEVELOPER_HEADERS=true
6161
# Memory Store
6262
# -----------
6363
# defaults to postgres
64-
# MEMORY_STORE_PASSWORD= < your password >
64+
# MEMORY_STORE_PASSWORD= < your password >
65+
MB_JAVA_TIMEZONE=Asia/Calcutta
6566

6667
# Gateway
6768
# ------

analytics/AGENTS.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# AGENTS.md - analytics
2+
3+
This directory contains the Metabase analytics service for the Julep platform.
4+
5+
Key Uses
6+
- Bash commands:
7+
- cd analytics
8+
- docker compose up analytics
9+
- docker buildx bake analytics
10+
- Core files:
11+
- `docker-compose.yml` for service deployment
12+
- `Dockerfile` for Metabase container
13+
- `README.md` for detailed documentation
14+
- Configuration guidelines:
15+
- Set `MEMORY_STORE_PASSWORD` for database access
16+
- Configure `JULEP_HOST` for proper URL generation
17+
- Uses same PostgreSQL instance as agents-api
18+
- Testing instructions:
19+
- Health check: `curl http://localhost:3001/api/health`
20+
- Access dashboard: `http://localhost:3001` or `https://<host>/analytics`
21+
- Repository etiquette:
22+
- Don't commit Metabase database files
23+
- Keep sensitive configuration in environment variables
24+
- Developer environment:
25+
- Requires Docker and Docker Compose
26+
- Connects to memory-store PostgreSQL service
27+
- Unexpected behaviors:
28+
- First run shows setup wizard (this is normal)
29+
- Metabase creates its own database for metadata
30+
31+
# Analytics Service
32+
33+
## Overview
34+
The analytics service provides business intelligence capabilities using Metabase, allowing users to create dashboards, run queries, and analyze data from the Julep platform's PostgreSQL database.
35+
36+
## Architecture
37+
- **Analytics Engine**: Metabase (open-source BI tool)
38+
- **Database**: Shared PostgreSQL instance with agents-api
39+
- **Routing**: Exposed via Traefik at `/analytics` path
40+
- **Authentication**: Metabase's built-in user management
41+
42+
## Key Components
43+
44+
### Metabase Configuration
45+
- **Application Database**: Stores Metabase metadata in PostgreSQL
46+
- **Data Source**: Connects to Julep's main PostgreSQL database
47+
- **Site URL**: Configured for proper link generation
48+
- **SSL**: Handled by Traefik gateway
49+
50+
### Environment Variables
51+
- `MEMORY_STORE_PASSWORD`: PostgreSQL password
52+
- `JULEP_HOST`: Host domain for URL configuration
53+
- `TAG`: Docker image tag for versioning
54+
55+
## Integration Points
56+
- **PostgreSQL**: Direct connection to memory-store service
57+
- **Traefik Gateway**: Reverse proxy with SSL termination
58+
- **Docker Network**: Shares julep-network with other services
59+
60+
## Security Features
61+
- User authentication via Metabase
62+
- SSL/TLS via Traefik
63+
- Database credentials in environment variables
64+
- Network isolation via Docker
65+
66+
## Development Workflow
67+
1. Build image: `docker buildx bake analytics`
68+
2. Deploy service: `docker compose up -d analytics`
69+
3. Access dashboard: Navigate to `/analytics`
70+
4. Complete setup wizard on first run
71+
5. Connect to Julep database
72+
73+
## Monitoring
74+
- Health endpoint at `/api/health`
75+
- Container health checks every 30s
76+
- Logs available via Docker
77+
78+
## AIDEV-NOTE: Metabase service for Julep analytics and reporting

analytics/Dockerfile

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Use the official Metabase image
2+
FROM metabase/metabase:latest
3+
4+
# Install PostgreSQL client for database initialization
5+
USER root
6+
7+
# Check if we're on Alpine (apk) or Debian/Ubuntu (apt-get) and install postgresql-client accordingly
8+
RUN if command -v apk > /dev/null; then \
9+
apk add --no-cache postgresql-client; \
10+
elif command -v apt-get > /dev/null; then \
11+
apt-get update && apt-get install -y postgresql-client && rm -rf /var/lib/apt/lists/*; \
12+
elif command -v yum > /dev/null; then \
13+
yum install -y postgresql; \
14+
else \
15+
echo "No supported package manager found"; exit 1; \
16+
fi
17+
18+
# Create metabase user if it doesn't exist (handle both Alpine and Debian/Ubuntu)
19+
RUN if ! id metabase >/dev/null 2>&1; then \
20+
echo "Creating metabase user"; \
21+
if command -v adduser > /dev/null; then \
22+
# Alpine Linux style
23+
adduser -D -s /bin/false -h /opt/metabase metabase; \
24+
elif command -v useradd > /dev/null; then \
25+
# Debian/Ubuntu style
26+
useradd -r -s /bin/false -d /opt/metabase metabase; \
27+
else \
28+
echo "No supported user creation command found"; exit 1; \
29+
fi; \
30+
else \
31+
echo "metabase user already exists"; \
32+
fi
33+
34+
# Create app directory and set ownership
35+
RUN mkdir -p /app && chown metabase:metabase /app
36+
37+
# Copy initialization scripts
38+
COPY init-metabase-db.sh /app/init-metabase-db.sh
39+
COPY entrypoint.sh /app/entrypoint.sh
40+
RUN chmod +x /app/init-metabase-db.sh /app/entrypoint.sh && \
41+
chown metabase:metabase /app/init-metabase-db.sh /app/entrypoint.sh
42+
43+
# Switch to metabase user
44+
USER metabase
45+
46+
# Show available users for debugging
47+
RUN echo "Available users:" && cat /etc/passwd | cut -d: -f1 | head -10
48+
49+
# AIDEV-NOTE: Custom image with database initialization support
50+
51+
# Expose the default Metabase port
52+
EXPOSE 3000
53+
54+
# Use custom entrypoint
55+
ENTRYPOINT ["/app/entrypoint.sh"]
56+
57+
# Metabase will use environment variables for configuration
58+
# MB_DB_TYPE, MB_DB_HOST, MB_DB_PORT, MB_DB_DBNAME, MB_DB_USER, MB_DB_PASS

analytics/README.md

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
# Julep Analytics Service
2+
3+
This service provides a Metabase analytics dashboard for the Julep platform, allowing users to visualize and analyze data from the PostgreSQL database.
4+
5+
## Overview
6+
7+
The analytics service uses Metabase, an open-source business intelligence tool, to provide:
8+
- Interactive dashboards and visualizations
9+
- SQL query interface for data exploration
10+
- Scheduled reports and alerts
11+
- User access management
12+
13+
## Architecture
14+
15+
- **Service**: Metabase (latest version)
16+
- **Database**: Connects to the same PostgreSQL instance as agents-api
17+
- **Routing**: Exposed via Traefik gateway at `/analytics`
18+
- **SSL**: Automatically handled by Traefik with Let's Encrypt
19+
20+
## Configuration
21+
22+
### Environment Variables
23+
24+
- `MEMORY_STORE_PASSWORD`: Password for PostgreSQL connection (default: `julep_secure_password`)
25+
- `JULEP_HOST`: Host domain for the analytics URL (default: `localhost`)
26+
- `TAG`: Docker image tag (default: `dev`)
27+
28+
### Database Connection
29+
30+
Metabase connects to the PostgreSQL database with:
31+
- Host: `memory-store`
32+
- Port: `5432`
33+
- Database: `postgres` (for Julep data), `metabase` (for Metabase metadata)
34+
- Username: `postgres`
35+
- Password: Value of `MEMORY_STORE_PASSWORD`
36+
37+
## Deployment
38+
39+
### Using Docker Compose
40+
41+
```bash
42+
# Deploy with other services
43+
docker compose --profile multi-tenant up -d
44+
45+
# Deploy only analytics
46+
docker compose -f analytics/docker-compose.yml up -d
47+
```
48+
49+
### Building the Image
50+
51+
```bash
52+
# Using docker-bake
53+
docker buildx bake analytics
54+
55+
# Using docker build
56+
docker build -t julepai/analytics:dev analytics/
57+
```
58+
59+
## Access
60+
61+
Once deployed, the analytics dashboard is available at:
62+
- Local: `http://localhost:3001`
63+
- Via Gateway: `https://<JULEP_HOST>/analytics`
64+
65+
### Initial Setup
66+
67+
1. Navigate to the analytics URL
68+
2. Create an admin account
69+
3. Connect to the Julep database:
70+
- Database Type: PostgreSQL
71+
- Host: `memory-store`
72+
- Port: `5432`
73+
- Database: `postgres`
74+
- Username: `postgres`
75+
- Password: (use `MEMORY_STORE_PASSWORD` value)
76+
77+
## Security
78+
79+
- Authentication is handled by Metabase's built-in user management
80+
- SSL/TLS is provided by Traefik gateway
81+
- Database credentials are managed via environment variables
82+
- CORS headers are configured in Traefik
83+
84+
## Monitoring
85+
86+
Health check endpoint: `http://analytics:3000/api/health`
87+
88+
## Development
89+
90+
### Local Development
91+
92+
```bash
93+
# Run Metabase locally
94+
docker run -d -p 3000:3000 \
95+
-e MB_DB_TYPE=postgres \
96+
-e MB_DB_HOST=localhost \
97+
-e MB_DB_PORT=5432 \
98+
-e MB_DB_DBNAME=metabase \
99+
-e MB_DB_USER=postgres \
100+
-e MB_DB_PASS=your_password \
101+
--name metabase metabase/metabase
102+
```
103+
104+
### Customization
105+
106+
To customize Metabase:
107+
1. Modify environment variables in `docker-compose.yml`
108+
2. Add custom plugins or themes via Dockerfile
109+
3. Configure additional settings via Metabase admin panel
110+
111+
## Troubleshooting
112+
113+
### Common Issues
114+
115+
1. **Cannot connect to database**
116+
- Verify PostgreSQL is running
117+
- Check network connectivity between containers
118+
- Confirm credentials are correct
119+
120+
2. **Analytics not accessible via gateway**
121+
- Check Traefik configuration
122+
- Verify analytics service is healthy
123+
- Review gateway logs
124+
125+
3. **Metabase setup wizard appears**
126+
- This is normal on first run
127+
- Complete the setup to initialize Metabase
128+
129+
## AIDEV-NOTE: Analytics service integrated with existing Julep infrastructure

analytics/docker-bake.hcl

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
variable "TAG" {
2+
default = "..."
3+
}
4+
5+
variable "GIT_SHA" {
6+
default = "..."
7+
}
8+
9+
group "default" {
10+
targets = [
11+
"agents-api",
12+
"agents-api-worker",
13+
"memory-store",
14+
"integrations",
15+
"gateway",
16+
"blob-store",
17+
"analytics",
18+
// "code-interpreter",
19+
]
20+
}
21+
22+
target "agents-api" {
23+
context = "./agents-api"
24+
dockerfile = "Dockerfile"
25+
tags = [
26+
"julepai/agents-api:${TAG}",
27+
"julepai/agents-api:git-${GIT_SHA}"
28+
]
29+
}
30+
31+
target "agents-api-worker" {
32+
context = "./agents-api"
33+
dockerfile = "Dockerfile.worker"
34+
tags = [
35+
"julepai/worker:${TAG}",
36+
"julepai/worker:git-${GIT_SHA}"
37+
]
38+
}
39+
40+
target "memory-store" {
41+
context = "./memory-store"
42+
dockerfile = "Dockerfile"
43+
tags = [
44+
"julepai/memory-store:${TAG}",
45+
"julepai/memory-store:git-${GIT_SHA}"
46+
]
47+
}
48+
49+
target "integrations" {
50+
context = "./integrations-service"
51+
dockerfile = "Dockerfile"
52+
tags = [
53+
"julepai/integrations:${TAG}",
54+
"julepai/integrations:git-${GIT_SHA}"
55+
]
56+
}
57+
58+
target "gateway" {
59+
context = "./gateway"
60+
dockerfile = "Dockerfile"
61+
tags = [
62+
"julepai/gateway:${TAG}",
63+
"julepai/gateway:git-${GIT_SHA}"
64+
]
65+
}
66+
67+
target "blob-store" {
68+
context = "./blob-store"
69+
dockerfile = "Dockerfile"
70+
tags = [
71+
"julepai/blob-store:${TAG}",
72+
"julepai/blob-store:git-${GIT_SHA}"
73+
]
74+
}
75+
76+
target "analytics" {
77+
context = "./analytics"
78+
dockerfile = "Dockerfile"
79+
tags = [
80+
"julepai/analytics:${TAG}",
81+
"julepai/analytics:git-${GIT_SHA}"
82+
]
83+
}
84+
85+
// target "code-interpreter" {
86+
// context = "./code-interpreter/vendor/cohere-ai/cohere-terrarium"
87+
// dockerfile = "Dockerfile"
88+
// tags = [
89+
// "julepai/code-interpreter:${TAG}",
90+
// "julepai/code-interpreter:git-${GIT_SHA}"
91+
// ]
92+
// }

0 commit comments

Comments
 (0)