Mini DB is a simple key-value store that communicates through a TCP interface, designed to handle basic operations such as setting and looking up key-value pairs. It utilizes Parquet files for data persistence, ensuring data durability across server restarts.
- Quick Start
- Features
- Configuration
- Building and Running
- Client Application
- Server Management
- Troubleshooting
- Safe Usage with TLS and Authentication
- Monitoring Setup with Prometheus and Grafana
- Future Enhancements
-
Clone the repository:
git clone <repository_url> cd mini-db
-
Build and run using Docker:
./run_server.sh
-
Or build and run locally:
./build.sh build ./build.sh run-server
- note: if you run with docker, grafana and prometheus will be available at
http://localhost:3000
andhttp://localhost:9090
respectively.
- SET and LOOKUP Commands: Store and retrieve key-value pairs efficiently.
- Data Persistence: Utilizes Parquet files for reliable data storage.
- TLS Support: Optional TLS to secure connections.
- Authentication: Supports token-based authentication for enhanced security.
- Structured Logging: Uses Logrus for clear and structured logging.
Configuration is managed via a YAML file (config/config.yaml
). Here’s an example:
server:
port: "8080"
tls: false
tls_cert_file: "config/server.crt"
tls_key_file: "config/server.key"
storage:
file_path: "data/db.parquet"
logging:
level: "info"
security:
auth_enabled: false
auth_token: "your-secure-auth-token"
Ensure Go is installed, and the script is executable:
chmod +x build.sh
./build.sh build
./build.sh run-server
./build.sh run-client -auth=true -tls=true -ca-cert=path/to/client.pem localhost 8080
Or you can just run:
chmod +x build.sh
./build.sh build
./build.sh run-server
./build.sh run-client localhost 8080
Ensure Docker is installed and run:
./run_server.sh
Interact with the Mini DB server using the client application:
cd client
go build -o client main.go
./client -auth=true -tls=true -ca-cert=path/to/client.pem <address> <port>
Or you can just run:
cd client
go build -o client main.go
./client <address> <port>
./client -auth=true -tls=true -ca-cert=path/to/client.pem localhost 8080
> SET your-secure-auth-token my_key my_value
OK
> LOOKUP your-secure-auth-token my_key
my_value
> EXIT
Exiting...
Without security concerns:
./client localhost 8080
> SET my_key my_value
OK
> LOOKUP my_key
my_value
> EXIT
Exiting...
Testing: Run tests with go test ./...
.
Stopping the Server: Use Ctrl+C
in the terminal or docker-compose down
for Docker users.
- Check all file paths and environment variables.
- Ensure Go and Docker are properly installed and configured.
- Review script outputs and server logs for error messages.
For enhanced security, Mini DB supports both TLS for encrypted connections and token-based authentication to control access. Below are guidelines on how to configure and use these features securely.
- Generate TLS Certificates: Follow the instructions above to generate
server.crt
andserver.key
. - Configure the Client: Ensure the client is set up to use the CA certificate through
-ca-cert
flag pointing toserver.crt
.
-
Install OpenSSL: If you don't have OpenSSL installed on your system, you can install it using your package manager. For example, on Ubuntu, you can install it with:
sudo apt-get install openssl
-
Generate a Private Key and a Self-Signed Certificate: Use the following commands to generate your private key and a self-signed certificate:
openssl genrsa -out server.key 2048 openssl req -new -x509 -sha256 -key server.key -out server.crt -days 365
During the certificate creation process (
req -new -x509
), you will be prompted to enter details such as country, state, and organization. These details are used to fill the subject field of the certificate. For local testing, you can fill these with any values. -
Place the Generated Files Appropriately: Once generated, place
server.crt
andserver.key
in a directory accessible by your server application, such as within aconfig
folder or directly in the directory from which you run your server.
Make sure your server application is configured to use these TLS files. Update the configuration settings in your config.yaml
or wherever your server application expects them:
tls: true
tls_cert_file: "path/to/server.crt"
tls_key_file: "path/to/server.key"
Start your server normally using your script or directly. If your server setup script or application is configured to output logs, watch for any TLS-related errors.
To test if TLS is working:
-
Using
curl
or a similar tool: You can test the HTTPS connection usingcurl
. Replacelocalhost
and8080
with your actual server address and port.curl https://localhost:8080 --cacert path/to/server.crt
This command tells
curl
to use your self-signed certificate as the CA certificate. If everything is set up correctly, you should not see any SSL errors, and you should be able to communicate securely with your server. -
Using a Web Browser: Access your server using a web browser. You might need to import your
server.crt
into the browser or accept a security exception because the browser will warn you about the self-signed certificate.
If you encounter TLS-related errors during testing, check the following:
- Ensure the paths to
server.crt
andserver.key
are correctly specified in your server's configuration. - Verify that the server is configured to listen over HTTPS and not HTTP.
- Check for detailed error messages in your server's logs to diagnose issues related to certificate loading or TLS handshake failures.
- Configure an Auth Token: Set
auth_enabled
totrue
in the server configuration and specify anauth_token
. - Client Usage: When starting the client, use
-auth=true
and provide the token in your commands as shown in the examples.
Follow these guidelines to ensure that your interactions with Mini DB are secure and your data is protected against unauthorized access.
For comprehensive monitoring, you can set up Prometheus to scrape metrics from the Mini DB server and Grafana to visualize these metrics.
-
Prometheus Configuration: Create a
prometheus.yml
file in themonitoring
directory with the following content:global: scrape_interval: 15s scrape_configs: - job_name: 'mini-db' static_configs: - targets: ['mini-db:2112']
-
Docker Compose for Monitoring: Create a
docker-compose.monitoring.yml
file in themonitoring
directory with the following content:version: '3.8' services: prometheus: image: prom/prometheus:v2.29.1 volumes: - ./prometheus.yml:/etc/prometheus/prometheus.yml ports: - "9090:9090" networks: - mini-db-network grafana: image: grafana/grafana:7.5.7 ports: - "3000:3000" volumes: - ./grafana:/var/lib/grafana environment: - GF_SECURITY_ADMIN_PASSWORD=admin user: "root" privileged: true networks: - mini-db-network networks: mini-db-network: external: true
-
Start Prometheus and Grafana: Ensure Docker is installed and run:
docker-compose -f monitoring/docker-compose.monitoring.yml up --build
-
Verify Prometheus Setup:
- Access Prometheus at
http://localhost:9090
. - Check if the
mini-db
job is listed underStatus > Targets
.
- Access Prometheus at
-
Access Grafana:
- Open your browser and go to
http://localhost:3000
. - Log in with
admin/admin
- Open your browser and go to
-
Add Prometheus as a Data Source:
- Navigate to Configuration > Data Sources.
- Add a new data source and select Prometheus.
- Set the URL to
http://prometheus:9090
. - Click Save & Test.
-
Create a Dashboard:
- Click on the + icon on the left sidebar and select Dashboard.
- Click on Add new panel to create a new visualization.
- Use Prometheus queries to visualize metrics (e.g.,
sum(requests_total) by (method)
).
-
Save the Dashboard:
- Click on Save dashboard icon at the top.
- Provide a name for your dashboard and click Save.
-
Total Requests:
sum(requests_total) by (method)
-
Request Rate:
rate(requests_total[1m])
-
CPU Usage:
sum(rate(process_cpu_seconds_total[1m])) by (instance)
-
Memory Usage:
process_resident_memory_bytes
To customize the colors in your Grafana dashboard:
-
Edit the Panel:
- Hover over the panel and click on the Panel Title.
- Select Edit from the dropdown menu.
-
Customize Panel Colors:
- In the panel editor, go to the Overrides or Visualization tab (depending on the panel type).
For Graph Panels:
- Line Color: Under the Field tab, click on the color box next to the field name to select a new color.
- Area Fill Color: Enable the Fill option and adjust the color using the color picker.
For Stat Panels:
- Text and Background Colors: Under the Field tab, click on Thresholds. Add thresholds and specify colors for different value ranges.
- Gauge Color: Under the Field tab, click on the color box next to the field name to select a new color.
-
Apply and Save:
- Click on Apply to save the changes to the panel.
- Save the dashboard.
- Scalability: Implement distributed processing and storage capabilities to scale beyond a single server instance.
- API Extensions: Add more sophisticated query capabilities and support for different data types beyond simple strings.
- Advanced Security: Implement more advanced security features such as OAuth or JWT-based authentication.
- User Interface: Develop a web-based user interface for easier interaction with the Mini DB.
Thank you for your interest in Mini DB. This project aims to provide a simple yet robust solution for managing key-value pairs with durability and security in mind. With features like TLS support, authentication, and comprehensive monitoring using Prometheus and Grafana, Mini DB is well-suited for various applications. We encourage you to explore, use, and contribute to the project, ensuring its continuous improvement and adaptability to meet evolving needs.
For any questions or support, feel free to reach out via the project's GitHub repository. Happy coding!