Skip to content

Commit 96a7fae

Browse files
committed
feat: integrate storage provider into gitopia localnet
- Enhanced tests/localnet/docker-compose.yml with storage infrastructure - Integrated single storage provider - Added Prometheus + Grafana monitoring stack for observability - Added comprehensive configuration and monitoring - config/storage-provider.toml with redundant WebSocket connections - monitoring/prometheus.yml for metrics collection - monitoring/grafana/ with dashboards and alerting - Updated localnet Makefile with new commands - make localnet-start: full environment with storage + monitoring - make localnet-start-basic: backward-compatible basic localnet - make localnet-logs-storage: monitor storage provider activity - make localnet-monitoring: open Grafana dashboard - Added comprehensive documentation - tests/localnet/README.md with setup and usage instructions - Integration guide for E2E tests and development workflows - Troubleshooting and monitoring guidance This enables local testing of storage challenges with full observability
1 parent 7c39020 commit 96a7fae

11 files changed

Lines changed: 761 additions & 88 deletions

File tree

scripts/makefiles/localnet.mk

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,66 @@ localnet-help:
1212
@echo " build Build localnet"
1313
@echo " clean Clean localnet"
1414
@echo " init Initialize localnet"
15-
@echo " start Start localnet"
15+
@echo " start Start localnet with storage & monitoring"
16+
@echo " start-basic Start basic localnet only"
1617
@echo " stop Stop localnet"
18+
@echo " logs Show logs from all services"
19+
@echo " logs-storage Show storage provider logs"
20+
@echo " status Show service status"
21+
@echo " monitoring Open monitoring dashboard"
22+
@echo " setup-storage Setup storage directories"
1723
localnet: localnet-help
1824

1925
localnet-init: localnet-clean localnet-build
2026

2127
localnet-build:
2228
@DOCKER_BUILDKIT=1 COMPOSE_DOCKER_CLI_BUILD=1 docker compose -f tests/localnet/docker-compose.yml build
2329

24-
localnet-start:
30+
localnet-setup-storage:
31+
@echo "Setting up storage directories..."
32+
@mkdir -p tests/localnet/data/{gitopia,storage1,storage2}/{repos,attachments,lfs-objects}
33+
@docker network create storage-provider-test 2>/dev/null || echo "Network already exists"
34+
35+
localnet-start: localnet-setup-storage
36+
@echo "Starting Gitopia localnet with storage providers and monitoring..."
37+
@echo ""
38+
@echo "Services will be available at:"
39+
@echo " - Gitopia Chain: http://localhost:26657"
40+
@echo " - Gitopia API: http://localhost:1317"
41+
@echo " - Storage Provider 1: http://localhost:5002"
42+
@echo " - Storage Provider 2: http://localhost:5003"
43+
@echo " - IPFS Gateway: http://localhost:8080"
44+
@echo " - IPFS Cluster: http://localhost:9094"
45+
@echo " - Grafana Dashboard: http://localhost:3000 (admin/admin123)"
46+
@echo " - Prometheus: http://localhost:9090"
47+
@echo ""
2548
docker compose -f tests/localnet/docker-compose.yml up
2649

50+
localnet-start-basic:
51+
@echo "Starting basic localnet (gitopiad + faucet only)..."
52+
docker compose -f tests/localnet/docker-compose.yml up gitopiad faucet
53+
2754
localnet-stop:
2855
docker compose -f tests/localnet/docker-compose.yml down
2956

57+
localnet-logs:
58+
docker compose -f tests/localnet/docker-compose.yml logs -f
59+
60+
localnet-logs-storage:
61+
docker compose -f tests/localnet/docker-compose.yml logs -f gitopia-storage-1 gitopia-storage-2
62+
63+
localnet-status:
64+
docker compose -f tests/localnet/docker-compose.yml ps
65+
66+
localnet-monitoring:
67+
@echo "Opening monitoring dashboards..."
68+
@echo "Grafana: http://localhost:3000 (admin/admin123)"
69+
@echo "Prometheus: http://localhost:9090"
70+
@which open >/dev/null && open http://localhost:3000 || echo "Open http://localhost:3000 in your browser"
71+
3072
localnet-clean:
73+
@echo "Cleaning up localnet environment..."
74+
@docker compose -f tests/localnet/docker-compose.yml down -v --remove-orphans 2>/dev/null || true
75+
@docker network rm storage-provider-test 2>/dev/null || true
76+
@rm -rf tests/localnet/data/
3177
@rm -rfI $(HOME)/.gitopia-local/

tests/localnet/.env

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Gitopia Localnet Configuration
2+
CHAIN_ID=localgitopia
3+
4+
# Storage Provider Mnemonics
5+
STORAGE_PROVIDER_MNEMONIC="prize cycle gravity trumpet force initial print pulp correct maze mechanic what gallery debris ice announce chunk curtain gate deliver walk resist forest grid"
6+
7+
# IPFS Cluster Configuration
8+
CLUSTER_PEERNAME=cluster0
9+
CLUSTER_SECRET=e11341a263ca30e7c1d57a34c7f9097d3c687532d09fcab07aa13286165806dc
10+
CLUSTER_TRUSTED_PEERS=*
11+
12+
# Monitoring Configuration
13+
PROMETHEUS_PORT=9090
14+
GRAFANA_PORT=3000
15+
GRAFANA_ADMIN_USER=admin
16+
GRAFANA_ADMIN_PASSWORD=admin123

tests/localnet/README.md

Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
# Gitopia Localnet with Storage Providers
2+
3+
This enhanced localnet setup includes Gitopia blockchain, storage providers, IPFS cluster, and comprehensive monitoring for testing storage challenges.
4+
5+
## 🏗️ Architecture
6+
7+
- **Gitopia Chain**: Local blockchain with pre-configured accounts
8+
- **Storage Providers**: Two redundant providers with enhanced reliability
9+
- **IPFS Infrastructure**: IPFS node + IPFS Cluster for distributed storage
10+
- **Monitoring**: Prometheus + Grafana for metrics and alerting
11+
- **Faucet**: Token distribution service
12+
13+
## 🚀 Quick Start
14+
15+
### From Gitopia Root Directory
16+
17+
```bash
18+
# Start complete environment (recommended)
19+
make localnet-start
20+
21+
# Or start basic localnet only (chain + faucet)
22+
make localnet-start-basic
23+
24+
# Build images first if needed
25+
make localnet-build
26+
```
27+
28+
### Available Commands
29+
30+
```bash
31+
make localnet-help # Show all available commands
32+
make localnet-build # Build Docker images
33+
make localnet-start # Start full environment
34+
make localnet-start-basic # Start basic localnet only
35+
make localnet-stop # Stop all services
36+
make localnet-clean # Clean up everything
37+
make localnet-logs # Show all logs
38+
make localnet-logs-storage # Show storage provider logs
39+
make localnet-status # Show service status
40+
make localnet-monitoring # Open monitoring dashboard
41+
```
42+
43+
## 📊 Service Endpoints
44+
45+
| Service | Endpoint | Description |
46+
|---------|----------|-------------|
47+
| Gitopia RPC | http://localhost:26657 | Tendermint RPC |
48+
| Gitopia API | http://localhost:1317 | REST API |
49+
| Gitopia gRPC | http://localhost:9090 | gRPC endpoint |
50+
| Storage Provider | http://localhost:5002 | Storage provider |
51+
| IPFS Gateway | http://localhost:8080 | IPFS HTTP gateway |
52+
| IPFS API | http://localhost:5001 | IPFS API |
53+
| IPFS Cluster API | http://localhost:9094 | Cluster management |
54+
| Faucet | http://localhost:4500 | Token faucet |
55+
| Grafana | http://localhost:3000 | Monitoring dashboard |
56+
| Prometheus | http://localhost:9090 | Metrics collection |
57+
58+
## 🧪 Testing Storage Challenges
59+
60+
### Monitor Challenge Activity
61+
62+
```bash
63+
# View storage provider logs
64+
make localnet-logs-storage
65+
66+
# Check service status
67+
make localnet-status
68+
69+
# Open monitoring dashboard
70+
make localnet-monitoring
71+
```
72+
73+
### Create Test Repository
74+
75+
```bash
76+
# Connect to the chain container
77+
docker exec -it gitopiad /bin/sh
78+
79+
# Create a test user and repository (this will trigger storage challenges)
80+
gitopiad tx gitopia create-user testuser --from val --keyring-backend test --chain-id localgitopia --yes
81+
gitopiad tx gitopia create-repository testrepo --from val --keyring-backend test --chain-id localgitopia --yes
82+
```
83+
84+
## 📊 Monitoring
85+
86+
### Grafana Dashboard
87+
- **URL**: http://localhost:3000
88+
- **Credentials**: admin / admin123
89+
- **Features**:
90+
- Localnet chain status
91+
- Storage provider health
92+
- Challenge response metrics
93+
- IPFS cluster status
94+
95+
### Prometheus Metrics
96+
- **URL**: http://localhost:9090
97+
- **Available Metrics**:
98+
- Chain consensus and block height
99+
- Storage challenge success/failure rates
100+
- WebSocket connection health
101+
- IPFS node metrics
102+
103+
## ⚙️ Configuration
104+
105+
### Storage Provider Configuration
106+
- `config/storage-provider-1.toml`: First provider settings
107+
- `config/storage-provider-2.toml`: Second provider settings
108+
109+
Key features:
110+
- Enhanced WebSocket reliability (50 reconnect attempts vs 3)
111+
- 8-second challenge response timeout (safely under 10s deadline)
112+
- Redundant RPC endpoints for failover
113+
- Comprehensive retry logic and error handling
114+
115+
### Environment Variables
116+
- `.env`: Contains all configuration variables
117+
- Modify `STORAGE_PROVIDER_*_MNEMONIC` to use different accounts
118+
- Adjust monitoring ports if needed
119+
120+
### Monitoring Configuration
121+
- `monitoring/prometheus.yml`: Metrics collection setup
122+
- `monitoring/alert_rules.yml`: Alert rules for failures
123+
- `monitoring/grafana/`: Dashboard and datasource configuration
124+
125+
## 🔧 Troubleshooting
126+
127+
### Common Issues
128+
129+
1. **Services not starting**
130+
```bash
131+
# Check Docker and network
132+
docker network ls | grep storage-provider-test
133+
134+
# Rebuild and restart
135+
make localnet-clean
136+
make localnet-build
137+
make localnet-start
138+
```
139+
140+
2. **Storage challenges not working**
141+
```bash
142+
# Check storage provider logs
143+
make localnet-logs-storage
144+
145+
# Verify chain connectivity
146+
curl http://localhost:26657/status
147+
```
148+
149+
3. **Port conflicts**
150+
```bash
151+
# Check what's using the ports
152+
lsof -i :26657 -i :3000 -i :9090
153+
154+
# Modify ports in .env file if needed
155+
```
156+
157+
### Health Checks
158+
159+
```bash
160+
# Chain health
161+
curl http://localhost:26657/health
162+
163+
# Storage provider health
164+
curl http://localhost:5002/health
165+
curl http://localhost:5003/health
166+
167+
# IPFS health
168+
curl http://localhost:5001/api/v0/version
169+
170+
# Monitoring health
171+
curl http://localhost:9090/-/healthy
172+
curl http://localhost:3000/api/health
173+
```
174+
175+
## 🔍 Development
176+
177+
### Adding Custom Storage Providers
178+
179+
1. Add new service to `docker-compose.yml`
180+
2. Create configuration file in `config/`
181+
3. Update monitoring configuration
182+
4. Add to Makefile commands
183+
184+
### Customizing Chain Configuration
185+
186+
Modify `scripts/setup_chain.sh` to:
187+
- Add more genesis accounts
188+
- Change chain parameters
189+
- Configure different validators
190+
191+
### Extending Monitoring
192+
193+
1. Add metrics to `monitoring/prometheus.yml`
194+
2. Create custom Grafana dashboards
195+
3. Add new alert rules
196+
197+
## 📚 Integration with E2E Tests
198+
199+
This localnet setup is compatible with the existing E2E test framework:
200+
201+
```bash
202+
# Run E2E tests against localnet
203+
make test-e2e
204+
205+
# Or run specific test suites
206+
cd tests/e2e && go test -v ./...
207+
```
208+
209+
The storage providers will automatically handle challenges generated during E2E test execution.
210+
211+
## 🎯 Next Steps
212+
213+
1. **Start the environment**: `make localnet-start`
214+
2. **Open monitoring**: http://localhost:3000
215+
3. **Create test repositories** to trigger storage challenges
216+
4. **Monitor logs** for challenge activity
217+
5. **Experiment** with different configurations
218+
219+
This setup provides a complete testing environment for Gitopia's storage challenge system with full observability and reliability features.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Storage Provider Configuration
2+
3+
# Server configuration
4+
SERVER_HOST = "0.0.0.0"
5+
SERVER_PORT = 5000
6+
7+
# Gitopia chain configuration - Redundant endpoints for reliability
8+
TM_RPC_ENDPOINTS = ["http://gitopiad:26657", "http://gitopiad:26657"]
9+
TM_WS_ENDPOINT = "ws://gitopiad:26657/websocket"
10+
TM_WS_MAX_RECONNECT = 50
11+
TM_WS_RECONNECT_DELAY = "5s"
12+
CHAIN_ID = "localgitopia"
13+
14+
# IPFS configuration
15+
IPFS_API_URL = "http://ipfs:5001"
16+
IPFS_CLUSTER_API_URL = "http://cluster:9094"
17+
18+
# Storage configuration
19+
REPOS_BASE_PATH = "/var/repos"
20+
ATTACHMENTS_BASE_PATH = "/var/attachments"
21+
LFS_OBJECTS_BASE_PATH = "/var/lfs-objects"
22+
23+
# Challenge response configuration - Enhanced for reliability
24+
CHALLENGE_RESPONSE_TIMEOUT = "8s"
25+
CHALLENGE_MAX_CONCURRENT_RESPONSES = 3
26+
CHALLENGE_CONNECTION_HEALTH_CHECK = "30s"
27+
CHALLENGE_RETRY_ATTEMPTS = 3
28+
CHALLENGE_RETRY_DELAY = "1s"
29+
CHALLENGE_QUEUE_SIZE = 1000
30+
31+
# Logging
32+
LOG_LEVEL = "info"
33+
LOG_FORMAT = "json"
34+
35+
# Metrics
36+
METRICS_ENABLED = true
37+
METRICS_PORT = 8080
38+
39+
# Database
40+
DATABASE_PATH = "/var/storage-provider-1.db"

0 commit comments

Comments
 (0)